[FFmpeg-devel] [PATCH v5 0/8] print_graphs: Complete Filtergraph Printing
ffmpegagent
ffmpegagent at gmail.com
Sat Mar 8 19:55:27 EET 2025
This new version of the patchset starts by extracting the text formatting
and writing APIs from ffprobe.c into a subfolder under fftools. The type
naming follows public API naming style, ramping up for making it a public
API in the future without another big renaming.
The extraction of the text formatting APIs can be followed in smaller steps
in the recent patchset "[RFC] avtextformat: Transform text writing into an
independent API". To make this more review-friendly, the ffprobe changes are
done in two steps. The 2nd commit includes all essential changes while the
large part of renamings is deferred to the 3rd commit (containing renamings
only).
The graph-printing uses the extracted APIs. It supports all ffprobe output
formats now. Otherwise it's functional equivalent to the previous version:
* Different to other graph printing methods, this is outputting:
* both, simple and complex filtergraphs
* all graphs with runtime state (including auto-inserted filters)
* each graph with its inputs and outputs
* all filters with their in- and output pads
* all connections between all input- and output pads
* for each connection:
* the runtime-negotiated format and media type
* the hw context
* if video hw context, both: hw pixfmt + sw pixfmt
* Output can either be printed to stdout or written to specified file
* Output is machine-readable
Right after filtergraph configuration, the connection details are often not
complete yet. On the other side, when waiting too long or if an error occurs
somewhere, the graph info might never be printed. Experience has shown, that
the most suitable and realiable point in time for printing graph information
is right before cleanup.
Due to the changes for multi-threading, this is no longer doable as easy as
before, so the following method is used: Each filtergraph initiates its own
graph printing short before cleanup into a buffer. Before final cleanup in
ffmpeg.c, the outputs from the individual graphs are pieced together for the
actual output to file or console. (the structure according to the output
format remains valid)
Example output:
https://gist.github.com/softworkz/2a9e8699b288f5d40fa381c2a496e165
Update V2
* Change NULL checks to match common code style
* Add Add avfilter_link_get_hw_frames_ctx() function to avoid importing
filters.h
* Do the same without including avfilter/filters.h (as per note from
Andreas Reinhardt)
Update V3
* Includes extraction and generalization of the text formatting APIs
* All output formats supported now
Update V4
* Fix "new warnings" were generated
* Fix missing colon in commit message
* Rebase due to changesin ApiChanges
Update V5
* Fix copyright headers
* Return proper error codes rather than -1
* Fix misnamed local functions
* Fix typo
* Rename 'w' in ffprobe.c to 'tfc'
softworkz (8):
fftools/textformat: Extract and generalize textformat api from
ffprobe.c
fftools/ffprobe: Change to use textformat api
fftools/ffprobe: Rename writer_print_section_* and WriterContext
fftools/ffmpeg_filter: Move some declaration to new header file
avfilter/avfilter: Add avfilter_link_get_hw_frames_ctx()
fftools/ffmpeg_graphprint: Add options for filtergraph printing
fftools: Enable filtergraph printing and update docs
fftools/ffprobe: Rename AVTextFormatContext variables (w => tc)
doc/APIchanges | 3 +
doc/ffmpeg.texi | 10 +
fftools/Makefile | 23 +
fftools/ffmpeg.c | 4 +
fftools/ffmpeg.h | 3 +
fftools/ffmpeg_filter.c | 193 +--
fftools/ffmpeg_filter.h | 232 +++
fftools/ffmpeg_graphprint.c | 518 +++++++
fftools/ffmpeg_graphprint.h | 35 +
fftools/ffmpeg_opt.c | 12 +
fftools/ffprobe.c | 2296 +++++-----------------------
fftools/textformat/avtextformat.c | 672 ++++++++
fftools/textformat/avtextformat.h | 171 +++
fftools/textformat/avtextwriters.h | 68 +
fftools/textformat/tf_compact.c | 282 ++++
fftools/textformat/tf_default.c | 145 ++
fftools/textformat/tf_flat.c | 174 +++
fftools/textformat/tf_ini.c | 160 ++
fftools/textformat/tf_json.c | 215 +++
fftools/textformat/tf_xml.c | 221 +++
fftools/textformat/tw_avio.c | 129 ++
fftools/textformat/tw_buffer.c | 92 ++
fftools/textformat/tw_stdout.c | 82 +
libavfilter/avfilter.c | 9 +
libavfilter/avfilter.h | 12 +
libavfilter/version.h | 2 +-
26 files changed, 3630 insertions(+), 2133 deletions(-)
create mode 100644 fftools/ffmpeg_filter.h
create mode 100644 fftools/ffmpeg_graphprint.c
create mode 100644 fftools/ffmpeg_graphprint.h
create mode 100644 fftools/textformat/avtextformat.c
create mode 100644 fftools/textformat/avtextformat.h
create mode 100644 fftools/textformat/avtextwriters.h
create mode 100644 fftools/textformat/tf_compact.c
create mode 100644 fftools/textformat/tf_default.c
create mode 100644 fftools/textformat/tf_flat.c
create mode 100644 fftools/textformat/tf_ini.c
create mode 100644 fftools/textformat/tf_json.c
create mode 100644 fftools/textformat/tf_xml.c
create mode 100644 fftools/textformat/tw_avio.c
create mode 100644 fftools/textformat/tw_buffer.c
create mode 100644 fftools/textformat/tw_stdout.c
base-commit: 0245e9382c748eba91645b65a377c4c9c4a44849
Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-52%2Fsoftworkz%2Fsubmit_print_graphs5-v5
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-52/softworkz/submit_print_graphs5-v5
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/52
Range-diff vs v4:
1: 55bfc6c6a6 ! 1: b26a45ea0e fftools/textformat: Extract and generalize textformat api from ffprobe.c
@@ Commit message
## fftools/textformat/avtextformat.c (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/avtextformat.c (new)
+ { 1.125899906842624e15, 1e15, "Pi", "P" },
+};
+
-+static const char *avtext_context_get_formatter_name(void *p)
++static const char *textcontext_get_formatter_name(void *p)
+{
+ AVTextFormatContext *tctx = p;
+ return tctx->formatter->name;
@@ fftools/textformat/avtextformat.c (new)
+ { NULL }
+};
+
-+static void *trextcontext_child_next(void *obj, void *prev)
++static void *textcontext_child_next(void *obj, void *prev)
+{
+ AVTextFormatContext *ctx = obj;
+ if (!prev && ctx->formatter && ctx->formatter->priv_class && ctx->priv)
@@ fftools/textformat/avtextformat.c (new)
+
+static const AVClass textcontext_class = {
+ .class_name = "AVTextContext",
-+ .item_name = avtext_context_get_formatter_name,
++ .item_name = textcontext_get_formatter_name,
+ .option = textcontext_options,
+ .version = LIBAVUTIL_VERSION_INT,
-+ .child_next = trextcontext_child_next,
++ .child_next = textcontext_child_next,
+};
+
+static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
@@ fftools/textformat/avtextformat.c (new)
+ int ret = 0;
+
+ if (!tctx)
-+ return -1;
++ return EINVAL;
+
+ av_hash_freep(&tctx->hash);
+
@@ fftools/textformat/avtextformat.c (new)
+
+ if (nb_sections > SECTION_MAX_NB_SECTIONS) {
+ av_log(tctx, AV_LOG_ERROR, "The number of section definitions (%d) is larger than the maximum allowed (%d)\n", nb_sections, SECTION_MAX_NB_SECTIONS);
++ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
@@ fftools/textformat/avtextformat.c (new)
+ av_bprint_finalize(&bp, NULL);
+}
+
-+static const char *avtextwriter_context_get_writer_name(void *p)
++static const char *writercontext_get_writer_name(void *p)
+{
+ AVTextWriterContext *wctx = p;
+ return wctx->writer->name;
@@ fftools/textformat/avtextformat.c (new)
+
+static const AVClass textwriter_class = {
+ .class_name = "AVTextWriterContext",
-+ .item_name = avtextwriter_context_get_writer_name,
++ .item_name = writercontext_get_writer_name,
+ .version = LIBAVUTIL_VERSION_INT,
+ .child_next = writercontext_child_next,
+};
@@ fftools/textformat/avtextformat.c (new)
+ int ret = 0;
+
+ if (!wctx)
-+ return -1;
++ return EINVAL;
+
+ if (wctx->writer->uninit)
+ wctx->writer->uninit(wctx);
@@ fftools/textformat/avtextformat.c (new)
## fftools/textformat/avtextformat.h (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/avtextformat.h (new)
+#define AV_TEXTFORMAT_PRINT_STRING_OPTIONAL 1
+#define AV_TEXTFORMAT_PRINT_STRING_VALIDATE 2
+
-+int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer, const char *args,
++int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args,
+ const struct AVTextFormatSection *sections, int nb_sections,
+ int show_value_unit,
+ int use_value_prefix,
@@ fftools/textformat/avtextformat.h (new)
## fftools/textformat/avtextwriters.h (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/avtextwriters.h (new)
## fftools/textformat/tf_compact.c (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/tf_compact.c (new)
## fftools/textformat/tf_default.c (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/tf_default.c (new)
## fftools/textformat/tf_flat.c (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/tf_flat.c (new)
## fftools/textformat/tf_ini.c (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/tf_ini.c (new)
## fftools/textformat/tf_json.c (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/tf_json.c (new)
## fftools/textformat/tf_xml.c (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/tf_xml.c (new)
## fftools/textformat/tw_avio.c (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/tw_avio.c (new)
## fftools/textformat/tw_buffer.c (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
@@ fftools/textformat/tw_buffer.c (new)
## fftools/textformat/tw_stdout.c (new) ##
@@
+/*
-+ * Copyright (c) The ffmpeg developers
++ * Copyright (c) The FFmpeg developers
+ *
+ * This file is part of FFmpeg.
+ *
2: 1950903610 = 2: 2eb2b4ded5 fftools/ffprobe: Change to use textformat api
3: 01cc022c3b = 3: 5ab9ac2a28 fftools/ffprobe: Rename writer_print_section_* and WriterContext
4: aed98ad79d = 4: 85735035e4 fftools/ffmpeg_filter: Move some declaration to new header file
5: 4b8d7ee51b = 5: 811c5ab35c avfilter/avfilter: Add avfilter_link_get_hw_frames_ctx()
6: f43eb56f39 = 6: 8ae08a7006 fftools/ffmpeg_graphprint: Add options for filtergraph printing
7: c0cf4adcd9 = 7: 03663768dd fftools: Enable filtergraph printing and update docs
-: ---------- > 8: 61dc171fa1 fftools/ffprobe: Rename AVTextFormatContext variables (w => tc)
--
ffmpeg-codebot
More information about the ffmpeg-devel
mailing list