[FFmpeg-devel] Modified force_key_frames option to accept frame numbers

Sylvester Zaluga sylwekzff at outlook.com
Sat Nov 22 21:46:09 CET 2014

I am sorry for the spam, but as I have not published any changes to ffmpeg before, I thought I should double-check.

Nicolas, you replied earlier that you would not oppose the feature described below. Does that mean I can go ahead
and submit my change? Can I consider my change reviewed or am I supposed to wait for further reviews?

Sylwester Zaluga

Date: Mon, 10 Nov 2014 14:18:25 +0100
From: george at nsup.org
To: ffmpeg-devel at ffmpeg.org
CC: sylwekzff at outlook.com
Subject: Re: [FFmpeg-devel] Modified force_key_frames option to accept frame numbers

Le nonidi 19 brumaire, an CCXXIII, Sylvester Zaluga a écrit :
> ***Sending again, this time with diff***
Better use git format-patch (or git send-email), so that you have authorship
and date information.
> Attached a patch which allows for passing in frame numbers
> at which key frames should be forced. 
> The current modes in which force_key_frames operate are:
> * force_key_frames 1,2,3,4,5  - parameter is interpreted as timestamps
> * force_key_frames expr:gte(t,n_forced) - parameter is an expression
> The patch adds support for third mode:
> * force_key_frames n:0,25,50,75,100  - interpret parameter as frame numbers
> I find this useful for avoiding float precision-related
> issues that surface when key frames are forced at specified timestamps.
I will not actually oppose the feature, but every time people insist on
working with frame numbers instead of timestamp, I feel they are doing
something incorrectly.
In this particular case, you can easily work around the floating point
rounding issues, since the rounding behaviour of -force_key_frames is
specified: "more precisely at the first frames after each specified time".
You just have to make sure your timestamps are rounded down. For example,
with 24000/1001 FPS: 4.21 4.25 4.30* 4.34 4.38, you need to write 4.29, not
4.30, but you can also write any value between 4.25425 and the actual
4.295958333. (4.25+4.30)/2 = 4.275 should always work.
> My use case is as follows:
> * generate output video with settings for HD video
> * extract key frame numbers from HD video
> * generate SD video with key frames at identical positions
> * In my application, do video LODing by switching HD/SD video 
>   depending on bandwith
What happens if, in order to lower even more the SD bitrate, you decide to
add the decimate filter? Frame numbers are jumbled, while timestamps are
preserved. Working with frame numbers is fragile.
(Also, note that with some codecs, forcing a lot of keyframes will have a
dramatic effect on the efficiency of the encoding.)
  Nicolas George

ffmpeg-devel mailing list
ffmpeg-devel at ffmpeg.org

More information about the ffmpeg-devel mailing list