[FFmpeg-devel] [PATCH] lavfi/drawtext: add support to expansion of generic expressions
Stefano Sabatini
stefasab at gmail.com
Tue Nov 27 12:06:27 CET 2012
On date Tuesday 2012-11-27 11:43:43 +0100, Nicolas George encoded:
> Le septidi 7 frimaire, an CCXXI, Stefano Sabatini a écrit :
> > TODO: bump micro
> > ---
> > doc/filters.texi | 8 ++++++++
> > libavfilter/vf_drawtext.c | 24 ++++++++++++++++++++++++
> > 2 files changed, 32 insertions(+)
> >
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index 99654eb..5c8bc6f 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -2075,6 +2075,14 @@ 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 at this point, so the constants
> > + at 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/vf_drawtext.c b/libavfilter/vf_drawtext.c
> > index 96512ab..cb23555 100644
> > --- a/libavfilter/vf_drawtext.c
> > +++ b/libavfilter/vf_drawtext.c
> > @@ -167,6 +167,7 @@ typedef struct {
> > AVTimecode tc; ///< timecode context
> > int tc24hmax; ///< 1 if timecode is wrapped to 24 hours, 0 otherwise
> > int frame_id;
> > + int expr_func_warning_done;
> > } DrawTextContext;
> >
> > #define OFFSET(x) offsetof(DrawTextContext, x)
> > @@ -643,12 +644,35 @@ 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 && !dtext->expr_func_warning_done) {
> > + av_log(ctx, AV_LOG_WARNING,
> > + "Expression '%s' for the expr text expansion function is not valid\n",
> > + argv[0]);
> > + dtext->expr_func_warning_done = 1;
>
> Any reason not just return an error? Most of the time, I rather dislike
> programs that continue running when the user made a stupid typo that will
> make their output useless.
This is a post-configuration error, so can't be detected during
configuration, and I felt a bit uneasy about aborting after that
stage. Also note that the function *is* returning an error, but it is
ignored by the higher-level function.
--
FFmpeg = Freak & Foolish Mystic Puritan Evanescent Guru
More information about the ffmpeg-devel
mailing list