[FFmpeg-soc] [soc]: r4271 - in libavfilter: doc/vfilters.texi vf_overlay.c

stefano subversion at mplayerhq.hu
Fri May 15 01:16:47 CEST 2009


Author: stefano
Date: Fri May 15 01:16:47 2009
New Revision: 4271

Log:
Make the overlay filter parameters x and y parametric.

Patch by Martin Storsjö <name at name.st>.

Modified:
   libavfilter/doc/vfilters.texi
   libavfilter/vf_overlay.c

Modified: libavfilter/doc/vfilters.texi
==============================================================================
--- libavfilter/doc/vfilters.texi	Thu May 14 21:28:42 2009	(r4270)
+++ libavfilter/doc/vfilters.texi	Fri May 15 01:16:47 2009	(r4271)
@@ -145,6 +145,18 @@ inputs through a @var{setpts=PTS-STARTPT
 begin in the same zero timestamp, as it does the example for
 the @var{movie} filter.
 
+Parameters to the filter are separated by a colon. The first parameter
+is the x coordinate of the overlay, the second parameter is the y
+coordinate. The parameters need not be constant expressions, but may
+be expressions containing the names @var{mainW}, @var{mainH},
+ at var{overlayW} and @var{overlayH}, for the size of the first and second
+input video, respectively. For example,
+ at example
+overlay=mainW-overlayW-10:mainH-overlayH-10
+ at end example
+can be used to draw the overlay at 10 pixels from the bottom right
+corner of the main video.
+
 @section rotate
 
 @example

Modified: libavfilter/vf_overlay.c
==============================================================================
--- libavfilter/vf_overlay.c	Thu May 14 21:28:42 2009	(r4270)
+++ libavfilter/vf_overlay.c	Fri May 15 01:16:47 2009	(r4271)
@@ -22,6 +22,23 @@
 #include <stdio.h>
 
 #include "avfilter.h"
+#include "libavcodec/eval.h"
+
+static const char *var_names[] = {
+    "mainW",    ///< width of the main video
+    "mainH",    ///< height of the main video
+    "overlayW", ///< width of the overlay video
+    "overlayH", ///< height of the overlay video
+    NULL
+};
+
+enum var_name {
+    MAIN_W,
+    MAIN_H,
+    OVERLAY_W,
+    OVERLAY_H,
+    VARS_NB
+};
 
 typedef struct {
     int x, y;                   //< position of subpicture
@@ -34,16 +51,19 @@ typedef struct {
 
     int bpp;                    //< bytes per pixel
     int hsub, vsub;             //< chroma subsampling
+
+    char x_expr[256], y_expr[256];
 } OverlayContext;
 
 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
 {
     OverlayContext *over = ctx->priv;
 
-    if(!args || sscanf(args, "%d:%d", &over->x, &over->y) != 2) {
-        over->x =
-        over->y = 0;
-    }
+    av_strlcpy(over->x_expr, "0", sizeof(over->x_expr));
+    av_strlcpy(over->y_expr, "0", sizeof(over->y_expr));
+
+    if (args)
+        sscanf(args, "%255[^:]:%255[^:]", over->x_expr, over->y_expr);
 
     return 0;
 }
@@ -89,6 +109,37 @@ static int config_input_main(AVFilterLin
     return 0;
 }
 
+static int config_input_overlay(AVFilterLink *link)
+{
+    AVFilterContext *ctx  = link->dst;
+    OverlayContext  *over = link->dst->priv;
+    const char *error = NULL, *expr;
+    double var_values[VARS_NB];
+
+    /* Finish the configuration by evaluating the expressions
+       now when both inputs are configured. */
+    var_values[MAIN_W]    = ctx->inputs[0]->w;
+    var_values[MAIN_H]    = ctx->inputs[0]->h;
+    var_values[OVERLAY_W] = ctx->inputs[1]->w;
+    var_values[OVERLAY_H] = ctx->inputs[1]->h;
+
+    over->x = ff_eval2((expr = over->x_expr), var_values, var_names,
+                       NULL, NULL, NULL, NULL, NULL, &error);
+    if (error)
+        goto fail;
+    over->y = ff_eval2((expr = over->y_expr), var_values, var_names,
+                       NULL, NULL, NULL, NULL, NULL, &error);
+    if (error)
+        goto fail;
+
+    return 0;
+
+fail:
+    av_log(NULL, AV_LOG_ERROR,
+           "Error when evaluating the expression '%s': %s\n", expr, error);
+    return -1;
+}
+
 static void shift_input(OverlayContext *over, int idx)
 {
     assert(over->pics[idx][0]);
@@ -238,6 +289,7 @@ AVFilter avfilter_vf_overlay =
                                   { .name            = "sub",
                                     .type            = CODEC_TYPE_VIDEO,
                                     .start_frame     = start_frame,
+                                    .config_props    = config_input_overlay,
                                     .end_frame       = end_frame,
                                     .min_perms       = AV_PERM_READ,
                                     .rej_perms       = AV_PERM_REUSE2, },


More information about the FFmpeg-soc mailing list