Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH v2 1/4] avfilter/graphdump: implement options parsing
Date: Tue, 18 Feb 2025 13:46:00 +0100
Message-ID: <20250218124603.95398-1-ffmpeg@haasn.xyz> (raw)

From: Niklas Haas <git@haasn.dev>

And use it to make the output format configurable.

I also added a "none" option to explicitly disable the behavior (in case a
previous command line argument was used to enable it). This has the added
benefit of giving the default "pretty" format the ID 1, allowing `-dumpgraph 1`
to continue working as expected.
---
 libavfilter/graphdump.c | 54 +++++++++++++++++++++++++++++++++++------
 1 file changed, 47 insertions(+), 7 deletions(-)

diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c
index 1bb59e4301..80cbda50f5 100644
--- a/libavfilter/graphdump.c
+++ b/libavfilter/graphdump.c
@@ -24,10 +24,33 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/bprint.h"
 #include "libavutil/mem.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "filters.h"
 
+enum {
+    FMT_NONE = 0,
+    FMT_PRETTY,
+    FMT_NB,
+};
+
+typedef struct GraphDumpOptions {
+    const AVClass *class;
+
+    int format;
+} GraphDumpOptions;
+
+#define OFFSET(x) offsetof(GraphDumpOptions, x)
+static const AVOption graph_dump_options[] = {
+    { "format",     "set the output format", OFFSET(format), AV_OPT_TYPE_INT, { .i64 = FMT_NONE }, 0, FMT_NB - 1, .unit = "format" },
+    {     "none",   "don't produce any output",         0, AV_OPT_TYPE_CONST, {.i64 = FMT_NONE},    .unit = "format" },
+    {     "pretty", "pretty printed ASCII art graph",   0, AV_OPT_TYPE_CONST, {.i64 = FMT_PRETTY},  .unit = "format" },
+    { NULL },
+};
+
+AVFILTER_DEFINE_CLASS(graph_dump);
+
 static int print_link_prop(AVBPrint *buf, AVFilterLink *link)
 {
     const char *format;
@@ -61,7 +84,7 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link)
     return buf->len;
 }
 
-static void avfilter_graph_dump_to_buf(AVBPrint *buf, AVFilterGraph *graph)
+static void dump_pretty(AVBPrint *buf, AVFilterGraph *graph)
 {
     unsigned i, j, x, e;
 
@@ -157,13 +180,30 @@ char *avfilter_graph_dump(AVFilterGraph *graph, const char *options)
 {
     AVBPrint buf;
     char *dump = NULL;
+    int ret;
 
-    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_COUNT_ONLY);
-    avfilter_graph_dump_to_buf(&buf, graph);
-    dump = av_malloc(buf.len + 1);
-    if (!dump)
+    GraphDumpOptions opts = {
+        .class = &graph_dump_class,
+    };
+
+    static const char *shorthand[] = {
+        "format", NULL,
+    };
+
+    av_opt_set_defaults(&opts);
+    ret = av_opt_set_from_string(&opts, options, shorthand, "=", ":");
+    if (ret < 0)
         return NULL;
-    av_bprint_init_for_buffer(&buf, dump, buf.len + 1);
-    avfilter_graph_dump_to_buf(&buf, graph);
+
+    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC);
+    switch (opts.format) {
+    case FMT_NONE:
+        break;
+    case FMT_PRETTY:
+        dump_pretty(&buf, graph);
+        break;
+    }
+
+    av_bprint_finalize(&buf, &dump);
     return dump;
 }
-- 
2.47.0

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

             reply	other threads:[~2025-02-18 12:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-18 12:46 Niklas Haas [this message]
2025-02-18 12:46 ` [FFmpeg-devel] [PATCH v2 2/4] avfilter/filters: keep track of AVFilterPad labels Niklas Haas
2025-02-18 12:46 ` [FFmpeg-devel] [PATCH v2 3/4] avfilter/graphdump: add complex format Niklas Haas
2025-02-18 12:46 ` [FFmpeg-devel] [PATCH v2 4/4] fftools/ffmpeg_filter: add -dump_filter_graph option Niklas Haas
2025-02-18 16:43   ` epirat07
2025-02-19 17:36     ` Niklas Haas
2025-02-18 12:50 ` [FFmpeg-devel] [PATCH v2 1/4] avfilter/graphdump: implement options parsing Niklas Haas

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=20250218124603.95398-1-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /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