[FFmpeg-devel] [PATCH v2 4/4] fftools/ffmpeg_filter: add -dump_filter_graph option
Niklas Haas
ffmpeg at haasn.xyz
Tue Feb 18 14:46:03 EET 2025
From: Niklas Haas <git at haasn.dev>
Debugging option to dump the filter graph after insertion of auto-filters.
Named such to avoid clashing with the existing -dumpgraph option on lavfi
devices.
---
doc/ffmpeg.texi | 18 ++++++++++++++++++
fftools/ffmpeg.h | 1 +
fftools/ffmpeg_filter.c | 13 +++++++++++++
fftools/ffmpeg_opt.c | 4 ++++
libavfilter/vf_libplacebo.c | 2 +-
5 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index da6549f043..298c736b47 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -2768,6 +2768,24 @@ filter (scale, aresample) in the graph.
On by default, to explicitly disable it you need to specify
@code{-noauto_conversion_filters}.
+ at item -dump_filter_graph
+Print out the fully settled filter graph, after all automatic conversion
+and format restriction filters have been inserted. Accepts a key/value list of
+suboptions to influnce the output.
+ at table @option
+ at item format
+Choose the output format. Possible values are:
+
+ at table @option
+ at item none
+Don't print anything.
+ at item pretty
+Pretty-print an ASCII art graph. This is the default.
+ at item complex
+Print in a format suitable for consumption by @option{-filter_complex}.
+ at end table
+ at end table
+
@item -bits_per_raw_sample[:@var{stream_specifier}] @var{value} (@emph{output,per-stream})
Declare the number of bits per raw sample in the given output stream to be
@var{value}. Note that this option sets the information provided to the
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 6cc0da05a0..d6be3df539 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -715,6 +715,7 @@ extern char *filter_nbthreads;
extern int filter_complex_nbthreads;
extern int vstats_version;
extern int auto_conversion_filters;
+extern char *dump_filter_graph;
extern const AVIOInterruptCB int_cb;
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 800e2a3f06..5aa871c8ad 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -23,6 +23,7 @@
#include "ffmpeg.h"
#include "libavfilter/avfilter.h"
+#include "libavfilter/filters.h"
#include "libavfilter/buffersink.h"
#include "libavfilter/buffersrc.h"
@@ -1986,6 +1987,18 @@ static int configure_filtergraph(FilterGraph *fg, FilterGraphThread *fgt)
if ((ret = avfilter_graph_config(fgt->graph, NULL)) < 0)
goto fail;
+ /* Print the generated filter graph after insertion of auto filters */
+ if (dump_filter_graph) {
+ char *graph = avfilter_graph_dump(fgt->graph, dump_filter_graph);
+ if (graph)
+ av_log(NULL, AV_LOG_INFO, "%s", graph);
+ else
+ av_log(NULL, AV_LOG_ERROR, "Failed dumping filtergraph!\n");
+ }
+
+ avfilter_inout_free(&inputs);
+ avfilter_inout_free(&outputs);
+
fgp->is_meta = graph_is_meta(fgt->graph);
/* limit the lists of allowed formats to the ones selected, to
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 3c0c682594..aa8a6508ab 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -76,6 +76,7 @@ char *filter_nbthreads;
int filter_complex_nbthreads = 0;
int vstats_version = 2;
int auto_conversion_filters = 1;
+char *dump_filter_graph;
int64_t stats_period = 500000;
@@ -1733,6 +1734,9 @@ const OptionDef options[] = {
{ "auto_conversion_filters", OPT_TYPE_BOOL, OPT_EXPERT,
{ &auto_conversion_filters },
"enable automatic conversion filters globally" },
+ { "dump_filter_graph", OPT_TYPE_STRING, OPT_EXPERT,
+ { &dump_filter_graph },
+ "dump filter graph after insertion of auto-filters" },
{ "stats", OPT_TYPE_BOOL, 0,
{ &print_stats },
"print progress report during encoding", },
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index e1c6629f6d..20f5c2cf75 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -1288,7 +1288,7 @@ static const AVOption libplacebo_options[] = {
{ "force_divisible_by", "enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used", OFFSET(force_divisible_by), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 256, STATIC },
{ "normalize_sar", "force SAR normalization to 1:1 by adjusting pos_x/y/w/h", OFFSET(normalize_sar), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, STATIC },
{ "pad_crop_ratio", "ratio between padding and cropping when normalizing SAR (0=pad, 1=crop)", OFFSET(pad_crop_ratio), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, 1.0, DYNAMIC },
- { "fillcolor", "Background fill color", OFFSET(fillcolor), AV_OPT_TYPE_STRING, {.str = "black"}, .flags = DYNAMIC },
+ { "fillcolor", "Background fill color", OFFSET(fillcolor), AV_OPT_TYPE_STRING, {.str = "black at 0.0"}, .flags = DYNAMIC },
{ "corner_rounding", "Corner rounding radius", OFFSET(corner_rounding), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, .flags = DYNAMIC },
{ "extra_opts", "Pass extra libplacebo-specific options using a :-separated list of key=value pairs", OFFSET(extra_opts), AV_OPT_TYPE_DICT, .flags = DYNAMIC },
--
2.47.0
More information about the ffmpeg-devel
mailing list