[FFmpeg-devel] [PATCH 2/2] drawtext: introduce fontcolor argument expansion

Stefano Sabatini stefasab at gmail.com
Mon Jun 23 16:34:11 CEST 2014


On date Monday 2014-06-23 16:27:46 +0200, Stefano Sabatini encoded:
> On date Sunday 2014-06-22 17:31:10 +0300, Andrey Utkin encoded:
> > ---
> >  libavfilter/vf_drawtext.c | 68 +++++++++++++++++++++++++++++++++++++++++++----
> >  1 file changed, 63 insertions(+), 5 deletions(-)
> 
> Missing doc updates.

[...] 
> > +static int func_eval_expr_int_format(AVFilterContext *ctx, AVBPrint *bp,
> > +                          char *fct, unsigned argc, char **argv, int tag)
> > +{
> > +    DrawTextContext *s = ctx->priv;
> > +    double res;
> > +    int intval;
> > +    int ret;
> > +
> > +    /* Check that argv[0] (format) contains exactly one output specifier */
> > +    const char *percent_sign = strchr(argv[0], '%');
> > +    if (!percent_sign || strchr(percent_sign + 1, '%')) {
> > +        av_log(ctx, AV_LOG_ERROR, "Format must contain exactly one output "
> > +                "specifier, but '%s' is supplied\n", argv[0]);
> > +        return AVERROR(EINVAL);
> > +    }
> > +    ret = av_expr_parse_and_eval(&res, argv[1], var_names, s->var_values,
> > +                                 NULL, NULL, fun2_names, fun2,
> > +                                 &s->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[1]);
> > +    else
> > +    {
> > +        av_log(ctx, AV_LOG_DEBUG, "Formatting value %f (expr '%s') with spec '%s'\n",
> > +                res, argv[1], argv[0]);
> > +        feclearexcept(FE_ALL_EXCEPT);
> > +        intval = res;
> > +        if ((ret = fetestexcept(FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW))) {
> > +            av_log(ctx, AV_LOG_ERROR, "Conversion of floating-point result to int failed. Control register: 0x%08x. Conversion result: %d\n", ret, intval);
> > +            return AVERROR(EINVAL);
> > +        }
> > +        av_bprintf(bp, argv[0], intval);
> > +    }
> > +
> > +    return ret;
> > +}
> 
> If I understand it correctly this evaluates some expression of the
> kind "%d" 42.00 -> "42", right? I'd prefer this in a separate patch,
> also I believe this has some security implications (for example an
> invalid format sequence may lead to a crash).

> Also how is this related to $subject.

Forget about the question, I see it from your example:
fontcolor_expr=ff0000%{eif\\\: %02x\\\: max(0\\, min(255\\,
255*(1*between(t\\, $DS + $FID\\, $DE - $FOD) + ((t - $DS)/$FID)*between(t\\, $DS\\, $DS + $FID) + (-(t - $DE)/$FOD)*between(t\\, $DE - $FOD\\, $DE) ) ))}

[...]
-- 
FFmpeg = Frightening & Fundamentalist Meaningless Power Ermetic Gadget


More information about the ffmpeg-devel mailing list