Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: ffmpegagent <ffmpegagent@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Soft Works <softworkz-at-hotmail.com@ffmpeg.org>,
	softworkz <softworkz@hotmail.com>,
	Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH v2 0/4] print_graphs: Complete Filtergraph Printing
Date: Fri, 21 Feb 2025 11:27:08 +0000
Message-ID: <pull.52.v2.ffstaging.FFmpeg.1740137232.ffmpegagent@gmail.com> (raw)
In-Reply-To: <pull.52.ffstaging.FFmpeg.1739959172.ffmpegagent@gmail.com>

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
_______________________________________________
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".

  parent reply	other threads:[~2025-02-21 11:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-19  9:59 [FFmpeg-devel] [PATCH 0/3] " ffmpegagent
2025-02-19  9:59 ` [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg_filter: Move some declaration to new header file softworkz
2025-02-19  9:59 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg_graphprint: Add options for filtergraph printing softworkz
2025-02-21  9:22   ` Andreas Rheinhardt
2025-02-21  9:42     ` Soft Works
2025-02-21 11:11       ` Andreas Rheinhardt
2025-02-21 11:25         ` Soft Works
2025-02-21 13:09   ` Nicolas George
2025-02-21 13:49     ` Soft Works
2025-02-19  9:59 ` [FFmpeg-devel] [PATCH 3/3] fftools: Enable filtergraph printing and update docs softworkz
2025-02-21 11:27 ` ffmpegagent [this message]
2025-02-21 11:27   ` [FFmpeg-devel] [PATCH v2 1/4] fftools/ffmpeg_filter: Move some declaration to new header file softworkz
2025-02-21 11:27   ` [FFmpeg-devel] [PATCH v2 2/4] avfilter/avfilter Add avfilter_link_get_hw_frames_ctx() softworkz
2025-02-21 11:27   ` [FFmpeg-devel] [PATCH v2 3/4] fftools/ffmpeg_graphprint: Add options for filtergraph printing softworkz
2025-02-21 11:27   ` [FFmpeg-devel] [PATCH v2 4/4] fftools: Enable filtergraph printing and update docs softworkz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.52.v2.ffstaging.FFmpeg.1740137232.ffmpegagent@gmail.com \
    --to=ffmpegagent@gmail.com \
    --cc=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=softworkz-at-hotmail.com@ffmpeg.org \
    --cc=softworkz@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git