[FFmpeg-devel] [PATCH] avfilter/formats: set audio fmt lists for vaf filters

Nicolas George george at nsup.org
Tue Dec 19 17:03:51 EET 2023


Niklas Haas (12023-12-14):
> From: Niklas Haas <git at haasn.dev>
> 
> Currently, the logic inside the FF_FILTER_FORMATS_QUERY_FUNC branch
> prevents this code from running in the event that we have a filter with
> a single video input and a single audio output, as the resulting audio
> output link will not have its channel counts / samplerates correctly
> initialized to their default values, possibly triggering a segfault
> downstream.
> 
> An example of such a filter is vaf_spectrumsynth. Although this
> particular filter already sets up the channel counts and samplerates as
> part of the query function and therefore avoids triggering this bug, the
> bug still exists in principle. (And importantly, sets a wrong precedent)
> ---
>  libavfilter/formats.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

You are asking the framework to guess the audio format when it has
NOTHING to base its guess on. This is a terrible idea.

When a filter has no audio input but must produce audio, only the filter
itself knows what kind of audio it will produce, and it should say so in
query_formats().

What happens in spectrumsynth is what MUST happens. It is not a wrong
precedent, it is the proper way of things.

The worry that a filter will forget to do so and result in a segfault
seems wrong to me: just testing the filter before committing would
reveal it, not even regression testing is necessary.

But if you really want, I would not object to a consistency check after
the call to query_formats().

Regards,

-- 
  Nicolas George


More information about the ffmpeg-devel mailing list