[FFmpeg-cvslog] lavfi/drawtext: add support to expansion of generic expressions

Stefano Sabatini git at videolan.org
Tue Nov 27 23:43:56 CET 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Tue Nov 27 11:27:12 2012 +0100| [2ac6a3d1bfd0a165a3f15da6ed75c718e908f5f4] | committer: Stefano Sabatini

lavfi/drawtext: add support to expansion of generic expressions

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

 doc/filters.texi          |   10 ++++++++++
 libavfilter/version.h     |    2 +-
 libavfilter/vf_drawtext.c |   22 ++++++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 99654eb..f3e86c1 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2075,6 +2075,16 @@ The following functions are available:
 
 @table @command
 
+ at item expr, e
+The expression evaluation result.
+
+It must take one argument specifying the expression to be evaluated,
+which accepts the same constants and functions as the @var{x} and
+ at var{y} values. Note that not all constants should be used, for
+example the text size is not known when evaluating the expression, so
+the constants @var{text_w} and @var{text_h} will have an undefined
+value.
+
 @item gmtime
 The time at which the filter is running, expressed in UTC.
 It can accept an argument: a strftime() format string.
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 04ab662..64e1f4b 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
 
 #define LIBAVFILTER_VERSION_MAJOR  3
 #define LIBAVFILTER_VERSION_MINOR  23
-#define LIBAVFILTER_VERSION_MICRO 103
+#define LIBAVFILTER_VERSION_MICRO 104
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 96512ab..509fbd2 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -643,12 +643,34 @@ static int func_strftime(AVFilterContext *ctx, AVBPrint *bp,
     return 0;
 }
 
+static int func_eval_expr(AVFilterContext *ctx, AVBPrint *bp,
+                          char *fct, unsigned argc, char **argv, int tag)
+{
+    DrawTextContext *dtext = ctx->priv;
+    double res;
+    int ret;
+
+    ret = av_expr_parse_and_eval(&res, argv[0], var_names, dtext->var_values,
+                                 NULL, NULL, fun2_names, fun2,
+                                 &dtext->prng, 0, ctx);
+    if (ret < 0)
+        av_log(ctx, AV_LOG_ERROR,
+               "Expression '%s' for the expr text expansion function is not valid\n",
+               argv[0]);
+    else
+        av_bprintf(bp, "%f", res);
+
+    return ret;
+}
+
 static const struct drawtext_function {
     const char *name;
     unsigned argc_min, argc_max;
     int tag; /** opaque argument to func */
     int (*func)(AVFilterContext *, AVBPrint *, char *, unsigned, char **, int);
 } functions[] = {
+    { "expr",      1, 1, 0,   func_eval_expr },
+    { "e",         1, 1, 0,   func_eval_expr },
     { "pts",       0, 0, 0,   func_pts      },
     { "gmtime",    0, 1, 'G', func_strftime },
     { "localtime", 0, 1, 'L', func_strftime },



More information about the ffmpeg-cvslog mailing list