[FFmpeg-devel] [PATCH] lavfi/overlay: make use of av_opt_set_from_string()

Stefano Sabatini stefasab at gmail.com
Sat Dec 15 14:52:42 CET 2012


Simplify.

TODO: bump micro.
---
 doc/filters.texi         |   25 +++++++++++++------------
 libavfilter/vf_overlay.c |   29 +++--------------------------
 2 files changed, 16 insertions(+), 38 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 7b2c56c..5b69559 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -3094,13 +3094,20 @@ Overlay one video on top of another.
 It takes two inputs and one output, the first input is the "main"
 video on which the second input is overlayed.
 
-It accepts the parameters: @var{x}:@var{y}[:@var{options}].
+This filter accepts a list of @var{key}=@var{value} pairs as argument,
+separated by ":". If the key of the first options is omitted, the
+arguments are interpreted according to the syntax @var{x}:@var{y}.
 
- at var{x} is the x coordinate of the overlayed video on the main video,
- at var{y} is the y coordinate. @var{x} and @var{y} are expressions containing
-the following parameters:
+A description of the accepted options follows.
 
 @table @option
+ at item x, y
+Set the expression for the x and y coordinates of the overlayed video
+on the main video. Default value is 0.
+
+The @var{x} and @var{y} expressions can contain the following
+parameters:
+ at table @option
 @item main_w, main_h
 main input width and height
 
@@ -3114,15 +3121,9 @@ overlay input width and height
 same as @var{overlay_w} and @var{overlay_h}
 @end table
 
- at var{options} is an optional list of @var{key}=@var{value} pairs,
-separated by ":".
-
-The description of the accepted options follows.
-
- at table @option
 @item rgb
-If set to 1, force the filter to accept inputs in the RGB
-color space. Default value is 0.
+If set to 1, force the filter to accept inputs in the RGB color
+space. Default value is 0.
 @end table
 
 Be aware that frames are taken from each input video in timestamp
diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index 23f4e79..6c67bc8 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -110,42 +110,19 @@ AVFILTER_DEFINE_CLASS(overlay);
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     OverlayContext *over = ctx->priv;
-    char *args1 = av_strdup(args);
-    char *expr, *bufptr = NULL;
-    int ret = 0;
+    static const char *shorthand[] = { "x", "y", NULL };
 
     over->class = &overlay_class;
     av_opt_set_defaults(over);
 
-    if (expr = av_strtok(args1, ":", &bufptr)) {
-        av_free(over->x_expr);
-        if (!(over->x_expr = av_strdup(expr))) {
-            ret = AVERROR(ENOMEM);
-            goto end;
-        }
-    }
-    if (expr = av_strtok(NULL, ":", &bufptr)) {
-        av_free(over->y_expr);
-        if (!(over->y_expr = av_strdup(expr))) {
-            ret = AVERROR(ENOMEM);
-            goto end;
-        }
-    }
-
-    if (bufptr && (ret = av_set_options_string(over, bufptr, "=", ":")) < 0)
-        goto end;
-
-end:
-    av_free(args1);
-    return ret;
+    return av_opt_set_from_string(over, args, shorthand, "=", ":");
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
 {
     OverlayContext *over = ctx->priv;
 
-    av_freep(&over->x_expr);
-    av_freep(&over->y_expr);
+    av_opt_free(over);
 
     avfilter_unref_bufferp(&over->overpicref);
     ff_bufqueue_discard_all(&over->queue_main);
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list