[Libav-user] Problem using avcodec_decode_video2 for reading HEVC stream

Krishna krish.rao.v at gmail.com
Wed Aug 27 15:48:14 CEST 2014


Hi,

I am writing an HEVC decoder and it seems that the first several frames are
not decoded by avcodec_decode_video2(). Here is my code snippet. The input
is an video-only stream (no audio). This is my function, that is called
each time I need a single frame (that is essentially what I want  -- one
frame at a time).

bool decode(pFormatCtx, pCodecCtx)
{
    int gotaFrame=0;
    int retVal = 0;
    while (gotaFrame==0) {

        printf("1\t");

        if ( !av_read_frame(pFormatCtx, &packet) ) {
            if(packet.stream_index==videoStreamIndex) {

                // try decoding
                retVal = avcodec_decode_video2(pCodecCtx, pFrame,
&gotaFrame, &packet);
                printf("%d\t", retVal);

                if (gotaFrame) {  // decode success.

                    printf("2\t");

                    // dump to yuv ... not shown here.

                    // cleanup
                    av_frame_unref(pFrame);
                    av_frame_free(&pFrame);
                    av_free_packet(&packet);

                    return true;
                }
            }
        }
    }
}

Here is the output of retVal:

retval=33149
retval=6715
retval=767
retval=264
retval=126
retval=147
retval=286
retval=140
retval=141
retval=7243
retval=568
retval=315
retval=95
retval=146
retval=328
retval=159
retval=121
retval=7010
retval=571
retval=309

After the retVal=309, gotaFrame becomes 1. Essentially, I have lost a lot
of frames. Can someone help me out here?

How do I get one frame at a time?

Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20140827/123940f0/attachment.html>


More information about the Libav-user mailing list