[FFmpeg-devel] [PATCH 5/5] avfilter/avfilter: Apply options in one av_opt_set_dict2() call

Nicolas George george at nsup.org
Wed Sep 15 20:56:15 EEST 2021


Andreas Rheinhardt (12021-09-15):
> Up until now, avfilter_init_dict() first applied the generic options
> via av_opt_set_dict(), then set the filter-specific options via
> av_opt_set_dict2() applied to the private context with the
> AV_OPT_SEARCH_CHILDREN flag set (this ensures that e.g. framesync
> options are set, too). For filters with the init_dict callback
> the remaining options were passed to it.
> 
> This has the downside that all non-generic options are copied to
> a new dictionary in the first av_opt_set_dict() which involves
> allocations. This commit changes this by using av_opt_set_dict2()
> on the AVFilterContext to set all options (except those for init_dict)
> in one step. In order to ensure that the generic options are still
> applied first, the new AV_OPT_SEARCH_CHILDREN_AFTER_ME flag is used.
> This also reverses the search order between the private context and
> its children (if any), but this is actually more logical (the child
> contexts are more generic, hence the more special private context
> options should take precedence) as well as irrelevant (there is some
> option duplication*, but all duplicated options are entirely equivalent).
> Notice that there is also no option collision between the generic option
> and any child option (i.e. one could have used AV_OPT_SEARCH_CHILDREN)
> as well, but there might be some day: E.g. both the AVFilterContext
> class as well as the swresample class have an option named "threads".
> If the scale filters would expose this class in their preinit callback,
> there would be a problem when using AV_OPT_SEARCH_CHILDREN.
> 
> Finally, in case an error happens in the second step
> (e.g. due to an option being out-of-range) the name and address
> of the AVFilterContext instead of the private context are used.
> This allows the user to more easily map this error to the actual filter.

I think it is ok, but I think AV_OPT_SEARCH_CHILDREN_AFTER_ME should be
the default. Also, we should try to simplify the logic to make all this
long explanation no longer relevant.

IIRC, we reserved a character in options name to introduce context. That
would fix the issue of overloaded options: lavfi.threads= vs.
sws.threads=.

> *: Several overlay filters duplicate framesync options (to preserve
> the ability to set them via the shorthand notation).

We should deprecate and eventually remove that. Shorthand notation is
for the main options, those that need to be there otherwise it will
probably do nothing useful.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20210915/b798d29a/attachment.sig>


More information about the ffmpeg-devel mailing list