From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 301964D1DF for ; Tue, 18 Feb 2025 12:46:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 42B4E68BE12; Tue, 18 Feb 2025 14:46:14 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7ECBC68ADF7 for ; Tue, 18 Feb 2025 14:46:07 +0200 (EET) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with ESMTP id 368E0403BC; Tue, 18 Feb 2025 13:46:07 +0100 (CET) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Feb 2025 13:46:00 +0100 Message-ID: <20250218124603.95398-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/4] avfilter/graphdump: implement options parsing X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas 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".