[FFmpeg-devel] [PATCH] vf_drawtext: make x and y options parametric

Víctor Paesa victorpaesa at googlemail.com
Wed Sep 21 22:14:26 CEST 2011


Hi,

2011/9/21 Víctor Paesa :
> Hi
>
> On Wed, Sep 21, 2011 at 10:33, Stefano Sabatini wrote:
>> On date Tuesday 2011-09-20 23:49:18 +0200, Víctor Paesa encoded:
>>> Hi,
>>>
>>> On Tue, Sep 20, 2011 at 20:30, Stefano Sabatini wrote:
>>> > Address trac issue #378.
>>> > ---
>>> >  doc/filters.texi          |   68 ++++++++++++++++++++-
>>> >  libavfilter/vf_drawtext.c |  143 ++++++++++++++++++++++++++++++++++++++++-----
>>> >  2 files changed, 191 insertions(+), 20 deletions(-)
>>> >
>>> > diff --git a/doc/filters.texi b/doc/filters.texi
>>> > index 1ab6450..f7f7865 100644
>>> > --- a/doc/filters.texi
>>> > +++ b/doc/filters.texi
>>> > @@ -724,10 +724,13 @@ parameter @var{text}.
>>> >  If both text and textfile are specified, an error is thrown.
>>> >
>>> >  @item x, y
>>> > -The offsets where text will be drawn within the video frame.
>>> > -Relative to the top/left border of the output image.
>>
>>> > +The expressions which express the offsets where text will be drawn
>>>
>>> Maybe "x, y express the offsets where text will be drawn"
>>
>> I wanted to stress the fact that x and y contain "expressions", I
>> removed the awkward repetition changing it to:
>>
>> |The expressions which specify the offsets where text will be drawn
>
> Yes, that's nice too.
>
>>> > +within the video frame. They are relative to the top/left border of the
>>> > +output image.
>>> >
>>> > -The default value of @var{x} and @var{y} is 0.
>>> > +The default value of @var{x} and @var{y} is "0".
>>> > +
>>> > +See below for the list of accepted constants.
>>> >
>>> >  @item fontsize
>>> >  The font size to be used for drawing text.
>>> > @@ -795,6 +798,43 @@ The size in number of spaces to use for rendering the tab.
>>> >  Default value is 4.
>>> >  @end table
>>> >
>>> > +The parameters for @var{x} and @var{y} are expressions containing the
>>> > +following constants:
>>> > +
>>> > + at table @option
>>> > + at item E, PI, PHI
>>> > +the corresponding mathematical approximated values for e
>>> > +(euler number), pi (greek PI), PHI (golden ratio)
>>> > +
>>> > + at item w, h
>>> > +the input width and heigth
>>> > +
>>> > + at item tw, text_w
>>> > +the width of the rendered text
>>> > +
>>> > + at item th, text_h
>>> > +the height of the rendered text
>>> > +
>>> > + at item lh, line_h
>>> > +the height of each text line
>>>
>>
>>> It would be nice to expose too either the ascent or the descent
>>> (y_max or y_min in code).
>>
>> Please can you suggest an application for this? So I can add an
>> illustrative example in the docs.
>
> The height of 'g' is the same of 'd', but one goes over the baseline,
> and the other goes down it.
> If you draw words splitted in several commands, you want to make all
> of them follow a common baseline.
>
> For example:
> Properly show "good" with initial "g" in different color at the center
> of the video frame:
>
> drawtext=fontsize=30:fontfile=FreeSerif.ttf:fontcolor=green:text='g':x=(w-text_w)/2:y=(h-text_h+ascent-line_h)/2
> drawtext=fontsize=30:fontfile=FreeSerif.ttf:fontcolor=red:text='ood':x=(w-text_w)/2:y=(h-text_h+ascent-line_h)/2
>
> Improperly show "not good" with initial "not g" in different color at
> the center of the video frame:
>
> drawtext=fontsize=30:fontfile=FreeSerif.ttf:fontcolor=green:text='not
> g':x=(w-text_w)/2:y=(h-text_h-line_h)/2
> drawtext=fontsize=30:fontfile=FreeSerif.ttf:fontcolor=red:text='ood':x=(w-text_w)/2:y=(h-text_h-line_h)/2

Hmm, poor example, because the two text fragments are
drawn one of top of the other.
It would be nice if the text_w of the first fragment could be
used to draw the second, but that is not possible.

So the example (ruining parametric horizontal centering) is:
drawtext=fontsize=30:fontfile=FreeSerif.ttf:fontcolor=green:text='g':x=w/2:y=(h-text_h+ascent-line_h)/2
drawtext=fontsize=30:fontfile=FreeSerif.ttf:fontcolor=red:text='ood':x=w/2+22:y=(h-text_h+ascent-line_h)/2

Regards,
Víctor


More information about the ffmpeg-devel mailing list