I have a HEVC sequence with 3500 frames, and I am writing a decoder to read it (read frame by frame and dump for yuv). In my main (), I have a for loop that calls the decoder () 3500 times (I assume at this point that main () knows how many frames there are).
So, for every decoder () call, I need a full frame that needs to be returned. This is what decoder () looks like.
bool decode(pFormatCtx, pCodecCtx)
{
int gotaFrame=0;
while (gotaFrame==0) {
printf("1\t");
if ( !av_read_frame(pFormatCtx, &packet) ) {
if(packet.stream_index==videoStreamIndex) {
avcodec_decode_video2(pCodecCtx, pFrame, &gotaFrame, &packet);
if (gotaFrame) {
printf("2\t");
av_frame_unref(pFrame);
av_frame_free(&pFrame);
av_free_packet(&packet);
return true;
}
}
}
}
}
The behavior looks like this: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 2 ...... does it look like it reads a few frames before decoding? The first frame is an I-frame, so can't it be decoded right away?
With this code, I lose a few frames (indicated by a series of 1). Can someone help me here? Is there something I'm doing wrong in my code?
: . .