[Libav-user] Repeating frame while encoding using ffmpeg api

Nicolas George george at nsup.org
Mon Sep 29 17:13:22 CEST 2014

Le quintidi 5 vendémiaire, an CCXXIII, Bradley O'Hearne a écrit :
> Over months of testing, the behavior I have seen is that whatever the
> time_base.den value is set on your codec, that number of frames per second
> absolutely has to be fed to the encoder, or else playback of the video
> will be out of sync.

That is not true, but a number of things can be wrong in your program and
explain that it does not seem to work.

First, you must make sure that all fields are properly set: the time base
for both codec and stream and the various frame rate fields.

Then, you must make sure that you actually set the timestamps and duration
before encoding.

Then you must make sure to convert the timestamps from codec time base to
stream time base. The muxer is allowed to change the time base during
write_header(), so the stream time base may not be what you requested.

Then you must make sure that the format you are using supports variable
frame rate, since that is what you are trying to achieve; AVI does not, for

You must also make sure that the muxer implementation in FFmpeg supports it.
For example, MOV/MP4 are supposed to support variable frame rate, but the
muxer in lavf does not.

At this point, you should be able to see valid pkt_pts using ffprobe

Last, you must make sure that the application you are using to see the video
uses the timestamps.

But to answer the first question, which was about dropping frames when they
are too similar to the previous one:

Do not do that.

Video encoding is all about finding what changed between one frame and the
next and finding the most efficient way of coding it.

If you Compare the frames and drop them when they are too similar, you are
re-implementing part of the codec in the application, poorly and without

Just let the codec do its job. If a frame is very similar to the previous
one, it will use very few bits to code it, but these bits will still be
better used there than elsewhere.

If you are stuck with a poor codec that does a bad job of it, and can not
switch to a better codec, consider using the decimate filter, which is
specifically designed for that task, with optimizations.


  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20140929/bfdceafd/attachment.asc>

More information about the Libav-user mailing list