diff mbox series

[FFmpeg-devel,2/5] fftools/cmdutils: Print filter input/output formats in help output

Message ID MN2PR04MB59816304644921218A52AAB3BAB79@MN2PR04MB5981.namprd04.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,1/5] avfilter/avfilter: Add avfilter_alloc() and avfilter_query_formats() for initializing filters without a graph | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Soft Works Oct. 13, 2021, 4:49 a.m. UTC
Exmaple command: ffmpeg -h filters=overlay

Output:

Filter overlay
  Overlay a video source on top of the input.
    slice threading supported
    Inputs:
       #0: main (video) [yuv420p, yuvj420p, yuva420p, nv12, nv21]
       #1: overlay (video) [yuva420p]
    Outputs:
       #0: default (video) [yuv420p, yuvj420p, yuva420p, nv12, nv21]
overlay AVOptions:
  x [...]

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 fftools/cmdutils.c | 89 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 84 insertions(+), 5 deletions(-)

Comments

Paul B Mahol Oct. 13, 2021, 7:17 a.m. UTC | #1
what about more complicated filters?
Soft Works Oct. 13, 2021, 7:22 a.m. UTC | #2
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Paul B Mahol
> Sent: Wednesday, October 13, 2021 9:18 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> filter input/output formats in help output
> 
> what about more complicated filters?

I guess you mean like this:

Filter amix
  Audio mixing.
    Inputs:
        dynamic (depending on the options)
    Outputs:
       #0: default (audio) [flt, fltp, dbl, dblp]
amix AVOptions:
  inputs            <int>        ..F.A...... Number of inputs. (from 1 to 32767) (default 2)
  duration          <int>        ..F.A...... How to determine the end-of-stream. (from 0 to 2) (default longest)
     longest         0            ..F.A...... Duration of longest input.
     shortest        1            ..F.A...... Duration of shortest input.
     first           2            ..F.A...... Duration of first input.
  dropout_transition <float>      ..F.A...... Transition time, in seconds, for volume renormalization when an input stream ends. (from 0 to INT_MAX) (default 2)
  weights           <string>     ..F.A....T. Set weight for each input. (default "1 1")
  normalize         <boolean>    ..F.A....T. Scale inputs (default true)
Paul B Mahol Oct. 13, 2021, 7:27 a.m. UTC | #3
scale, extractplanes, alphaextract, waveform, vectorscope.
Soft Works Oct. 13, 2021, 7:35 a.m. UTC | #4
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Paul B Mahol
> Sent: Wednesday, October 13, 2021 9:27 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> filter input/output formats in help output
> 
> scale, extractplanes, alphaextract, waveform, vectorscope.

See the results below. Nothing is flawed. Of course there can't be an
output in all cases, as you have pointed out correctly.

But for the remaining 95% of filters, the formats output is very useful.
(and correct)


Filter extractplanes
  Extract planes as grayscale frames.
    Inputs:
       #0: default (video)
    Outputs:
        dynamic (depending on the options)
extractplanes AVOptions:


Filter alphaextract
  Extract an alpha channel as a grayscale image component.
    Inputs:
       #0: default (video)
    Outputs:
        dynamic (depending on the options)


Filter waveform
  Video waveform monitor.
    slice threading supported
    Inputs:
       #0: default (video)
    Outputs:
       #0: default (video)
waveform AVOptions:


Filter vectorscope
  Video vectorscope.
    Inputs:
       #0: default (video)
    Outputs:
       #0: default (video)
vectorscope AVOptions:
Soft Works Oct. 13, 2021, 7:58 a.m. UTC | #5
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Soft Works
> Sent: Wednesday, October 13, 2021 9:36 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> filter input/output formats in help output
> 
> 
> 
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > Paul B Mahol
> > Sent: Wednesday, October 13, 2021 9:27 AM
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> > filter input/output formats in help output
> >
> > scale, extractplanes, alphaextract, waveform, vectorscope.
> 
> See the results below. Nothing is flawed. Of course there can't be an
> output in all cases, as you have pointed out correctly.
> 
> But for the remaining 95% of filters, the formats output is very
> useful.
> (and correct)

I'd also like to point out that this information is currently completely
inaccessible for anybody without looking it up in the source code.

Knowing about a filter's supported formats is important for building
efficient filter chains and avoiding unexpected auto format 
conversions.

I had added this output years ago and the information (which is 
parsed from the help output) is an important prerequisite for our 
automated filter-string-building (outside of ffmpeg).

I also use it regularly for looking up filter formats and I think
it might be useful for others as well.

Kind regards,
softworkz
Paul B Mahol Oct. 13, 2021, 8:15 a.m. UTC | #6
On Wed, Oct 13, 2021 at 9:58 AM Soft Works <softworkz@hotmail.com> wrote:

>
>
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > Soft Works
> > Sent: Wednesday, October 13, 2021 9:36 AM
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> > filter input/output formats in help output
> >
> >
> >
> > > -----Original Message-----
> > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > Paul B Mahol
> > > Sent: Wednesday, October 13, 2021 9:27 AM
> > > To: FFmpeg development discussions and patches <ffmpeg-
> > > devel@ffmpeg.org>
> > > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> > > filter input/output formats in help output
> > >
> > > scale, extractplanes, alphaextract, waveform, vectorscope.
> >
> > See the results below. Nothing is flawed. Of course there can't be an
> > output in all cases, as you have pointed out correctly.
> >
> > But for the remaining 95% of filters, the formats output is very
> > useful.
> > (and correct)
>

As proved by above, this is big hack and should not be applied, its also
ugly.


>
> I'd also like to point out that this information is currently completely
> inaccessible for anybody without looking it up in the source code.
>
> Knowing about a filter's supported formats is important for building
> efficient filter chains and avoiding unexpected auto format
> conversions.
>
> I had added this output years ago and the information (which is
> parsed from the help output) is an important prerequisite for our
> automated filter-string-building (outside of ffmpeg).
>
> I also use it regularly for looking up filter formats and I think
> it might be useful for others as well.
>
> Kind regards,
> softworkz
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Soft Works Oct. 13, 2021, 8:24 a.m. UTC | #7
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Paul B Mahol
> Sent: Wednesday, October 13, 2021 10:16 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> filter input/output formats in help output
> 
> On Wed, Oct 13, 2021 at 9:58 AM Soft Works <softworkz@hotmail.com>
> wrote:
> 
> >
> >
> > > -----Original Message-----
> > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > Soft Works
> > > Sent: Wednesday, October 13, 2021 9:36 AM
> > > To: FFmpeg development discussions and patches <ffmpeg-
> > > devel@ffmpeg.org>
> > > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> > > filter input/output formats in help output
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf
> Of
> > > > Paul B Mahol
> > > > Sent: Wednesday, October 13, 2021 9:27 AM
> > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > > devel@ffmpeg.org>
> > > > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> > > > filter input/output formats in help output
> > > >
> > > > scale, extractplanes, alphaextract, waveform, vectorscope.
> > >
> > > See the results below. Nothing is flawed. Of course there can't
> be an
> > > output in all cases, as you have pointed out correctly.
> > >
> > > But for the remaining 95% of filters, the formats output is very
> > > useful.
> > > (and correct)
> >
> 
> As proved by above, this is big hack and should not be applied, its
> also
> ugly.

I'm not sure what you mean. I do not see at which point this would 
qualify as a hack.

Anyway, then - would you have a better suggestion for getting at 
and printing out this information?

Or do you want to say that this information should remain hidden
knowledge only available to developers?

Thanks,
softworkz
Paul B Mahol Oct. 13, 2021, 8:41 a.m. UTC | #8
On Wed, Oct 13, 2021 at 10:24 AM Soft Works <softworkz@hotmail.com> wrote:

>
>
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > Paul B Mahol
> > Sent: Wednesday, October 13, 2021 10:16 AM
> > To: FFmpeg development discussions and patches <ffmpeg-
> > devel@ffmpeg.org>
> > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> > filter input/output formats in help output
> >
> > On Wed, Oct 13, 2021 at 9:58 AM Soft Works <softworkz@hotmail.com>
> > wrote:
> >
> > >
> > >
> > > > -----Original Message-----
> > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > > Soft Works
> > > > Sent: Wednesday, October 13, 2021 9:36 AM
> > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > > devel@ffmpeg.org>
> > > > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> > > > filter input/output formats in help output
> > > >
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf
> > Of
> > > > > Paul B Mahol
> > > > > Sent: Wednesday, October 13, 2021 9:27 AM
> > > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > > > devel@ffmpeg.org>
> > > > > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> > > > > filter input/output formats in help output
> > > > >
> > > > > scale, extractplanes, alphaextract, waveform, vectorscope.
> > > >
> > > > See the results below. Nothing is flawed. Of course there can't
> > be an
> > > > output in all cases, as you have pointed out correctly.
> > > >
> > > > But for the remaining 95% of filters, the formats output is very
> > > > useful.
> > > > (and correct)
> > >
> >
> > As proved by above, this is big hack and should not be applied, its
> > also
> > ugly.
>
> I'm not sure what you mean. I do not see at which point this would
> qualify as a hack.
>
> Anyway, then - would you have a better suggestion for getting at
> and printing out this information?
>
> Or do you want to say that this information should remain hidden
> knowledge only available to developers?
>

Formats can differ between each  input and output pad.


>
> Thanks,
> softworkz
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
Soft Works Oct. 13, 2021, 8:48 a.m. UTC | #9
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> Paul B Mahol
> Sent: Wednesday, October 13, 2021 10:42 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> filter input/output formats in help output
> 
> On Wed, Oct 13, 2021 at 10:24 AM Soft Works <softworkz@hotmail.com>
> wrote:
> 
> >
> >
> > > -----Original Message-----
> > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of
> > > Paul B Mahol
> > > Sent: Wednesday, October 13, 2021 10:16 AM
> > > To: FFmpeg development discussions and patches <ffmpeg-
> > > devel@ffmpeg.org>
> > > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils: Print
> > > filter input/output formats in help output
> > >
> > > On Wed, Oct 13, 2021 at 9:58 AM Soft Works
> <softworkz@hotmail.com>
> > > wrote:
> > >
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On
> Behalf Of
> > > > > Soft Works
> > > > > Sent: Wednesday, October 13, 2021 9:36 AM
> > > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > > > devel@ffmpeg.org>
> > > > > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils:
> Print
> > > > > filter input/output formats in help output
> > > > >
> > > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On
> Behalf
> > > Of
> > > > > > Paul B Mahol
> > > > > > Sent: Wednesday, October 13, 2021 9:27 AM
> > > > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > > > > devel@ffmpeg.org>
> > > > > > Subject: Re: [FFmpeg-devel] [PATCH 2/5] fftools/cmdutils:
> Print
> > > > > > filter input/output formats in help output
> > > > > >
> > > > > > scale, extractplanes, alphaextract, waveform, vectorscope.
> > > > >
> > > > > See the results below. Nothing is flawed. Of course there
> can't
> > > be an
> > > > > output in all cases, as you have pointed out correctly.
> > > > >
> > > > > But for the remaining 95% of filters, the formats output is
> very
> > > > > useful.
> > > > > (and correct)
> > > >
> > >
> > > As proved by above, this is big hack and should not be applied,
> its
> > > also
> > > ugly.
> >
> > I'm not sure what you mean. I do not see at which point this would
> > qualify as a hack.
> >
> > Anyway, then - would you have a better suggestion for getting at
> > and printing out this information?
> >
> > Or do you want to say that this information should remain hidden
> > knowledge only available to developers?
> >
> 
> Formats can differ between each  input and output pad.

Yes, and this is shown correctly:

Filter paletteuse
  Use a palette to downsample an input video stream.
    Inputs:
       #0: default (video) [bgra]
       #1: palette (video) [bgra]
    Outputs:
       #0: default (video) [pal8]
...

No hack :-)

softworkz
diff mbox series

Patch

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index aa706c33ab..a112998574 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -33,6 +33,7 @@ 
 #include "compat/va_copy.h"
 #include "libavformat/avformat.h"
 #include "libavfilter/avfilter.h"
+#include <libavfilter/formats.h>
 #include "libavdevice/avdevice.h"
 #include "libswscale/swscale.h"
 #include "libswresample/swresample.h"
@@ -1922,11 +1923,38 @@  static void show_help_muxer(const char *name)
 }
 
 #if CONFIG_AVFILTER
+static void print_link_formats(enum AVMediaType mediaType, AVFilterFormats* formats)
+{
+    if (formats == NULL)
+        return;
+
+    printf(" [");
+
+    for (unsigned i = 0; i < formats->nb_formats; i++) {
+        if (formats->formats[i] >= 0) {
+            if (i > 0)
+                printf(", ");
+            if (mediaType == AVMEDIA_TYPE_VIDEO) {
+                printf("%s", av_get_pix_fmt_name(formats->formats[i]));
+            } else if (mediaType == AVMEDIA_TYPE_AUDIO) {
+                printf("%s", av_get_sample_fmt_name(formats->formats[i]));
+            // TODO: Uncomment once subtitle filtering is added
+            ////} else if (mediaType == AVMEDIA_TYPE_SUBTITLE) {
+            ////    printf("%s", av_get_subtitle_fmt_name(formats->formats[i]));
+            }
+        }
+    }
+
+    printf("]");
+}
+
 static void show_help_filter(const char *name)
 {
 #if CONFIG_AVFILTER
     const AVFilter *f = avfilter_get_by_name(name);
-    int i, count;
+    unsigned i, count;
+    int got_formats = 0;
+    AVFilterContext *filter_context;
 
     if (!name) {
         av_log(NULL, AV_LOG_ERROR, "No filter name specified.\n");
@@ -1943,12 +1971,50 @@  static void show_help_filter(const char *name)
     if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
         printf("    slice threading supported\n");
 
+    filter_context = avfilter_alloc(f, "filter");
+    if (!filter_context) {
+        av_log(NULL, AV_LOG_ERROR, "Failed create filtercontext\n");
+        return;
+    }
+
+    if (filter_context->nb_outputs == 0) {
+        filter_context->outputs= av_calloc(1, sizeof(AVFilterLink*));
+        filter_context->outputs[0] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink));
+    }
+
+    if (filter_context->nb_inputs == 0) {
+        filter_context->inputs= av_calloc(1, sizeof(AVFilterLink*));
+        filter_context->inputs[0] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink));
+    }
+
+    for (i = 0; i < filter_context->nb_inputs; i++)
+        filter_context->inputs[i] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink));
+    
+    for (i = 0; i < filter_context->nb_outputs; i++)
+        filter_context->outputs[i] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink));
+
+    if (filter_context->filter->nb_inputs)
+        filter_context->inputs[0]->type = avfilter_pad_get_type(f->inputs, 0);
+
+    if (filter_context->filter->nb_outputs)
+        filter_context->outputs[0]->type = avfilter_pad_get_type(f->outputs, 0);
+
+    if (filter_context->nb_inputs > 0 || filter_context->nb_outputs > 0)
+        got_formats = !avfilter_query_formats(filter_context);
+
     printf("    Inputs:\n");
     count = avfilter_filter_pad_count(f, 0);
     for (i = 0; i < count; i++) {
-        printf("       #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
-               media_type_string(avfilter_pad_get_type(f->inputs, i)));
+        const enum AVMediaType media_type = avfilter_pad_get_type(f->inputs, i);
+
+        printf("       #%d: %s (%s)", i, avfilter_pad_get_name(f->inputs, i),
+               media_type_string(media_type));
+
+        if (got_formats && (i < filter_context->nb_inputs))
+            print_link_formats(media_type, filter_context->inputs[i]->outcfg.formats);
+        printf("\n");
     }
+
     if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
         printf("        dynamic (depending on the options)\n");
     else if (!count)
@@ -1957,8 +2023,13 @@  static void show_help_filter(const char *name)
     printf("    Outputs:\n");
     count = avfilter_filter_pad_count(f, 1);
     for (i = 0; i < count; i++) {
-        printf("       #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
-               media_type_string(avfilter_pad_get_type(f->outputs, i)));
+        const enum AVMediaType media_type = avfilter_pad_get_type(f->outputs, i);
+        printf("       #%d: %s (%s)", i, avfilter_pad_get_name(f->outputs, i),
+               media_type_string(media_type));
+ 
+        if (got_formats && i < filter_context->nb_outputs)
+            print_link_formats(media_type, filter_context->outputs[i]->incfg.formats);
+        printf("\n");
     }
     if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
         printf("        dynamic (depending on the options)\n");
@@ -1970,6 +2041,14 @@  static void show_help_filter(const char *name)
                                           AV_OPT_FLAG_AUDIO_PARAM);
     if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
         printf("This filter has support for timeline through the 'enable' option.\n");
+
+    if (filter_context->nb_inputs == 0)
+        filter_context->nb_inputs = 1;
+    if (filter_context->nb_outputs == 0)
+        filter_context->nb_outputs = 1;
+
+    avfilter_free(filter_context);
+
 #else
     av_log(NULL, AV_LOG_ERROR, "Build without libavfilter; "
            "can not to satisfy request\n");