diff mbox series

[FFmpeg-devel,v4,2/2] avdevice/lavf: add more options to dump filter graph

Message ID 1590191673-2181-2-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,v4,1/2] fftools: add options to dump filter graph
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Limin Wang May 22, 2020, 11:54 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 doc/indevs.texi     | 16 ++++++++++++++--
 libavdevice/lavfi.c | 19 +++++++++++++------
 2 files changed, 27 insertions(+), 8 deletions(-)

Comments

Nicolas George May 23, 2020, 12:52 p.m. UTC | #1
lance.lmwang@gmail.com (12020-05-23):
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  doc/indevs.texi     | 16 ++++++++++++++--
>  libavdevice/lavfi.c | 19 +++++++++++++------
>  2 files changed, 27 insertions(+), 8 deletions(-)

I think the change to allow to set the format and the change to allow to
set the output file belong in a different patch.

The existing dump_graph field can very well serve as the options string
for the function.

Regards,
Limin Wang May 23, 2020, 2:05 p.m. UTC | #2
On Sat, May 23, 2020 at 02:52:12PM +0200, Nicolas George wrote:
> lance.lmwang@gmail.com (12020-05-23):
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  doc/indevs.texi     | 16 ++++++++++++++--
> >  libavdevice/lavfi.c | 19 +++++++++++++------
> >  2 files changed, 27 insertions(+), 8 deletions(-)
> 
> I think the change to allow to set the format and the change to allow to
> set the output file belong in a different patch.

OK, will try to split the patch.

> 
> The existing dump_graph field can very well serve as the options string
> for the function.

So you prefer to the existing dump_graph option as options string for format?

> 
> Regards,
> 
> -- 
>   Nicolas George
diff mbox series

Patch

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 6f5afaf..a1bd9e1 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -973,8 +973,20 @@  Set the filename of the filtergraph to be read and sent to the other
 filters. Syntax of the filtergraph is the same as the one specified by
 the option @var{graph}.
 
-@item dumpgraph
-Dump graph to stderr.
+@item dumpgraph @var{filename}
+Set the filename of filtergraph for dump.
+
+It is "ASCII" format by default. for Graphviz DOT output format,
+you can convert it to png by GraphViz tool:
+@example
+dot -Tpng dump_fg_filename -o dump_graph.png
+@end example
+
+@item dumpgraph_format @var{format}
+Set the output format of filtergraph for dump. Support format: "DOT", "ASCII".
+
+DOT is the text file format of the suite GraphViz, ASCII is the text file format
+of ASCII style.
 
 @end table
 
diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index c949ff7..18b5f07 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -47,7 +47,8 @@  typedef struct {
     AVClass *class;          ///< class for private options
     char          *graph_str;
     char          *graph_filename;
-    char          *dump_graph;
+    char          *dump_fg_filename;
+    char          *dump_fg_format;
     AVFilterGraph *graph;
     AVFilterContext **sinks;
     int *sink_stream_map;
@@ -300,11 +301,16 @@  av_cold static int lavfi_read_header(AVFormatContext *avctx)
     if ((ret = avfilter_graph_config(lavfi->graph, avctx)) < 0)
         goto end;
 
-    if (lavfi->dump_graph) {
-        char *dump = avfilter_graph_dump(lavfi->graph, lavfi->dump_graph);
+    if (lavfi->dump_fg_filename) {
+        char *dump = avfilter_graph_dump(lavfi->graph, lavfi->dump_fg_format);
+        FILE *fg_file = fopen(lavfi->dump_fg_filename, "w");
+
+        if (!fg_file)
+            FAIL(AVERROR(ENOMEM));
         if (dump != NULL) {
-            fputs(dump, stderr);
-            fflush(stderr);
+            fputs(dump, fg_file);
+            fflush(fg_file);
+            fclose(fg_file);
             av_free(dump);
         } else {
             FAIL(AVERROR(ENOMEM));
@@ -493,7 +499,8 @@  static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
 static const AVOption options[] = {
     { "graph",     "set libavfilter graph", OFFSET(graph_str),  AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
     { "graph_file","set libavfilter graph filename", OFFSET(graph_filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC},
-    { "dumpgraph", "dump graph to stderr",  OFFSET(dump_graph), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+    { "dumpgraph", "set dump graph filename",  OFFSET(dump_fg_filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
+    { "dumpgraph_format", "set dump graph format, DOT or ASCII",  OFFSET(dump_fg_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC },
     { NULL },
 };