[RFC] Dynamic filtergraph reconfiguration
Hi, maybe it's time to finally tackle this, since it seems to be a recurring issue. Sometimes the input of the filterchain changes configuration parameters. For audio it means it could change channel layout/sample rate/sample format/timebase, for video it may change frame rate, size, pixel format, sample aspect ratio and timebase. Basically most filters assume these values to be invariant during the whole life of the filtergraph, others (e.g. the scale filter) monitors *some* of the input values and reconfigure themselves accordingly, sometimes calling configure on the following filters (which may or may not be correct). We need to make reconfiguration consistently applied at the framework level, and properly design it, in order to avoid brittle code and glitches. Problems to tackle are: - not all filters may support reconfigurations, for example some filters rely on some specific values defined during configuration, so in general we need a mechanism which allows to reconfigure only the filters which can do that - some filters may support only *one* parameter change (e.g. timebase may easily change). - since we don't mark codecs/containers which support variable configuration parameters (do we?), we may need to "normalize" the output before the terminal sink (depending on the application). Related questions: where should we check the changes (possibly in the framework code)? Where should we add the "buffer" filters which normalize input towards a "non-reconfigurable" filter (possibly we should auto-insert it only when required). Filter supporting reconfiguration should be marked as such (or alternatively we may mark filters *not* supporting it). Also I wonder if we should also support filters where the *number* of inputs or outputs change dinamically (e.g. a movie source which adds a new stream). I'll try to come with a more detailed design and proof of concept once we'll clear some of the design issues. -- FFmpeg = Frightening and Faithful Murdering Pacific Explosive Guru
Hi, On Wed, Oct 24, 2012 at 5:21 PM, Stefano Sabatini <stefasab@gmail.com> wrote:
Hi,
maybe it's time to finally tackle this, since it seems to be a recurring issue.
Sometimes the input of the filterchain changes configuration parameters. For audio it means it could change channel layout/sample rate/sample format/timebase, for video it may change frame rate, size, pixel format, sample aspect ratio and timebase.
Basically most filters assume these values to be invariant during the whole life of the filtergraph, others (e.g. the scale filter) monitors *some* of the input values and reconfigure themselves accordingly, sometimes calling configure on the following filters (which may or may not be correct). We need to make reconfiguration consistently applied at the framework level, and properly design it, in order to avoid brittle code and glitches.
Problems to tackle are: - not all filters may support reconfigurations, for example some filters rely on some specific values defined during configuration, so in general we need a mechanism which allows to reconfigure only the filters which can do that
- some filters may support only *one* parameter change (e.g. timebase may easily change).
- since we don't mark codecs/containers which support variable configuration parameters (do we?), we may need to "normalize" the output before the terminal sink (depending on the application).
Related questions: where should we check the changes (possibly in the framework code)?
I think that would be nice (because then I wouldn't have to do it myself every time I use the C API)
Where should we add the "buffer" filters which normalize input towards a "non-reconfigurable" filter (possibly we should auto-insert it only when required).
Filter supporting reconfiguration should be marked as such (or alternatively we may mark filters *not* supporting it).
How detailed would this marking be? i.e. do you say "this filter supports total reconfiguration" and "this filter supports reconfiguring these 3 specific parameters" or do you say "this filter supports at least some reconfiguration" and just fail if an unsupported reconfiguration is attempted (and then auto-insert a "normalization" filter).
Also I wonder if we should also support filters where the *number* of inputs or outputs change dinamically (e.g. a movie source which adds a new stream).
That would be nice.
I'll try to come with a more detailed design and proof of concept once we'll clear some of the design issues.
Thanks for bringing this up. I'm really looking forward to this (however it's implemented). Are you also considering handling if one filter dynamically changes its output configuration parameters, even if it's in the middle of the filter graph? For example, an auto-crop filter that crops letterboxing on frames (and maybe there's a commercial segment with no letterboxing). I wonder how this would be affected by subtitle filters (when we get some)...
Le quartidi 4 brumaire, an CCXXI, Stefano Sabatini a écrit :
maybe it's time to finally tackle this, since it seems to be a recurring issue.
I agree.
Sometimes the input of the filterchain changes configuration parameters. For audio it means it could change channel layout/sample rate/sample format/timebase, for video it may change frame rate, size, pixel format, sample aspect ratio and timebase.
Basically most filters assume these values to be invariant during the whole life of the filtergraph, others (e.g. the scale filter) monitors *some* of the input values and reconfigure themselves accordingly, sometimes calling configure on the following filters (which may or may not be correct). We need to make reconfiguration consistently applied at the framework level, and properly design it, in order to avoid brittle code and glitches.
Good summary.
Problems to tackle are: - not all filters may support reconfigurations, for example some filters rely on some specific values defined during configuration, so in general we need a mechanism which allows to reconfigure only the filters which can do that
- some filters may support only *one* parameter change (e.g. timebase may easily change).
A bitmask on each input or input pad seems the obvious solution to both these problems.
- since we don't mark codecs/containers which support variable configuration parameters (do we?), we may need to "normalize" the output before the terminal sink (depending on the application).
The buffer sink can have an option to set the bitmask for supported configuration change: if an application needs constant output, it leaves it to its default 0.
Related questions: where should we check the changes (possibly in the framework code)?
IMHO, calling config_props when the configuration changes is a good. That means: for buffersrc, either detect or have an API to notify of a change, for other sources, on a case by case basis, and for any non-source filter, assume input is constant unless config_props is called on it, and call config_props before changing the output. We can provide an helper API: unsigned avfilter_detect_format_change(AVFilterLink *link, AVFilterBufferRef *ref); that returns the bitmask for the difference between link and ref.
Where should we add the "buffer" filters which normalize input towards a "non-reconfigurable" filter (possibly we should auto-insert it only when required).
Inserting only when necessary looks like the obvious solution. I suggest something like that: int avfilter_link_reconfigure(AVFilterLink *outlink, unsigned changed) { unsigned reconf = changed & outlink->dst->reconfigure_flags; unsigned normalize = changed & ~outlink->dst->reconfigure_flags; if (normalize) { ff_insert_normalization_filter(outlink, normalize); } if (reconf) { if (link->dstpad->config_props) link->dstpad->config_props(link); } } (with some more error checks, of course)
Filter supporting reconfiguration should be marked as such (or alternatively we may mark filters *not* supporting it). Also I wonder if we should also support filters where the *number* of inputs or outputs change dinamically (e.g. a movie source which adds a new stream).
I do not see how we could handle it without some kind of high-level language to describe the graph. I believe we can leave that out for now. Regards, -- Nicolas George
On 10/24/12, Stefano Sabatini <stefasab@gmail.com> wrote:
Hi,
maybe it's time to finally tackle this, since it seems to be a recurring issue.
Sometimes the input of the filterchain changes configuration parameters. For audio it means it could change channel layout/sample rate/sample format/timebase, for video it may change frame rate, size, pixel format, sample aspect ratio and timebase.
Basically most filters assume these values to be invariant during the whole life of the filtergraph, others (e.g. the scale filter) monitors *some* of the input values and reconfigure themselves accordingly, sometimes calling configure on the following filters (which may or may not be correct). We need to make reconfiguration consistently applied at the framework level, and properly design it, in order to avoid brittle code and glitches.
Problems to tackle are: - not all filters may support reconfigurations, for example some filters rely on some specific values defined during configuration, so in general we need a mechanism which allows to reconfigure only the filters which can do that
- some filters may support only *one* parameter change (e.g. timebase may easily change).
- since we don't mark codecs/containers which support variable configuration parameters (do we?), we may need to "normalize" the output before the terminal sink (depending on the application).
Related questions: where should we check the changes (possibly in the framework code)? Where should we add the "buffer" filters which normalize input towards a "non-reconfigurable" filter (possibly we should auto-insert it only when required).
Filter supporting reconfiguration should be marked as such (or alternatively we may mark filters *not* supporting it). Also I wonder if we should also support filters where the *number* of inputs or outputs change dinamically (e.g. a movie source which adds a new stream).
I'll try to come with a more detailed design and proof of concept once we'll clear some of the design issues. -- FFmpeg = Frightening and Faithful Murdering Pacific Explosive Guru _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Any updates?
participants (4)
-
Michael Bradshaw -
Nicolas George -
Paul B Mahol -
Stefano Sabatini