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

Víctor Paesa victorpaesa at googlemail.com
Tue Sep 20 23:49:18 CEST 2011


Hi,

On Tue, Sep 20, 2011 at 20:30, Stefano Sabatini <stefasab at gmail.com> 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"

> +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).

[...]

> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
> index d7447c2..ffc2bdf 100644
> --- a/libavfilter/vf_drawtext.c
> +++ b/libavfilter/vf_drawtext.c
> @@ -30,6 +30,7 @@
>  #include <time.h>
>
>  #include "libavutil/colorspace.h"
> +#include "libavutil/eval.h"
>  #include "libavutil/file.h"
>  #include "libavutil/opt.h"
>  #include "libavutil/parseutils.h"
> @@ -45,6 +46,46 @@
>  #include FT_FREETYPE_H
>  #include FT_GLYPH_H
>
> +static const char *var_names[] = {
> +    "E",
> +    "PHI",
> +    "PI",
> +    "w",             ///< width  of the input video
> +    "h",             ///< height of the input video
> +    "tw", "text_w",  ///< width  of the rendered text
> +    "th", "text_h",  ///< height of the rendered text
> +    "lh", "line_h",  ///< height of each line
> +    "sar",
> +    "dar",
> +    "hsub",
> +    "vsub",
> +    "x",
> +    "y",
> +    "n",            ///< number of frame
> +    "t",            ///< timestamp expressed in seconds
> +    NULL
> +};
> +
> +enum var_name {
> +    VAR_E,
> +    VAR_PHI,
> +    VAR_PI,
> +    VAR_W,
> +    VAR_H,
> +    VAR_TW, VAR_TEXT_W,
> +    VAR_TH, VAR_TEXT_H,
> +    VAR_LH, VAR_LINE_H,
> +    VAR_SAR,
> +    VAR_DAR,
> +    VAR_HSUB,
> +    VAR_VSUB,
> +    VAR_X,
> +    VAR_Y,
> +    VAR_N,
> +    VAR_T,
> +    VAR_VARS_NB
> +};
> +
>  typedef struct {
>     const AVClass *class;
>     uint8_t *fontfile;              ///< font to be used
> @@ -57,6 +98,11 @@ typedef struct {
>     char *textfile;                 ///< file with text to be drawn
>     int x;                          ///< x position to start drawing text
>     int y;                          ///< y position to start drawing text
> +    char *x_expr;                   ///< expression for x position
> +    char *y_expr;                   ///< expression for y position
> +    AVExpr *x_pexpr, *y_pexpr;      ///< parsed expressions for x and y
> +    int line_h;                     ///< size of each line
                                            ^^^^
It should be "height of each line"

Regards,
Víctor


More information about the ffmpeg-devel mailing list