[FFmpeg-cvslog] graphparser: allow specifying sws flags in the graph description.

Anton Khirnov git at videolan.org
Sat Apr 14 22:52:17 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Apr  9 06:13:53 2012 +0200| [12e7e1d03e772b16ae95fa6c79ed870d9335564c] | committer: Anton Khirnov

graphparser: allow specifying sws flags in the graph description.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=12e7e1d03e772b16ae95fa6c79ed870d9335564c
---

 doc/filters.texi          |    8 +++++++-
 libavfilter/graphparser.c |   29 +++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 2a089be..446e124 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -76,6 +76,12 @@ In a complete filterchain all the unlabelled filter input and output
 pads must be connected. A filtergraph is considered valid if all the
 filter input and output pads of all the filterchains are connected.
 
+Libavfilter will automatically insert scale filters where format
+conversion is required. It is possible to specify swscale flags
+for those automatically inserted scalers by prepending
+ at code{sws_flags=@var{flags};}
+to the filtergraph description.
+
 Follows a BNF description for the filtergraph syntax:
 @example
 @var{NAME}             ::= sequence of alphanumeric characters and '_'
@@ -84,7 +90,7 @@ Follows a BNF description for the filtergraph syntax:
 @var{FILTER_ARGUMENTS} ::= sequence of chars (eventually quoted)
 @var{FILTER}           ::= [@var{LINKNAMES}] @var{NAME} ["=" @var{ARGUMENTS}] [@var{LINKNAMES}]
 @var{FILTERCHAIN}      ::= @var{FILTER} [, at var{FILTERCHAIN}]
- at var{FILTERGRAPH}      ::= @var{FILTERCHAIN} [;@var{FILTERGRAPH}]
+ at var{FILTERGRAPH}      ::= [sws_flags=@var{flags};] @var{FILTERCHAIN} [;@var{FILTERGRAPH}]
 @end example
 
 @c man end FILTERGRAPH DESCRIPTION
diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c
index ebd9cc9..d2d3165 100644
--- a/libavfilter/graphparser.c
+++ b/libavfilter/graphparser.c
@@ -349,6 +349,30 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
 #else
 #define log_ctx NULL
 #endif
+
+static int parse_sws_flags(const char **buf, AVFilterGraph *graph)
+{
+    char *p = strchr(*buf, ';');
+
+    if (strncmp(*buf, "sws_flags=", 10))
+        return 0;
+
+    if (!p) {
+        av_log(log_ctx, AV_LOG_ERROR, "sws_flags not terminated with ';'.\n");
+        return AVERROR(EINVAL);
+    }
+
+    *buf += 4;  // keep the 'flags=' part
+
+    av_freep(&graph->scale_sws_opts);
+    if (!(graph->scale_sws_opts = av_mallocz(p - *buf + 1)))
+        return AVERROR(ENOMEM);
+    av_strlcpy(graph->scale_sws_opts, *buf, p - *buf + 1);
+
+    *buf = p + 1;
+    return 0;
+}
+
 int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
                           AVFilterInOut **inputs,
                           AVFilterInOut **outputs)
@@ -358,6 +382,11 @@ int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
 
     AVFilterInOut *curr_inputs = NULL, *open_inputs = NULL, *open_outputs = NULL;
 
+    filters += strspn(filters, WHITESPACES);
+
+    if ((ret = parse_sws_flags(&filters, graph)) < 0)
+        goto fail;
+
     do {
         AVFilterContext *filter;
         filters += strspn(filters, WHITESPACES);



More information about the ffmpeg-cvslog mailing list