[Libav-user] Frames are not visually lining up between my code and ffmpeg.exe

Michael Bradshaw mbradshaw at sorensonmedia.com
Wed Jun 27 19:50:48 CEST 2012

On Tue, Jun 26, 2012 at 1:11 PM, Simon Daniels <simondaniels23 at gmail.com> wrote:
> Hi Michael -- after reading into things a bit more, I agree that it's risky
> what I'm doing. However, I only need about 3 frames per second so maybe
> waiting for a key frame isn't the end of the world...
> Is there a safer way? The decoding is extremely expensive so I only want to
> do it when I absolutely need to.

I'm not the most knowledgable about this, so someone correct me if I'm
wrong/if there's a better way...

You've got an H264 stream. H264 streams can have P and B-frames, and
both P and B-frames depend on the previous frame to be properly
decoded. If you're just skipping frames without decoding them, it's
possible (and I'd say quite likely) you'll try and decode a P or
B-frame after skipping the previous frame that this frame depended on.

The only way I know of to "skip" every X frames is to: decode all the
frames, and only use the ones you need, or only decode keyframes (but
it's possible there can be a few seconds between two keyframes).
AVPacket.flag can be used to know if the packet has a keyframe (check

More information about the Libav-user mailing list