[FFmpeg-devel] [PATCH v2] drawtext: add fontcolor_expr

Stefano Sabatini stefasab at gmail.com
Thu Jul 3 19:59:22 CEST 2014


On date Thursday 2014-07-03 16:36:12 +0300, Andrey Utkin encoded:
> An option for fontcolor, dynamically evaluated
> ---
>  doc/filters.texi          | 25 +++++++++++++
>  libavfilter/vf_drawtext.c | 89 ++++++++++++++++++++++++++++++++++++++++++++---
>  2 files changed, 109 insertions(+), 5 deletions(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index a5f6965..3f9dc8e 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -3660,6 +3660,11 @@ the "Color" section in the ffmpeg-utils manual.
>  
>  The default value of @var{fontcolor} is "black".
>  

> + at item fontcolor_expr
> +String which is expanded the same way as @var{text} to obtain dynamic
> + at var{fontcolor} value. By default this option has empty value and is not
> +processed.

It's not very clear the interaction with fontcolor.

Alternatively, what about something like fontcolor_r/g/b/a_expr with
RGBA values expressed as floats in the 0-1 range?

This should be easier on the user and probably more robust.

> +
>  @item font
>  The font family to be used for drawing text. By default Sans.
>  
> @@ -3867,6 +3872,15 @@ 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.
>  

> + at item eif
> +Evaluate the expression's value and output as formatted integer.
> +
> +First argument is expression to be evaluated, same as for @var{expr} function.
> +Second argument specifies output format. Allowed values are 'x', 'X', 'd' and
> +'u', they are treated exactly as in printf function.
> +Third parameter is optional and sets the number of positions taken by output.
> +Effectively this allows to add padding with zeros from the left.

Not a strong objection, but probably better sent as a separate patch
(IIRC this should also fix an open ticket).

>  @item gmtime
>  The time at which the filter is running, expressed in UTC.
>  It can accept an argument: a strftime() format string.
> @@ -3966,6 +3980,17 @@ Print the date of a real-time encoding (see strftime(3)):
>  drawtext='fontfile=FreeSans.ttf:text=%@{localtime:%a %b %d %Y@}'
>  @end example
>  
> + at item
> +Text fading in and out (appearing/disappearing).
> + at example

> +#!/bin/bash

#!/bin/sh is preferred for compatibility reasons.

> +DS=1.0 # display start
> +DE=10.0 # display end
> +FID=1.5 # fade in duration
> +FOD=5 # fade out duration
> +ffplay -f lavfi -i "drawtext=text=TEST:fontsize=50:fontfile=FreeSerif.ttf:fontcolor_expr=ff0000%@{eif\\\\: 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) ) )) \\\\: x\\\\: 2 @}"
> + at end example
> +
>  @end itemize

[...]
-- 
FFmpeg = Fiendish Faithful Mastering Power Exxagerate Gem


More information about the ffmpeg-devel mailing list