aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/vf_drawtext.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-11-27 11:27:12 +0100
committerStefano Sabatini <stefasab@gmail.com>2012-11-27 23:27:50 +0100
commit2ac6a3d1bfd0a165a3f15da6ed75c718e908f5f4 (patch)
tree94f4185dcc9a15f18b72016769739c1a6356a335 /libavfilter/vf_drawtext.c
parent2cfa6fd025f730d91f5904951dd4dbee5899c32a (diff)
downloadffmpeg-2ac6a3d1bfd0a165a3f15da6ed75c718e908f5f4.tar.gz
lavfi/drawtext: add support to expansion of generic expressions
Diffstat (limited to 'libavfilter/vf_drawtext.c')
-rw-r--r--libavfilter/vf_drawtext.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index 96512ab390..509fbd22f5 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 },