[FFmpeg-devel] [PATCH] ffmpeg: implement -force_key_frames_expr option

Stefano Sabatini stefasab at gmail.com
Sun Jan 13 22:36:45 CET 2013

On date Saturday 2012-12-15 23:00:59 +0100, Stefano Sabatini encoded:
> On date Saturday 2012-12-15 19:18:59 +0100, Michael Niedermayer encoded:
> > On Sat, Dec 15, 2012 at 10:57:27AM +0100, Stefano Sabatini wrote:
> [...]
> > > Now the problem is that I can't set frame->key_frame in
> > > avcodec_encode_video2(), since the struct is const. The best way seems
> > > to set a field in AVCodecContext.force_key_frame, but that would
> > > require changing all the encoders.
> > > 
> > > Do you see a better way?
> > 
> > the keyframe expression evaluation could be put in a seperate function
> > and called from mpegvideo or other encoders for which it makes sense.
> > You cant call it from the generic code anyway as it doesnt know the
> > scene change score and other parameters from motion estimation and
> > rate control which may be interresting.
> I need the option to be as generic as possible, having it working only
> for MPEGVIDEO codecs doesn't simply work for me.
> Implementing a private MPEG-codecs option, overriding the generic one
> and accessing the internal MPEG context, would be a possibility (but I
> don't volunteer for doing it, as I have no need for it and limited
> time).

Also, after some thinking I'm not sure it is a good idea to "pollute"
libavcodec (and I can't find a simple way to implement this at the
library level), and I don't want to churn library code more than
necessary. Thus basically I'm reproposing this patch in the current
form, which fixes the problem for me.

A possible alternative to the current approach (which computes the
time value for the next split) would be to evaluate an expression for
every frame, so that for example:

would become:
expr:gte(t, n*10)

which would be more flexible.

Ideally we should be able to cope the problem in the most flexible way
in case we decide to extend filtering at the data level (so you can
set a filter/script which specifies the condition to enable keyframe
FFmpeg = Friendly Fostering MultiPurpose Embarassing Guru

More information about the ffmpeg-devel mailing list