non strictly monotonic PTS
specified frame type is not compatible with max B-frames
specified frame type (5) at 11 is not compatible with the keyframe interval
Other than that if I change the width and height of my encoder, i get an error that the input is bigger than the stride?
Here is my code
Code: Select all
ppAVO = av_guess_format("mp4", NULL, NULL); //create an output format (MP4)
int po = avformat_alloc_output_context2(&pFD, ppAVO, NULL, "c://wav//testme.mp4"); //create output context
av_init_packet(&packet);
av_init_packet(&spacket);
pFC = avformat_alloc_context();
pFD = avformat_alloc_context();
avformat_open_input(&pFC, "c://wav//test2.flv", NULL, NULL);
po = av_find_stream_info(pFC);
// pRead = pFC->streams
int jje = pFC->nb_streams;
//ADD LOGIC TO FIND VIDEO STREAM
pCodecC = pFC->streams[0]->codec;
decoder = avcodec_find_decoder(pCodecC->codec_id);
encoder = avcodec_find_encoder(pCodecC->codec_id);
po = avcodec_open(pCodecC, decoder);
pCodecE = avcodec_alloc_context3(encoder);
/* put sample parameters */
pCodecE->bit_rate = pCodecE->width * pCodecE->height * 4;//400000;
/* resolution must be a multiple of two */
pCodecE->width = 352;
pCodecE->height = 288;
/* frames per second */
pCodecE->time_base.den = 30;//25
pCodecE->time_base.num = 1;//1
pCodecE->gop_size = 12;//10; /* emit one intra frame every ten frames */
pCodecE->max_b_frames=0;//1;
pCodecE->pix_fmt = PIX_FMT_YUV420P;
if(pCodecC->codec_id == CODEC_ID_H264)
av_opt_set(pCodecE->priv_data, "preset", "slow", 0);
po = avcodec_open2(pCodecE, encoder, NULL);
AVFrame *pFrame;
// Allocate an AVFrame structure
// Allocate video frame
pFrame=avcodec_alloc_frame();
FILE * ff = fopen(filename,"r+");
int frameFinished = 0;
AVFrame * pFrameRGB= avcodec_alloc_frame();
uint8_t *buffer;
int numBytes;
// Determine required buffer size and allocate buffer
numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecC->width,
pCodecC->height);
buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
// Assign appropriate parts of buffer to image planes in pFrameRGB
// Note that pFrameRGB is an AVFrame, but AVFrame is a superset
// of AVPicture
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
pCodecC->width, pCodecC->height);
int frame = 0;
while(av_read_frame(pFC, &packet) >= 0)
{
if(packet.stream_index==0) //the video stream is 0
{
int len = avcodec_decode_video2(pCodecC, pFrame, &frameFinished, &packet);
if(frameFinished)
{
printf("frame # %i", frame);
int gotpacket = 0;
po =avcodec_encode_video2(pCodecE, &spacket, pFrame, &gotpacket);
if(gotpacket)
{
printf("packet # %i", frame);
}
frameFinished = 0;
gotpacket = 0;
frame++;
len = 0;
}
}
av_free_packet(&packet);
av_free_packet(&spacket);
}
printf("encoding done");