[FFmpeg-user] Revisit FFmpeg Frame Lost

JIA Pei jp4work at gmail.com
Sat Feb 16 00:41:47 CET 2013


Hi, all:

Sorry to bug all of you. This is actually a very old topic, but I still
would like to mention it again.

Actually what I've done so far is:
1) using the following 2 commands to create 2 video files from the same
image sequence (268 images in total)
*ffmpeg -i %3d video.mpg*
*ffmpeg ii %3d video.mp4*

2) trying to use the following patch of code to decode these 2 video files
--- in the following patch, I just count the number of frames in these 2
video files.

int e = ERROR_NONE;


    AVPacket pkt;

    av_init_packet(&pkt);

    if( av_read_frame(this->m_pFormatCtxDec, &pkt) < 0)

    {

        return (e = ERROR_ENDOFFILE);

    }


    if(pkt.stream_index == this->m_iVideoStreamIdx)

    {

        int got_picture = 0;

        int len = avcodec_decode_video2(this->m_pCodecCtxDecVideo,

                                        this->m_pVideoFrame,

                                        &got_picture,

                                        &pkt);

        if(!got_picture)

            return (e = ERROR_GOTPICTUREPTR);


        if(len < 0)

            return (e = ERROR_VIDEODECODING);


        ++this->m_iNbOfFrames;

    }




As mentioned in *av_read_frame()* documentation,
*For video, the packet contains * exactly one frame*

So, what I've been expecting is: this->m_iNbOfFrames
should be equal to 268 (total number of frames inside video files. )

However,
for .mpg, I got 267 images after decoding; (lack of 1 frame)
for .mp4, I got 260 images after decoding (lack of 8 frames)



It seems http://ffmpeg.org/doxygen/trunk/api-example_8c-source.html is able
to handle the "frame lost" issue, but it uses* fread()* instead of *
av_read_frame()*. If I insist on using *av_read_frame()*, how can I avoid
this "frame lost" issue?

Please do help.. Thank you very much.

-- 

Pei JIA

Email: jp4work at gmail.com
cell:    +1 604-362-5816

Welcome to Vision Open
http://www.visionopen.com


More information about the ffmpeg-user mailing list