[FFmpeg-devel] [PATCH v7 0/7] print_graphs: Complete Filtergraph Printing
ffmpegagent
ffmpegagent at gmail.com
Wed Mar 12 06:04:18 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'
Update V6
* Fix commit message (8)
* Revert renaming of context in main()
Update V7
* Fix code style issues in ffmpeg_graphprint and other files
* Rename w > tfc in ffmpeg_graphprint
* Use snake_case for output element names
* Rework ouitput
* Reduce properties for inputs and outputs
* Use clear names for filters and src/dest
* Add color_range and color_space properties
* Drop extra device_context section
* Remove unused section definitions (as per notes by Stefano Sabatini,
thanks!)
softworkz (7):
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/ffprobe: Rename AVTextFormatContext variables (w => tfc)
doc/APIchanges | 3 +
doc/ffmpeg.texi | 11 +
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 | 470 ++++++
fftools/ffmpeg_graphprint.h | 35 +
fftools/ffmpeg_opt.c | 12 +
fftools/ffprobe.c | 2296 +++++-----------------------
fftools/textformat/avtextformat.c | 674 ++++++++
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, 3585 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: 0b097ed9f141f57e2b91f0704c721a9eff0204c0
Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-52%2Fsoftworkz%2Fsubmit_print_graphs5-v7
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-52/softworkz/submit_print_graphs5-v7
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/52
Range-diff vs v6:
1: b26a45ea0e = 1: f379c77e88 fftools/textformat: Extract and generalize textformat api from ffprobe.c
2: 2eb2b4ded5 = 2: 67bc38ac96 fftools/ffprobe: Change to use textformat api
3: 5ab9ac2a28 = 3: 52c41fdcd0 fftools/ffprobe: Rename writer_print_section_* and WriterContext
4: 85735035e4 = 4: 21480a08b1 fftools/ffmpeg_filter: Move some declaration to new header file
5: 811c5ab35c ! 5: 70ba7a8bc9 avfilter/avfilter: Add avfilter_link_get_hw_frames_ctx()
@@ doc/APIchanges: The last version increases of all libraries were on 2024-03-07
+2025-02-xx - xxxxxxxxxx - lavfi 10.10.100 - avfilter.h
+ Add avfilter_link_get_hw_frames_ctx().
+
- 2025-03-01 - xxxxxxxxxx - lavu 59.58.100 - pixfmt.h
- Add AV_PIX_FMT_GRAY32BE and AV_PIX_FMT_GRAY32LE.
-
+ 2025-03-10 - xxxxxxxxxx - lavu 59.59.100 - pixfmt.h
+ Add AV_PIX_FMT_YAF16BE, AV_PIX_FMT_YAF16LE, AV_PIX_FMT_YAF32BE,
+ and AV_PIX_FMT_YAF32LE.
## libavfilter/avfilter.c ##
@@ libavfilter/avfilter.c: enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
@@ libavfilter/avfilter.c: enum AVMediaType avfilter_pad_get_type(const AVFilterPad
+AVBufferRef *avfilter_link_get_hw_frames_ctx(AVFilterLink *link)
+{
-+ FilterLink* plink = ff_filter_link(link);
++ FilterLink *plink = ff_filter_link(link);
+ if (plink->hw_frames_ctx)
+ return av_buffer_ref(plink->hw_frames_ctx);
+
@@ libavfilter/avfilter.h: const char *avfilter_pad_get_name(const AVFilterPad *pad
+ *
+ * @param link an AVFilterLink
+ *
-+ * @return a ref-counted copy of the link's hw_frames_ctx if there's a hardware
-+ * frames context associated with the link or NULL otherwise.
++ * @return a ref-counted copy of the link's hw_frames_ctx field if there is
++ * a hardware frames context associated with the link or NULL otherwise.
+ * The returned AVBufferRef needs to be released with av_buffer_unref()
-+ * when it's no longer used.
++ * when it is no longer used.
+ */
+AVBufferRef* avfilter_link_get_hw_frames_ctx(AVFilterLink *link);
+
6: 8ae08a7006 ! 6: a30ded4d62 fftools/ffmpeg_graphprint: Add options for filtergraph printing
@@ Metadata
## Commit message ##
fftools/ffmpeg_graphprint: Add options for filtergraph printing
+ Enables filtergraph printing and adds the options to the docs
+
The key benefits are:
- Different to other graph printing methods, this is outputting:
@@ Commit message
Signed-off-by: softworkz <softworkz at hotmail.com>
+ ## doc/ffmpeg.texi ##
+@@ doc/ffmpeg.texi: It is on by default, to explicitly disable it you need to specify @code{-nostats
+ @item -stats_period @var{time} (@emph{global})
+ Set period at which encoding progress/statistics are updated. Default is 0.5 seconds.
+
++ at item -print_graphs (@emph{global})
++Prints filtergraph details to stderr in the format set via -print_graphs_format.
++
++ at item -print_graphs_file @var{filename} (@emph{global})
++Writes filtergraph details to the specified file in the format set via -print_graphs_format.
++Use a dash (-) for the file name to write to stdout.
++
++ at item -print_graphs_format @var{format} (@emph{global})
++Sets the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)
++The default format is json.
++
+ @item -progress @var{url} (@emph{global})
+ Send program-friendly progress information to @var{url}.
+
+
## fftools/Makefile ##
@@ fftools/Makefile: OBJS-ffmpeg += \
fftools/ffmpeg_mux_init.o \
@@ fftools/Makefile: OBJS-ffmpeg += \
OBJS-ffprobe += \
fftools/textformat/avtextformat.o \
+ ## fftools/ffmpeg.c ##
+@@
+ #include "ffmpeg.h"
+ #include "ffmpeg_sched.h"
+ #include "ffmpeg_utils.h"
++#include "ffmpeg_graphprint.h"
+
+ const char program_name[] = "ffmpeg";
+ const int program_birth_year = 2000;
+@@ fftools/ffmpeg.c: const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL };
+
+ static void ffmpeg_cleanup(int ret)
+ {
++ if (print_graphs || print_graphs_file)
++ print_filtergraphs(filtergraphs, nb_filtergraphs, output_files, nb_output_files);
++
+ if (do_benchmark) {
+ int64_t maxrss = getmaxrss() / 1024;
+ av_log(NULL, AV_LOG_INFO, "bench: maxrss=%"PRId64"KiB\n", maxrss);
+
## fftools/ffmpeg.h ##
@@ fftools/ffmpeg.h: extern float max_error_rate;
extern char *filter_nbthreads;
extern int filter_complex_nbthreads;
extern int vstats_version;
+extern int print_graphs;
-+extern char* print_graphs_file;
-+extern char* print_graphs_format;
++extern char *print_graphs_file;
++extern char *print_graphs_format;
extern int auto_conversion_filters;
extern const AVIOInterruptCB int_cb;
+ ## fftools/ffmpeg_filter.c ##
+@@
+
+ #include "ffmpeg.h"
+ #include "ffmpeg_filter.h"
++#include "ffmpeg_graphprint.h"
+
+ #include "libavfilter/avfilter.h"
+ #include "libavfilter/buffersink.h"
+@@ fftools/ffmpeg_filter.c: read_frames:
+ }
+
+ finish:
++
++ if (print_graphs || print_graphs_file)
++ print_filtergraph(fg, fgt.graph);
++
+ // EOF is normal termination
+ if (ret == AVERROR_EOF)
+ ret = 0;
+
## fftools/ffmpeg_graphprint.c (new) ##
@@
+/*
@@ fftools/ffmpeg_graphprint.c (new)
+ SECTION_ID_OUTPUT,
+ SECTION_ID_FILTERS,
+ SECTION_ID_FILTER,
-+ SECTION_ID_HWDEViCECONTEXT,
+ SECTION_ID_HWFRAMESCONTEXT,
-+ SECTION_ID_ERROR,
-+ SECTION_ID_LOG,
-+ SECTION_ID_LOGS,
+} SectionID;
+
+static struct AVTextFormatSection sections[] = {
-+ [SECTION_ID_ROOT] = { SECTION_ID_ROOT, "GraphDescription", AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER,
-+ { SECTION_ID_ERROR, SECTION_ID_PROGRAM_VERSION, SECTION_ID_FILTERGRAPHS, SECTION_ID_LOGS, -1} },
-+ [SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "ProgramVersion", 0, { -1 } },
-+
-+ [SECTION_ID_FILTERGRAPHS] = { SECTION_ID_FILTERGRAPHS, "Graphs", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_FILTERGRAPH, -1 } },
-+ [SECTION_ID_FILTERGRAPH] = { SECTION_ID_FILTERGRAPH, "Graph", 0, { SECTION_ID_INPUTS, SECTION_ID_OUTPUTS, SECTION_ID_FILTERS, -1 }, },
++ [SECTION_ID_ROOT] = { SECTION_ID_ROOT, "graph_description", AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER,
++ { SECTION_ID_PROGRAM_VERSION, SECTION_ID_FILTERGRAPHS, -1} },
++ [SECTION_ID_PROGRAM_VERSION] = { SECTION_ID_PROGRAM_VERSION, "program_version", 0, { -1 } },
+
-+ [SECTION_ID_INPUTS] = { SECTION_ID_INPUTS, "Inputs", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_INPUT, SECTION_ID_ERROR, -1 } },
-+ [SECTION_ID_INPUT] = { SECTION_ID_INPUT, "Input", 0, { SECTION_ID_HWFRAMESCONTEXT, SECTION_ID_ERROR, -1 }, },
++ [SECTION_ID_FILTERGRAPHS] = { SECTION_ID_FILTERGRAPHS, "graphs", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_FILTERGRAPH, -1 } },
++ [SECTION_ID_FILTERGRAPH] = { SECTION_ID_FILTERGRAPH, "graph", 0, { SECTION_ID_INPUTS, SECTION_ID_OUTPUTS, SECTION_ID_FILTERS, -1 }, },
+
-+ [SECTION_ID_OUTPUTS] = { SECTION_ID_OUTPUTS, "Outputs", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_OUTPUT, SECTION_ID_ERROR, -1 } },
-+ [SECTION_ID_OUTPUT] = { SECTION_ID_OUTPUT, "Output", 0, { SECTION_ID_HWFRAMESCONTEXT, SECTION_ID_ERROR, -1 }, },
++ [SECTION_ID_INPUTS] = { SECTION_ID_INPUTS, "inputs", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_INPUT, -1 } },
++ [SECTION_ID_INPUT] = { SECTION_ID_INPUT, "input", 0, { SECTION_ID_HWFRAMESCONTEXT, -1 }, },
+
-+ [SECTION_ID_FILTERS] = { SECTION_ID_FILTERS, "Filters", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_FILTER, SECTION_ID_ERROR, -1 } },
-+ [SECTION_ID_FILTER] = { SECTION_ID_FILTER, "Filter", 0, { SECTION_ID_HWDEViCECONTEXT, SECTION_ID_ERROR, -1 }, },
++ [SECTION_ID_OUTPUTS] = { SECTION_ID_OUTPUTS, "outputs", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_OUTPUT, -1 } },
++ [SECTION_ID_OUTPUT] = { SECTION_ID_OUTPUT, "output", 0, { SECTION_ID_HWFRAMESCONTEXT, -1 }, },
+
-+ [SECTION_ID_HWDEViCECONTEXT] = { SECTION_ID_HWDEViCECONTEXT, "HwDeviceContext", 0, { SECTION_ID_ERROR, -1 }, },
-+ [SECTION_ID_HWFRAMESCONTEXT] = { SECTION_ID_HWFRAMESCONTEXT, "HwFramesContext", 0, { SECTION_ID_ERROR, -1 }, },
++ [SECTION_ID_FILTERS] = { SECTION_ID_FILTERS, "filters", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_FILTER, -1 } },
++ [SECTION_ID_FILTER] = { SECTION_ID_FILTER, "filter", 0, { -1 }, },
+
-+ [SECTION_ID_ERROR] = { SECTION_ID_ERROR, "Error", 0, { -1 } },
-+ [SECTION_ID_LOGS] = { SECTION_ID_LOGS, "Log", AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY, { SECTION_ID_LOG, -1 } },
-+ [SECTION_ID_LOG] = { SECTION_ID_LOG, "LogEntry", 0, { -1 }, },
++ [SECTION_ID_HWFRAMESCONTEXT] = { SECTION_ID_HWFRAMESCONTEXT, "hw_frames_context", 0, { -1 }, },
+};
+
+/* Text Format API Shortcuts */
-+#define print_int(k, v) avtext_print_integer(w, k, v)
-+#define print_q(k, v, s) avtext_print_rational(w, k, v, s)
-+#define print_str(k, v) avtext_print_string(w, k, v, 0)
++#define print_int(k, v) avtext_print_integer(tfc, k, v)
++#define print_q(k, v, s) avtext_print_rational(tfc, k, v, s)
++#define print_str(k, v) avtext_print_string(tfc, k, v, 0)
+
-+static void print_hwdevicecontext(AVTextFormatContext *w, const AVHWDeviceContext *hw_device_context)
++static void print_hwdevicecontext(AVTextFormatContext *tfc, const AVHWDeviceContext *hw_device_context)
+{
-+ avtext_print_section_header(w, NULL, SECTION_ID_HWDEViCECONTEXT);
-+
-+ print_int("HasHwDeviceContext", 1);
-+ print_str("DeviceType", av_hwdevice_get_type_name(hw_device_context->type));
-+
-+ avtext_print_section_footer(w); // SECTION_ID_HWDEViCECONTEXT
++ print_int("has_hw_device_context", 1);
++ print_str("hw_device_type", av_hwdevice_get_type_name(hw_device_context->type));
+}
+
-+static void print_hwframescontext(AVTextFormatContext *w, const AVHWFramesContext *hw_frames_context)
++static void print_hwframescontext(AVTextFormatContext *tfc, const AVHWFramesContext *hw_frames_context)
+{
-+ const AVPixFmtDescriptor* pixdescHw;
-+ const AVPixFmtDescriptor* pixdescSw;
++ const AVPixFmtDescriptor* pix_desc_hw;
++ const AVPixFmtDescriptor* pix_desc_sw;
+
-+ avtext_print_section_header(w, NULL, SECTION_ID_HWFRAMESCONTEXT);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_HWFRAMESCONTEXT);
+
-+ print_int("HasHwFramesContext", 1);
++ print_int("has_hw_frames_context", 1);
++ print_str("hw_device_type", av_hwdevice_get_type_name(hw_frames_context->device_ctx->type));
+
-+ pixdescHw = av_pix_fmt_desc_get(hw_frames_context->format);
-+ if (pixdescHw) {
-+ print_str("HwPixelFormat", pixdescHw->name);
-+ print_str("HwPixelFormatAlias", pixdescHw->alias);
++ pix_desc_hw = av_pix_fmt_desc_get(hw_frames_context->format);
++ if (pix_desc_hw) {
++ print_str("hw_pixel_format", pix_desc_hw->name);
++ if (pix_desc_hw->alias)
++ print_str("hw_pixel_format_alias", pix_desc_hw->alias);
+ }
+
-+ pixdescSw = av_pix_fmt_desc_get(hw_frames_context->sw_format);
-+ if (pixdescSw) {
-+ print_str("SwPixelFormat", pixdescSw->name);
-+ print_str("SwPixelFormatAlias", pixdescSw->alias);
++ pix_desc_sw = av_pix_fmt_desc_get(hw_frames_context->sw_format);
++ if (pix_desc_sw) {
++ print_str("sw_pixel_format", pix_desc_sw->name);
++ if (pix_desc_sw->alias)
++ print_str("sw_pixel_format_alias", pix_desc_sw->alias);
+ }
+
-+ print_int("Width", hw_frames_context->width);
-+ print_int("Height", hw_frames_context->height);
-+
-+ print_hwdevicecontext(w, hw_frames_context->device_ctx);
++ print_int("width", hw_frames_context->width);
++ print_int("height", hw_frames_context->height);
++ print_int("initial_pool_size", hw_frames_context->initial_pool_size);
+
-+ avtext_print_section_footer(w); // SECTION_ID_HWFRAMESCONTEXT
++ avtext_print_section_footer(tfc); // SECTION_ID_HWFRAMESCONTEXT
+}
+
-+static void print_link(AVTextFormatContext *w, AVFilterLink *link)
++static void print_link(AVTextFormatContext *tfc, AVFilterLink *link)
+{
+ AVBufferRef *hw_frames_ctx;
-+ char layoutString[64];
++ char layout_string[64];
++
++ print_str("media_type", av_get_media_type_string(link->type));
+
+ switch (link->type) {
+ case AVMEDIA_TYPE_VIDEO:
-+ print_str("Format", av_x_if_null(av_get_pix_fmt_name(link->format), "?"));
-+ print_int("Width", link->w);
-+ print_int("Height", link->h);
-+ print_q("SAR", link->sample_aspect_ratio, ':');
-+ print_q("TimeBase", link->time_base, '/');
++ print_str("format", av_x_if_null(av_get_pix_fmt_name(link->format), "?"));
++ print_int("width", link->w);
++ print_int("height", link->h);
++ print_q("sar", link->sample_aspect_ratio, ':');
++ print_str("color_range", av_color_range_name(link->color_range));
++ print_str("color_space", av_color_space_name(link->colorspace));
+ break;
+
-+ ////case AVMEDIA_TYPE_SUBTITLE:
-+ //// print_str("Format", av_x_if_null(av_get_subtitle_fmt_name(link->format), "?"));
-+ //// print_int("Width", link->w);
-+ //// print_int("Height", link->h);
-+ //// print_q("TimeBase", link->time_base, '/');
-+ //// break;
++ case AVMEDIA_TYPE_SUBTITLE:
++ ////print_str("format", av_x_if_null(av_get_subtitle_fmt_name(link->format), "?"));
++ print_int("width", link->w);
++ print_int("height", link->h);
++ break;
+
+ case AVMEDIA_TYPE_AUDIO:
-+ av_channel_layout_describe(&link->ch_layout, layoutString, sizeof(layoutString));
-+ print_str("ChannelString", layoutString);
-+ print_int("Channels", link->ch_layout.nb_channels);
-+ ////print_int("ChannelLayout", link->ch_layout);
-+ print_int("SampleRate", link->sample_rate);
++ av_channel_layout_describe(&link->ch_layout, layout_string, sizeof(layout_string));
++ print_str("channel_layout", layout_string);
++ print_int("channels", link->ch_layout.nb_channels);
++ print_int("sample_rate", link->sample_rate);
+ break;
+ }
+
++ print_q("time_base", link->time_base, '/');
++
+ hw_frames_ctx = avfilter_link_get_hw_frames_ctx(link);
+
-+ if (hw_frames_ctx && hw_frames_ctx->buffer) {
-+ print_hwframescontext(w, (AVHWFramesContext *)hw_frames_ctx->data);
-+ }
++ if (hw_frames_ctx && hw_frames_ctx->data)
++ print_hwframescontext(tfc, (AVHWFramesContext *)hw_frames_ctx->data);
+}
+
-+static void print_filter(AVTextFormatContext *w, const AVFilterContext* filter)
++static void print_filter(AVTextFormatContext *tfc, const AVFilterContext* filter)
+{
-+ avtext_print_section_header(w, NULL, SECTION_ID_FILTER);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_FILTER);
+
-+ print_str("Name", filter->name);
++ print_str("filter_id", filter->name);
+
+ if (filter->filter) {
-+ print_str("Name2", filter->filter->name);
-+ print_str("Description", filter->filter->description);
++ print_str("filter_name", filter->filter->name);
++ print_str("description", filter->filter->description);
+ }
+
+ if (filter->hw_device_ctx) {
-+ AVHWDeviceContext* decCtx = (AVHWDeviceContext*)filter->hw_device_ctx->data;
-+ print_hwdevicecontext(w, decCtx);
++ AVHWDeviceContext* device_context = (AVHWDeviceContext*)filter->hw_device_ctx->data;
++ print_hwdevicecontext(tfc, device_context);
++ if (filter->extra_hw_frames > 0)
++ print_int("extra_hw_frames", filter->extra_hw_frames);
+ }
+
-+ avtext_print_section_header(w, NULL, SECTION_ID_INPUTS);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_INPUTS);
+
+ for (unsigned i = 0; i < filter->nb_inputs; i++) {
+ AVFilterLink *link = filter->inputs[i];
-+ avtext_print_section_header(w, NULL, SECTION_ID_INPUT);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_INPUT);
+
-+ print_str("SourceName", link->src->name);
-+ print_str("SourcePadName", avfilter_pad_get_name(link->srcpad, 0));
-+ print_str("DestPadName", avfilter_pad_get_name(link->dstpad, 0));
++ print_int("input_index", i);
++ print_str("pad_name", avfilter_pad_get_name(link->dstpad, 0));;
++ print_str("source_filter_id", link->src->name);
++ print_str("source_pad_name", avfilter_pad_get_name(link->srcpad, 0));
+
-+ print_link(w, link);
++ print_link(tfc, link);
+
-+ avtext_print_section_footer(w); // SECTION_ID_INPUT
++ avtext_print_section_footer(tfc); // SECTION_ID_INPUT
+ }
+
-+ avtext_print_section_footer(w); // SECTION_ID_INPUTS
++ avtext_print_section_footer(tfc); // SECTION_ID_INPUTS
+
-+ avtext_print_section_header(w, NULL, SECTION_ID_OUTPUTS);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_OUTPUTS);
+
+ for (unsigned i = 0; i < filter->nb_outputs; i++) {
+ AVFilterLink *link = filter->outputs[i];
-+ avtext_print_section_header(w, NULL, SECTION_ID_OUTPUT);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_OUTPUT);
+
-+ print_str("DestName", link->dst->name);
-+ print_str("DestPadName", avfilter_pad_get_name(link->dstpad, 0));
-+ print_str("SourceName", link->src->name);
++ print_int("output_index", i);
++ print_str("pad_name", avfilter_pad_get_name(link->srcpad, 0));
++ print_str("dest_filter_id", link->dst->name);
++ print_str("dest_pad_name", avfilter_pad_get_name(link->dstpad, 0));
+
-+ print_link(w, link);
++ print_link(tfc, link);
+
-+ avtext_print_section_footer(w); // SECTION_ID_OUTPUT
++ avtext_print_section_footer(tfc); // SECTION_ID_OUTPUT
+ }
+
-+ avtext_print_section_footer(w); // SECTION_ID_OUTPUTS
++ avtext_print_section_footer(tfc); // SECTION_ID_OUTPUTS
+
-+ avtext_print_section_footer(w); // SECTION_ID_FILTER
++ avtext_print_section_footer(tfc); // SECTION_ID_FILTER
+}
+
+static void init_sections(void)
@@ fftools/ffmpeg_graphprint.c (new)
+ sections[i].show_all_entries = 1;
+}
+
-+static void print_filtergraph_single(AVTextFormatContext *w, FilterGraph* fg, AVFilterGraph *graph)
++static void print_filtergraph_single(AVTextFormatContext *tfc, FilterGraph *fg, AVFilterGraph *graph)
+{
-+ char layoutString[64];
+ FilterGraphPriv *fgp = fgp_from_fg(fg);
+
-+ print_int("GraphIndex", fg->index);
-+ print_str("Description", fgp->graph_desc);
++ print_int("graph_index", fg->index);
++ print_str("description", fgp->graph_desc);
+
-+ avtext_print_section_header(w, NULL, SECTION_ID_INPUTS);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_INPUTS);
+
+ for (int i = 0; i < fg->nb_inputs; i++) {
+ InputFilterPriv* ifilter = ifp_from_ifilter(fg->inputs[i]);
-+ enum AVMediaType mediaType = ifilter->type;
-+
-+ avtext_print_section_header(w, NULL, SECTION_ID_INPUT);
-+
-+ print_str("Name1", (char*)ifilter->ifilter.name);
++ enum AVMediaType media_type = ifilter->type;
+
-+ if (ifilter->filter) {
-+ print_str("Name2", ifilter->filter->name);
-+ print_str("Name3", ifilter->filter->filter->name);
-+ print_str("Description", ifilter->filter->filter->description);
-+ }
++ avtext_print_section_header(tfc, NULL, SECTION_ID_INPUT);
+
-+ print_str("MediaType", av_get_media_type_string(mediaType));
-+ print_int("MediaTypeId", mediaType);
++ print_int("input_index", ifilter->index);
+
-+ switch (ifilter->type) {
-+ case AVMEDIA_TYPE_VIDEO:
-+ case AVMEDIA_TYPE_SUBTITLE:
-+ print_str("Format", av_x_if_null(av_get_pix_fmt_name(ifilter->format), "?"));
-+ print_int("Width", ifilter->width);
-+ print_int("Height", ifilter->height);
-+ print_q("SAR", ifilter->sample_aspect_ratio, ':');
-+ break;
-+ case AVMEDIA_TYPE_AUDIO:
++ if (ifilter->linklabel)
++ print_str("link_label", (const char*)ifilter->linklabel);
+
-+ av_channel_layout_describe(&ifilter->ch_layout, layoutString, sizeof(layoutString));
-+ print_str("ChannelString", layoutString);
-+ print_int("SampleRate", ifilter->sample_rate);
-+ break;
-+ case AVMEDIA_TYPE_ATTACHMENT:
-+ case AVMEDIA_TYPE_DATA:
-+ break;
++ if (ifilter->filter) {
++ print_str("filter_id", ifilter->filter->name);
++ print_str("filter_name", ifilter->filter->filter->name);
+ }
+
-+ if (ifilter->hw_frames_ctx)
-+ print_hwframescontext(w, (AVHWFramesContext*)ifilter->hw_frames_ctx->data);
-+ else if (ifilter->filter && ifilter->filter->hw_device_ctx) {
-+ AVHWDeviceContext* devCtx = (AVHWDeviceContext*)ifilter->filter->hw_device_ctx->data;
-+ print_hwdevicecontext(w, devCtx);
-+ }
++ print_str("media_type", av_get_media_type_string(media_type));
+
-+ avtext_print_section_footer(w); // SECTION_ID_INPUT
++ avtext_print_section_footer(tfc); // SECTION_ID_INPUT
+ }
+
-+ avtext_print_section_footer(w); // SECTION_ID_INPUTS
-+
++ avtext_print_section_footer(tfc); // SECTION_ID_INPUTS
+
-+ avtext_print_section_header(w, NULL, SECTION_ID_OUTPUTS);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_OUTPUTS);
+
+ for (int i = 0; i < fg->nb_outputs; i++) {
+ OutputFilterPriv *ofilter = ofp_from_ofilter(fg->outputs[i]);
-+ enum AVMediaType mediaType = AVMEDIA_TYPE_UNKNOWN;
+
-+ avtext_print_section_header(w, NULL, SECTION_ID_OUTPUT);
-+ print_str("Name1", ofilter->name);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_OUTPUT);
+
-+ if (ofilter->filter) {
-+ print_str("Name2", ofilter->filter->name);
-+ print_str("Name3", ofilter->filter->filter->name);
-+ print_str("Description", ofilter->filter->filter->description);
++ print_int("output_index", ofilter->index);
+
-+ if (ofilter->filter->nb_inputs > 0)
-+ mediaType = ofilter->filter->inputs[0]->type;
-+ }
++ print_str("name", ofilter->name);
+
-+ print_str("MediaType", av_get_media_type_string(mediaType));
-+ print_int("MediaTypeId", mediaType);
++ if (fg->outputs[i]->linklabel)
++ print_str("link_label", (const char*)fg->outputs[i]->linklabel);
+
-+ switch (ofilter->ofilter.type) {
-+ case AVMEDIA_TYPE_VIDEO:
-+ case AVMEDIA_TYPE_SUBTITLE:
-+ print_str("Format", av_x_if_null(av_get_pix_fmt_name(ofilter->format), "?"));
-+ print_int("Width", ofilter->width);
-+ print_int("Height", ofilter->height);
-+ break;
-+ case AVMEDIA_TYPE_AUDIO:
-+
-+ av_channel_layout_describe(&ofilter->ch_layout, layoutString, sizeof(layoutString));
-+ print_str("ChannelString", layoutString);
-+ print_int("SampleRate", ofilter->sample_rate);
-+ break;
-+ case AVMEDIA_TYPE_ATTACHMENT:
-+ case AVMEDIA_TYPE_DATA:
-+ break;
++ if (ofilter->filter) {
++ print_str("filter_id", ofilter->filter->name);
++ print_str("filter_name", ofilter->filter->filter->name);
+ }
+
-+ if (ofilter->filter && ofilter->filter->hw_device_ctx) {
-+ AVHWDeviceContext* devCtx = (AVHWDeviceContext*)ofilter->filter->hw_device_ctx->data;
-+ print_hwdevicecontext(w, devCtx);
-+ }
++ print_str("media_type", av_get_media_type_string(fg->outputs[i]->type));
+
-+ avtext_print_section_footer(w); // SECTION_ID_OUTPUT
++ avtext_print_section_footer(tfc); // SECTION_ID_OUTPUT
+ }
+
-+ avtext_print_section_footer(w); // SECTION_ID_OUTPUTS
-+
++ avtext_print_section_footer(tfc); // SECTION_ID_OUTPUTS
+
-+ avtext_print_section_header(w, NULL, SECTION_ID_FILTERS);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_FILTERS);
+
+ if (graph) {
+ for (unsigned i = 0; i < graph->nb_filters; i++) {
+ AVFilterContext *filter = graph->filters[i];
-+ avtext_print_section_header(w, NULL, SECTION_ID_FILTER);
++ avtext_print_section_header(tfc, NULL, SECTION_ID_FILTER);
+
-+ print_filter(w, filter);
++ print_filter(tfc, filter);
+
-+ avtext_print_section_footer(w); // SECTION_ID_FILTER
++ avtext_print_section_footer(tfc); // SECTION_ID_FILTER
+ }
+ }
+
-+ avtext_print_section_footer(w); // SECTION_ID_FILTERS
++ avtext_print_section_footer(tfc); // SECTION_ID_FILTERS
+}
+
+int print_filtergraph(FilterGraph *fg, AVFilterGraph *graph)
@@ fftools/ffmpeg_graphprint.c (new)
+ }
+
+ text_formatter = avtext_get_formatter_by_name(w_name);
-+ if (text_formatter == NULL) {
-+ av_log(NULL, AV_LOG_ERROR, "Unknown filter graph output format with name '%s'\n", w_name);
++ if (!text_formatter ) {
++ av_log(NULL, AV_LOG_ERROR, "Unknown filter graph output format with name '%s'\n", w_name);
+ return AVERROR(EINVAL);
+ }
+
@@ fftools/ffmpeg_graphprint.c (new)
+ }
+
+ if ((ret = avtext_context_open(&tctx, text_formatter, wctx, w_args, sections, FF_ARRAY_ELEMS(sections), 0, 0, 0, 0, -1, NULL)) >= 0) {
++
++ // Due to the threading model each graph needs to print itself into a buffer
++ // from its own thread. The actual printing happens short before cleanup in ffmpeg.c
++ // where all grahps are assembled together. To make this work, we need to put the
++ // formatting context into the same state like it would be when printing all at once,
++ // so here we print the section headers and clear the buffer to get into the right state.
+ avtext_print_section_header(tctx, NULL, SECTION_ID_ROOT);
+ avtext_print_section_header(tctx, NULL, SECTION_ID_FILTERGRAPHS);
+ avtext_print_section_header(tctx, NULL, SECTION_ID_FILTERGRAPH);
@@ fftools/ffmpeg_graphprint.c (new)
+ w_args = buf;
+
+ text_formatter = avtext_get_formatter_by_name(w_name);
-+ if (text_formatter == NULL) {
-+ av_log(NULL, AV_LOG_ERROR, "Unknown filter graph output format with name '%s'\n", w_name);
++ if (!text_formatter) {
++ av_log(NULL, AV_LOG_ERROR, "Unknown filter graph output format with name '%s'\n", w_name);
+ return AVERROR(EINVAL);
+ }
+
@@ fftools/ffmpeg_graphprint.c (new)
+ ret = avtextwriter_create_buffer(&wctx, &target_buf);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "avtextwriter_create_buffer failed. Error code %d\n", ret);
-+ return AVERROR(EINVAL);
++ return ret;
+ }
+
+ if ((ret = avtext_context_open(&tctx, text_formatter, wctx, w_args, sections, FF_ARRAY_ELEMS(sections), 0, 0, 0, 0, -1, NULL)) >= 0) {
@@ fftools/ffmpeg_graphprint.c (new)
+ if (print_graphs_file) {
+ AVIOContext *avio = NULL;
+
-+ ret = avio_open2(&avio, print_graphs_file, AVIO_FLAG_WRITE, NULL, NULL);
-+ if (ret < 0) {
-+ av_log(NULL, AV_LOG_ERROR, "Failed to open graph output file, \"%s\": %s\n",
-+ print_graphs_file, av_err2str(ret));
-+ return ret;
-+ }
++ if (!strcmp(print_graphs_file, "-")) {
++ printf("%s", target_buf.str);
++ } else {
++ ret = avio_open2(&avio, print_graphs_file, AVIO_FLAG_WRITE, NULL, NULL);
++ if (ret < 0) {
++ av_log(NULL, AV_LOG_ERROR, "Failed to open graph output file, \"%s\": %s\n",
++ print_graphs_file, av_err2str(ret));
++ return ret;
++ }
+
-+ avio_write(avio, (const unsigned char*)target_buf.str, FFMIN(target_buf.len, target_buf.size - 1));
-+ avio_flush(avio);
++ avio_write(avio, (const unsigned char*)target_buf.str, FFMIN(target_buf.len, target_buf.size - 1));
++ avio_flush(avio);
+
-+ if ((ret = avio_closep(&avio)) < 0)
-+ av_log(NULL, AV_LOG_ERROR, "Error closing graph output file, loss of information possible: %s\n", av_err2str(ret));
++ if ((ret = avio_closep(&avio)) < 0)
++ av_log(NULL, AV_LOG_ERROR, "Error closing graph output file, loss of information possible: %s\n", av_err2str(ret));
++ }
+ }
+
-+ if (print_graphs) {
-+ printf("%s", target_buf.str);
++ if (print_graphs)
+ av_log(NULL, AV_LOG_INFO, "%s %c", target_buf.str, '\n');
-+ }
+
+ avtext_context_close(&tctx);
+ avtextwriter_context_close(&wctx);
@@ fftools/ffmpeg_opt.c: float max_error_rate = 2.0/3;
int filter_complex_nbthreads = 0;
int vstats_version = 2;
+int print_graphs = 0;
-+char* print_graphs_file = NULL;
-+char* print_graphs_format = NULL;
++char *print_graphs_file = NULL;
++char *print_graphs_format = NULL;
int auto_conversion_filters = 1;
int64_t stats_period = 500000;
@@ fftools/ffmpeg_opt.c: const OptionDef options[] = {
#endif
+ { "print_graphs", OPT_TYPE_BOOL, 0,
+ { &print_graphs },
-+ "prints filtergraph details to stderr" },
++ "print filtergraph details to stderr" },
+ { "print_graphs_file", OPT_TYPE_STRING, 0,
+ { &print_graphs_file },
-+ "writes graph details to a file", "filename" },
++ "write graph details to a file", "filename" },
+ { "print_graphs_format", OPT_TYPE_STRING, 0,
+ { &print_graphs_format },
+ "set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)", "format" },
{ "auto_conversion_filters", OPT_TYPE_BOOL, OPT_EXPERT,
{ &auto_conversion_filters },
"enable automatic conversion filters globally" },
+
+ ## fftools/textformat/avtextformat.c ##
+@@ fftools/textformat/avtextformat.c: static char *value_string(AVTextFormatContext *tctx, char *buf, int buf_size, st
+ vali = vald;
+ }
+
+- if (show_float || (tctx->use_value_prefix && vald != (int64_t)vald))
++ if (show_float || (tctx->use_value_prefix && vald != (int64_t)vald)) {
+ snprintf(buf, buf_size, "%f", vald);
+- else
++ } else {
+ snprintf(buf, buf_size, "%"PRId64, vali);
++ }
++
+ av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || tctx->show_value_unit ? " " : "",
+ prefix_string, tctx->show_value_unit ? uv.unit : "");
+ }
+
+ ## fftools/textformat/avtextformat.h ##
+@@ fftools/textformat/avtextformat.h: typedef struct AVTextFormatter {
+ #define SECTION_MAX_NB_SECTIONS 100
+
+ struct AVTextFormatContext {
+- const AVClass *class; ///< class of the formatter
+- const AVTextFormatter *formatter; ///< the AVTextFormatter of which this is an instance
+- AVTextWriterContext *writer; ///< the AVTextWriterContext
++ const AVClass *class; ///< class of the formatter
++ const AVTextFormatter *formatter; ///< the AVTextFormatter of which this is an instance
++ AVTextWriterContext *writer; ///< the AVTextWriterContext
+
+- char *name; ///< name of this formatter instance
+- void *priv; ///< private data for use by the filter
++ char *name; ///< name of this formatter instance
++ void *priv; ///< private data for use by the filter
+
+ const struct AVTextFormatSection *sections; ///< array containing all sections
+- int nb_sections; ///< number of sections
++ int nb_sections; ///< number of sections
+
+- int level; ///< current level, starting from 0
++ int level; ///< current level, starting from 0
+
+ /** number of the item printed in the given section, starting from 0 */
+ unsigned int nb_item[SECTION_MAX_NB_LEVELS];
+@@ fftools/textformat/avtextformat.h: void avtext_print_data(AVTextFormatContext *tctx, const char *name, const uint8_
+
+ void avtext_print_data_hash(AVTextFormatContext *tctx, const char *name, const uint8_t *data, int size);
+
+-void avtext_print_integers(AVTextFormatContext *tctx, const char *name, uint8_t *data, int size,
++void avtext_print_integers(AVTextFormatContext *tctx, const char *name, uint8_t *data, int size,
+ const char *format, int columns, int bytes, int offset_add);
+
+ const AVTextFormatter *avtext_get_formatter_by_name(const char *name);
7: 03663768dd < -: ---------- fftools: Enable filtergraph printing and update docs
8: 0caab91adc = 7: fcfcc5f7df fftools/ffprobe: Rename AVTextFormatContext variables (w => tfc)
--
ffmpeg-codebot
More information about the ffmpeg-devel
mailing list