[FFmpeg-devel] [PATCH v2 0/4] print_graphs: Complete Filtergraph Printing
ffmpegagent
ffmpegagent at gmail.com
Fri Feb 21 13:27:08 EET 2025
The key benefits are:
* Different to other graph printing methods, this is outputting:
* 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
* Use the same output implementation as ffprobe, supporting multiple
formats
(this commit includes only the default and JSON writers)
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)
softworkz (4):
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
doc/APIchanges | 3 +
doc/ffmpeg.texi | 10 +
fftools/Makefile | 1 +
fftools/ffmpeg.c | 4 +
fftools/ffmpeg.h | 3 +
fftools/ffmpeg_filter.c | 193 +-----
fftools/ffmpeg_filter.h | 232 +++++++
fftools/ffmpeg_graphprint.c | 1141 +++++++++++++++++++++++++++++++++++
fftools/ffmpeg_graphprint.h | 224 +++++++
fftools/ffmpeg_opt.c | 12 +
libavfilter/avfilter.c | 9 +
libavfilter/avfilter.h | 12 +
libavfilter/version.h | 2 +-
13 files changed, 1658 insertions(+), 188 deletions(-)
create mode 100644 fftools/ffmpeg_filter.h
create mode 100644 fftools/ffmpeg_graphprint.c
create mode 100644 fftools/ffmpeg_graphprint.h
base-commit: e18f87ed9f9f61c980420b315dc8ecb308831bc5
Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-52%2Fsoftworkz%2Fsubmit_print_graphs5-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-52/softworkz/submit_print_graphs5-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/52
Range-diff vs v1:
1: c843eb0741 = 1: c843eb0741 fftools/ffmpeg_filter: Move some declaration to new header file
-: ---------- > 2: 5a7b45ab09 avfilter/avfilter Add avfilter_link_get_hw_frames_ctx()
2: 0750b971f9 ! 3: 1f87cfae77 fftools/ffmpeg_graphprint: Add options for filtergraph printing
@@ fftools/ffmpeg_graphprint.c (new)
+#include "libavutil/intreadwrite.h"
+#include "libavutil/common.h"
+#include "libavfilter/avfilter.h"
-+#include "libavfilter/filters.h"
+#include "libavutil/buffer.h"
+#include "libavutil/hwcontext.h"
+
@@ fftools/ffmpeg_graphprint.c (new)
+ .priv_class = &json_class,
+};
+
-+static void print_hwdevicecontext(WriterContext *w, AVHWDeviceContext *hw_device_context)
++static void print_hwdevicecontext(WriterContext *w, const AVHWDeviceContext *hw_device_context)
+{
+ writer_print_section_header(w, SECTION_ID_HWDEViCECONTEXT);
+
@@ fftools/ffmpeg_graphprint.c (new)
+ writer_print_section_footer(w); // SECTION_ID_HWDEViCECONTEXT
+}
+
-+static void print_hwframescontext(WriterContext *w, AVHWFramesContext *hw_frames_context)
++static void print_hwframescontext(WriterContext *w, const AVHWFramesContext *hw_frames_context)
+{
+ const AVPixFmtDescriptor* pixdescHw;
+ const AVPixFmtDescriptor* pixdescSw;
@@ fftools/ffmpeg_graphprint.c (new)
+ print_int("HasHwFramesContext", 1);
+
+ pixdescHw = av_pix_fmt_desc_get(hw_frames_context->format);
-+ if (pixdescHw != NULL) {
++ if (pixdescHw) {
+ print_str("HwPixelFormat", pixdescHw->name);
+ print_str("HwPixelFormatAlias", pixdescHw->alias);
+ }
+
+ pixdescSw = av_pix_fmt_desc_get(hw_frames_context->sw_format);
-+ if (pixdescSw != NULL) {
++ if (pixdescSw) {
+ print_str("SwPixelFormat", pixdescSw->name);
+ print_str("SwPixelFormatAlias", pixdescSw->alias);
+ }
@@ fftools/ffmpeg_graphprint.c (new)
+ break;
+ }
+
-+ FilterLink* plink = ff_filter_link(link);
++ AVBufferRef *hw_frames_ctx = avfilter_link_get_hw_frames_ctx(link);
+
-+ if (plink->hw_frames_ctx != NULL && plink->hw_frames_ctx->buffer != NULL)
-+ print_hwframescontext(w, (AVHWFramesContext*)plink->hw_frames_ctx->data);
++ if (hw_frames_ctx && hw_frames_ctx->buffer) {
++ print_hwframescontext(w, (AVHWFramesContext *)hw_frames_ctx->data);
++ }
+}
+
-+static void print_filter(WriterContext *w, AVFilterContext* filter)
++static void print_filter(WriterContext *w, const AVFilterContext* filter)
+{
+ writer_print_section_header(w, SECTION_ID_FILTER);
+
+ print_str("Name", filter->name);
+
-+ if (filter->filter != NULL) {
++ if (filter->filter) {
+ print_str("Name2", filter->filter->name);
+ print_str("Description", filter->filter->description);
+ }
+
-+ if (filter->hw_device_ctx != NULL) {
++ if (filter->hw_device_ctx) {
+ AVHWDeviceContext* decCtx = (AVHWDeviceContext*)filter->hw_device_ctx->data;
+ print_hwdevicecontext(w, decCtx);
+ }
@@ fftools/ffmpeg_graphprint.c (new)
+ writer_print_section_header(w, SECTION_ID_INPUT);
+
+ print_str("SourceName", link->src->name);
-+ print_str("SourcePadName", link->srcpad->name);
-+ print_str("DestPadName", link->dstpad->name);
++ print_str("SourcePadName", avfilter_pad_get_name(link->srcpad, 0));
++ print_str("DestPadName", avfilter_pad_get_name(link->dstpad, 0));
+
+ print_link(w, link);
+
@@ fftools/ffmpeg_graphprint.c (new)
+ writer_print_section_header(w, SECTION_ID_OUTPUT);
+
+ print_str("DestName", link->dst->name);
-+ print_str("DestPadName", link->dstpad->name);
++ print_str("DestPadName", avfilter_pad_get_name(link->dstpad, 0));
+ print_str("SourceName", link->src->name);
+
+ print_link(w, link);
@@ fftools/ffmpeg_graphprint.c (new)
+ writer_print_section_footer(w); // SECTION_ID_FILTER
+}
+
-+static void print_filtergraph_single(WriterContext *w, FilterGraph* fg)
++static void print_filtergraph_single(WriterContext *w, FilterGraph* fg, AVFilterGraph *graph)
+{
+ char layoutString[64];
+ FilterGraphPriv *fgp = fgp_from_fg(fg);
-+ AVFilterGraph* graph = NULL;
+
+ print_int("GraphIndex", fg->index);
+ print_str("Description", fgp->graph_desc);
@@ fftools/ffmpeg_graphprint.c (new)
+
+ print_str("Name1", (char*)ifilter->ifilter.name);
+
-+ if (ifilter->filter != NULL) {
++ if (ifilter->filter) {
+ print_str("Name2", ifilter->filter->name);
+ print_str("Name3", ifilter->filter->filter->name);
+ print_str("Description", ifilter->filter->filter->description);
@@ fftools/ffmpeg_graphprint.c (new)
+ break;
+ }
+
-+ if (ifilter->hw_frames_ctx != NULL)
++ if (ifilter->hw_frames_ctx)
+ print_hwframescontext(w, (AVHWFramesContext*)ifilter->hw_frames_ctx->data);
-+ else if (ifilter->filter != NULL && ifilter->filter->hw_device_ctx != NULL) {
++ else if (ifilter->filter && ifilter->filter->hw_device_ctx) {
+ AVHWDeviceContext* devCtx = (AVHWDeviceContext*)ifilter->filter->hw_device_ctx->data;
+ print_hwdevicecontext(w, devCtx);
+ }
+
+ writer_print_section_footer(w); // SECTION_ID_INPUT
-+
-+ if (!graph && ifilter->filter != NULL && ifilter->filter->nb_outputs > 0) {
-+ FilterLink* link = ff_filter_link(ifilter->filter->outputs[0]);
-+ graph = link->graph;
-+ }
+ }
+
+ writer_print_section_footer(w); // SECTION_ID_INPUTS
@@ fftools/ffmpeg_graphprint.c (new)
+ writer_print_section_header(w, SECTION_ID_OUTPUT);
+ print_str("Name1", ofilter->name);
+
-+ if (ofilter->filter != NULL) {
++ if (ofilter->filter) {
+ print_str("Name2", ofilter->filter->name);
+ print_str("Name3", ofilter->filter->filter->name);
+ print_str("Description", ofilter->filter->filter->description);
@@ fftools/ffmpeg_graphprint.c (new)
+ break;
+ }
+
-+ if (ofilter->filter != NULL && ofilter->filter->hw_device_ctx != NULL) {
++ if (ofilter->filter && ofilter->filter->hw_device_ctx) {
+ AVHWDeviceContext* devCtx = (AVHWDeviceContext*)ofilter->filter->hw_device_ctx->data;
+ print_hwdevicecontext(w, devCtx);
+ }
+
+ writer_print_section_footer(w); // SECTION_ID_OUTPUT
-+
-+ if (!graph && ofilter->filter != NULL && ofilter->filter->nb_inputs > 0) {
-+ FilterLink* link = ff_filter_link(ofilter->filter->inputs[0]);
-+ graph = link->graph;
-+ }
+ }
+
+ writer_print_section_footer(w); // SECTION_ID_OUTPUTS
@@ fftools/ffmpeg_graphprint.c (new)
+
+ writer_print_section_header(w, SECTION_ID_FILTERS);
+
-+ if (graph != NULL) {
++ if (graph) {
+ for (unsigned i = 0; i < graph->nb_filters; i++) {
+ AVFilterContext *filter = graph->filters[i];
+ writer_print_section_header(w, SECTION_ID_FILTER);
@@ fftools/ffmpeg_graphprint.c (new)
+
+ av_bprint_clear(&w->bpBuf);
+
-+ print_filtergraph_single(w, fg);
++ print_filtergraph_single(w, fg, graph);
+
+ av_bprint_finalize(&w->bpBuf, &targetBuf->str);
+ targetBuf->len = w->bpBuf.len;
3: 7eea20993c = 4: 1bf975fa0e fftools: Enable filtergraph printing and update docs
--
ffmpeg-codebot
More information about the ffmpeg-devel
mailing list