[Libav-user] what's wrong with this loop?

Jason Livingston jettoblack at gmail.com
Fri Dec 14 18:30:17 CET 2012


On Fri, Dec 14, 2012 at 11:38 AM, Dominic Laflamme <flamz3d at gmail.com>wrote:

> Hello,
> I am attempting to sequentially fetch frames from a movie encoded with
> libx264. I am using a typical av_read_frame / av_decode_video2 loop (found
> in most demos out there) to fetch each frames. Like this:
>
> int nbFrames = 0;
> while ( av_read_frame () >= 0 )
> {
>  av_decode_video2(&frameFinished);
> if ( frameFinished )
>  {
> nbFrames++;
> }
> }
>
> Now, my video file has 1000 frames, but after the loop runs, nbFrames only
> got incremented to 994.
>

Hi Dominic,
Your loop stops when av_read_frame() returns an error such as EOF.  There
may still be decoded frames in memory.  To get those frames out, pass an
empty AVPacket (size = 0, data = NULL) into av_decode_video2() until
frameFinished returns 0.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20121214/5126d3bb/attachment.html>


More information about the Libav-user mailing list