From 8bf3fe7e2a05809103527fa3d2a0fd8eeed3ef2a Mon Sep 17 00:00:00 2001 From: llyyr Date: Mon, 14 Aug 2023 21:11:11 +0530 Subject: [PATCH] f_lavfi: don't reject dynamic lavfi ins/outs Ideally, users should be using lavfi-complex instead of lavfi-bridge for such a use case, however currently lavfi-complex doesn't support hwdec. So we can allow filters with dynamic inputs to work with lavfi-bridge, at the cost of them only being able to take in only one input. This should probably be reverted when/if lavfi-complex has hwdec, but for now this allows us to use libplacebo as a video filter with hwdec in mpv again. --- DOCS/man/vf.rst | 6 ++++++ filters/f_lavfi.c | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/DOCS/man/vf.rst b/DOCS/man/vf.rst index bd3254e557..d42acdc44b 100644 --- a/DOCS/man/vf.rst +++ b/DOCS/man/vf.rst @@ -44,6 +44,12 @@ The exact syntax is: the ``lavfi`` filter, which uses a very similar syntax as mpv (MPlayer historically) to specify filters and their parameters. +.. note:: + + ``--vf`` can only take a single track as input, even if the filter supports + dynamic input. Filters that require multiple inputs can't be used. + Use ``--lavfi-complex`` for such a use case. This also applies for ``--af``. + Filters can be manipulated at run time. You can use ``@`` labels as described above in combination with the ``vf`` command (see `COMMAND INTERFACE`_) to get more control over this. Initially disabled filters with ``!`` are useful for diff --git a/filters/f_lavfi.c b/filters/f_lavfi.c index 597cf91fc0..ec50dd5946 100644 --- a/filters/f_lavfi.c +++ b/filters/f_lavfi.c @@ -981,9 +981,13 @@ static bool is_usable(const AVFilter *filter, int media_type) int nb_inputs = avfilter_pad_count(filter->inputs), nb_outputs = avfilter_pad_count(filter->outputs); #endif - return nb_inputs == 1 && nb_outputs == 1 && - avfilter_pad_get_type(filter->inputs, 0) == media_type && - avfilter_pad_get_type(filter->outputs, 0) == media_type; + bool input_ok = filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS; + bool output_ok = filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS; + if (nb_inputs == 1) + input_ok = avfilter_pad_get_type(filter->inputs, 0) == media_type; + if (nb_outputs == 1) + output_ok = avfilter_pad_get_type(filter->outputs, 0) == media_type; + return input_ok && output_ok; } bool mp_lavfi_is_usable(const char *name, int media_type)