[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;


    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,





            return (e = ERROR_GOTPICTUREPTR);

        if(len < 0)

            return (e = ERROR_VIDEODECODING);



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. )

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.



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

Welcome to Vision Open

More information about the ffmpeg-user mailing list