From patchwork Mon Aug 23 09:45:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29732 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1919617iov; Mon, 23 Aug 2021 02:45:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyONMhjOYnoT9twpkixX85p0oHZZEWETeldu3f63lb2ty/NcuKbOO/ActKJxy9oIuGplzLa X-Received: by 2002:a50:eb95:: with SMTP id y21mr35645754edr.5.1629711923705; Mon, 23 Aug 2021 02:45:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629711923; cv=none; d=google.com; s=arc-20160816; b=JZirB4O+YPT/0D17qlPNL9X9VeVrTNR24hXp7I+SQ6d7z+ghxSdD8cgOQFRoYJoFlU B911GAKWG+WkkuxvImk553aEopq958YVAV9Ji3XmeD6/Bi9eJHbAJq53P2flrfNaIP1n mviSFk7CAliaMBbKyxT+OM66DqjYrPPaTM+a4jAETnLQSsLwzaEyYDYz5WTrzgIMcyMY x4lLzwfGgFylLLPD1PVqsuL6ZlbRd5Q5CQvmzTuMvGR9+Jr+AjolguZEGqygLvOs9qzm TYBClQ+/uNfWLuz7mA0xwIeqQFV3FjP+v4UKUvjiYPexclp0I8OYunX8SDj1EGoyvAEr AWMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=zQUKeHU50by8Z8/bsynEWYbAUueEtSV3I5b3HoAQaGA=; b=0ncPZiOsan2UfuRvCJVdws1DiCNfA6GUvEydtIrAG1aA0mC7GB6G1HENuPup5gEZnb j4O0Q1BTSy8HXS1WbxwogQ2dHVx36Xae/6MAJfO6Y9cBqDUJ/H34m1p+r8z4jAwoC9qF KFni2aXLBaLO5tVNxIBZKzBq9KfTKyZOYIrykZPRQMd6QnugcsQHlFSBIdQ7mHlY6Ob5 GwjBG0k8N5VaykaodOS5cX8WBKmTSyVccX3YcXFlQ1sNmQ7tw/5dmsV2V5PDj2RY880l 9ljVxB+tGxmuRmpsRMmO5yOAvFZfjbz6/U8lDhVNLQ+04BotAjqxjTlOUSlmGqAs2Od8 Zyhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id my9si14390859ejc.686.2021.08.23.02.45.18; Mon, 23 Aug 2021 02:45:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EA01468A307; Mon, 23 Aug 2021 12:45:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9C61A6809BA for ; Mon, 23 Aug 2021 12:45:07 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 17N9j6W9005626 for ; Mon, 23 Aug 2021 11:45:06 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 3FA4FEB5BC; Mon, 23 Aug 2021 11:45:05 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Aug 2021 11:45:03 +0200 Message-Id: <20210823094504.100789-1-george@nsup.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Mon, 23 Aug 2021 11:45:06 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 1/2] lavfi/graphdump: add plain listing output 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: asmfzeaUQmKK Signed-off-by: Nicolas George --- libavfilter/avfilter.h | 5 ++- libavfilter/graphdump.c | 79 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 69ecb0186d..2a3c1e79a8 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -1097,7 +1097,10 @@ int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const * Dump a graph into a human-readable string representation. * * @param graph the graph to dump - * @param options formatting options; currently ignored + * @param options formatting options; can be NULL, empty + * or "f=aa" for clumsy ascii-art drawing, + * or "f=tech" for plain listing; + * other values silently ignored * @return a string, or NULL in case of memory allocation failure; * the string must be freed using av_free */ diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c index 79ef1a733f..388f80de80 100644 --- a/libavfilter/graphdump.c +++ b/libavfilter/graphdump.c @@ -27,6 +27,9 @@ #include "avfilter.h" #include "internal.h" +#define FORMAT_AA 0 +#define FORMAT_TECH 1 + static int print_link_prop(AVBPrint *buf, AVFilterLink *link) { char *format; @@ -59,7 +62,51 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link) return buf->len; } -static void avfilter_graph_dump_to_buf(AVBPrint *buf, AVFilterGraph *graph) +static inline const char *fcname(const AVFilterContext *filter) +{ + return filter->name ? filter->name : ""; +} + +static void dump_tech(AVBPrint *buf, AVFilterGraph *graph) +{ + unsigned i, j; + + for (i = 0; i < graph->nb_filters; i++) { + AVFilterContext *filter = graph->filters[i]; + + if (i) + av_bprintf(buf, "\n"); + av_bprintf(buf, "Filter: %s (%s)\n", fcname(filter), filter->filter->name); + + for (j = 0; j < filter->nb_inputs; j++) { + AVFilterPad *pad = &filter->input_pads[j]; + AVFilterLink *link = filter->inputs[j]; + AVFilterPad *ppad = link->srcpad; + AVFilterContext *peer = link->src; + + av_bprintf(buf, " in %d: %s ← %s.%d:%s ", + j, pad->name, + fcname(peer), FF_OUTLINK_IDX(link), ppad->name); + print_link_prop(buf, link); + av_bprintf(buf, "\n"); + } + + for (j = 0; j < filter->nb_outputs; j++) { + AVFilterPad *pad = &filter->output_pads[j]; + AVFilterLink *link = filter->outputs[j]; + AVFilterPad *ppad = link->dstpad; + AVFilterContext *peer = link->dst; + + av_bprintf(buf, " out %d: %s → %s.%d:%s ", + j, pad->name, + fcname(peer), FF_INLINK_IDX(link), ppad->name); + print_link_prop(buf, link); + av_bprintf(buf, "\n"); + } + } +} + +static void dump_ascii_art(AVBPrint *buf, AVFilterGraph *graph) { unsigned i, j, x, e; @@ -151,15 +198,41 @@ static void avfilter_graph_dump_to_buf(AVBPrint *buf, AVFilterGraph *graph) } } +static void avfilter_graph_dump_to_buf(AVBPrint *buf, AVFilterGraph *graph, const char *options) +{ + unsigned format = FORMAT_AA; + + /* For a very long time, options was ignored. + Having a string for that task was a mistake, but it is not important. + It is not worth a proper parsing. + */ + if (options && *options) { + if (!strcmp("f=aa", options)) { + format = FORMAT_AA; + } else if (!strcmp("f=tech", options)) { + format = FORMAT_TECH; + } + /* ignore other values */ + } + switch (format) { + case FORMAT_AA: + dump_ascii_art(buf, graph); + break; + case FORMAT_TECH: + dump_tech(buf, graph); + break; + } +} + char *avfilter_graph_dump(AVFilterGraph *graph, const char *options) { AVBPrint buf; char *dump = NULL; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_COUNT_ONLY); - avfilter_graph_dump_to_buf(&buf, graph); + avfilter_graph_dump_to_buf(&buf, graph, options); av_bprint_init(&buf, buf.len + 1, buf.len + 1); - avfilter_graph_dump_to_buf(&buf, graph); + avfilter_graph_dump_to_buf(&buf, graph, options); av_bprint_finalize(&buf, &dump); return dump; } From patchwork Mon Aug 23 09:45:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29731 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp1919746iov; Mon, 23 Aug 2021 02:45:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa2o6GGsyCJC1dauSClMXh2tlX4aHNxPfPSYFZhI49aG8NbsVEiesii8M/Kcc7NNoY5olH X-Received: by 2002:a17:906:4d4d:: with SMTP id b13mr10624505ejv.528.1629711937708; Mon, 23 Aug 2021 02:45:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629711937; cv=none; d=google.com; s=arc-20160816; b=Wn1Phj4sR2ttFEdyaua5gAPAoexF+1hZHG8lZlFhDqD1a/lPdrI27JR/g+pirYc459 wCx9u+rkjdMs5XKe1MlYYDTJiBei8xAzt5p3shusk9XJ5xiOHInBMt9qIjiDL+qrliC8 QgQLAay1TM3jDzZ7vX4U/OEr8yfleKKoX1JX6svlvBpKowmBeb+jAw1oO5I0iMi1kdGO EAuKiVx8N50q1x132nzs0zQ0216uIeQi86DPF/b/7ByT+S/r3MDN9dXYGDhZQj7aDzPw MNnmrUUx4Bao5OyLMPG/wVlmYr/UU0yD2TAhfxfaDUSBd33el5+sdiWb0/jV6/xJWgcU zcOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=eNFhFvja1hwtyPuHn25wX0w5QKkkSLpldcxJjA7Pahk=; b=kWFiauGF0ghLvGYm8D2rFsnG0mILKQAdog5TGZTOSf1mOawbdXvPrxGHAns2ne3Fc1 th9Leb5muUJlJu/qflkMnyyUj4/9Ta06KsMKFqyCBb1nCxXJzmdylkCPFgcT9oMZ6fZP 1BrLSRQ6hpenLPc4jl9a6eA/Cc9m3xlDMEQnXLG3yDaQCf4GYqLNhG+FdNr+QnPPipwD VKqmflihCvdR1Qp3YYGGoJYroLNbU4efQyHvx0cwJPm1ihliXIZETOLzrJmA7HUOt3vB p4Hhg66cPE+8ydp3dXG1+cB31jwuEaMVoq69Z9O8vbXpfR2195ylxffPzlJYUmY0MWiY Lz4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id oz15si14430212ejc.715.2021.08.23.02.45.31; Mon, 23 Aug 2021 02:45:37 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3EED168A348; Mon, 23 Aug 2021 12:45:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C8AEE68A0EA for ; Mon, 23 Aug 2021 12:45:07 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 17N9j77K005636 for ; Mon, 23 Aug 2021 11:45:07 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 02BECEB5BC; Mon, 23 Aug 2021 11:45:06 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Aug 2021 11:45:04 +0200 Message-Id: <20210823094504.100789-2-george@nsup.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210823094504.100789-1-george@nsup.org> References: <20210823094504.100789-1-george@nsup.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Mon, 23 Aug 2021 11:45:07 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 2/2] fftools: add -lavfi_dump option 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: M5yOrCLZH2cu Signed-off-by: Nicolas George --- doc/ffmpeg.texi | 4 ++++ fftools/ffmpeg.h | 1 + fftools/ffmpeg_filter.c | 14 ++++++++++++++ fftools/ffmpeg_opt.c | 3 +++ 4 files changed, 22 insertions(+) This will be useful for tests covering suble cases of the format negotiation. I do not like to depend on libavdevice's lavfi, it is clumsy. diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index c896aede3b..e7341dda1d 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1834,6 +1834,10 @@ The default is the number of available CPUs. Define a complex filtergraph, i.e. one with arbitrary number of inputs and/or outputs. Equivalent to @option{-filter_complex}. +@anchor{lavfi_dump option} +@item -lavfi_dump (@emph{global}) +Dump the filter graphs and their negotiated formats to standard output. + @item -filter_complex_script @var{filename} (@emph{global}) This option is similar to @option{-filter_complex}, the only difference is that its argument is the name of the file from which a complex filtergraph diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d2dd7ca092..42bf06e224 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -637,6 +637,7 @@ extern int filter_nbthreads; extern int filter_complex_nbthreads; extern int vstats_version; extern int auto_conversion_filters; +extern int dump_filtergraphs; extern const AVIOInterruptCB int_cb; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 49076f13ee..a35c93f587 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1056,6 +1056,20 @@ int configure_filtergraph(FilterGraph *fg) avfilter_graph_set_auto_convert(fg->graph, AVFILTER_AUTO_CONVERT_NONE); if ((ret = avfilter_graph_config(fg->graph, NULL)) < 0) goto fail; + if (dump_filtergraphs) { + char *dump = avfilter_graph_dump(fg->graph, "f=tech"); + if (!dump) + return AVERROR(ENOMEM); + if (simple) { + OutputStream *ost = fg->outputs[0]->ost; + printf("Dump of filter graph for output #%d:%d:", ost->file_index, ost->index); + } else { + printf("Dump of complex filter graph #%d:", fg->index); + } + printf("\n\n%s\n", dump); + av_free(dump); + fflush(stdout); + } /* limit the lists of allowed formats to the ones selected, to * make sure they stay the same if the filtergraph is reconfigured later */ diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 428934a3d8..7855ea8a32 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -173,6 +173,7 @@ int filter_nbthreads = 0; int filter_complex_nbthreads = 0; int vstats_version = 2; int auto_conversion_filters = 1; +int dump_filtergraphs = 0; int64_t stats_period = 500000; @@ -3632,6 +3633,8 @@ const OptionDef options[] = { "number of threads for -filter_complex" }, { "lavfi", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex }, "create a complex filtergraph", "graph_description" }, + { "lavfi_dump", OPT_BOOL | OPT_EXPERT, { &dump_filtergraphs }, + "dump filter graphs to standard output" }, { "filter_complex_script", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex_script }, "read complex filtergraph description from a file", "filename" }, { "auto_conversion_filters", OPT_BOOL | OPT_EXPERT, { &auto_conversion_filters },