FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
vf_drawtext.c File Reference

drawtext filter, based on the original vhook/drawtext.c filter by Gustavo Sverzut Barbieri More...

#include <sys/time.h>
#include <time.h>
#include "config.h"
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/common.h"
#include "libavutil/file.h"
#include "libavutil/eval.h"
#include "libavutil/opt.h"
#include "libavutil/random_seed.h"
#include "libavutil/parseutils.h"
#include "libavutil/timecode.h"
#include "libavutil/tree.h"
#include "libavutil/lfg.h"
#include "avfilter.h"
#include "drawutils.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
#include <ft2build.h>
#include <FT_FREETYPE_H>
#include <FT_GLYPH_H>
#include <FT_ERRORS_H>

Go to the source code of this file.

Data Structures

struct  DrawTextContext
 
struct  ft_error
 
struct  drawtext_function
 

Macros

#define OFFSET(x)   offsetof(DrawTextContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define FT_ERROR_START_LIST   {
 
#define FT_ERRORDEF(e, v, s)   { (e), (s) },
 
#define FT_ERROR_END_LIST   { 0, NULL } };
 
#define FT_ERRMSG(e)   ft_errors[e].err_msg
 

Typedefs

typedef double(* eval_func2 )(void *, double a, double b)
 

Enumerations

enum  var_name {
  VAR_B1, VAR_B2, VAR_S1, VAR_S2,
  VAR_T1, VAR_T2, VAR_NB, VAR_N,
  VAR_T, VAR_S, VAR_VARS_NB, VAR_TB,
  VAR_PTS, VAR_START_PTS, VAR_PREV_PTS, VAR_PREV_SELECTED_PTS,
  VAR_T, VAR_START_T, VAR_PREV_T, VAR_PREV_SELECTED_T,
  VAR_PICT_TYPE, VAR_I, VAR_P, VAR_B,
  VAR_S, VAR_SI, VAR_SP, VAR_BI,
  VAR_PICT_TYPE_I, VAR_PICT_TYPE_P, VAR_PICT_TYPE_B, VAR_PICT_TYPE_S,
  VAR_PICT_TYPE_SI, VAR_PICT_TYPE_SP, VAR_PICT_TYPE_BI, VAR_INTERLACE_TYPE,
  VAR_INTERLACE_TYPE_P, VAR_INTERLACE_TYPE_T, VAR_INTERLACE_TYPE_B, VAR_CONSUMED_SAMPLES_N,
  VAR_SAMPLES_N, VAR_SAMPLE_RATE, VAR_N, VAR_SELECTED_N,
  VAR_PREV_SELECTED_N, VAR_KEY, VAR_POS, VAR_SCENE,
  VAR_VARS_NB, VAR_AVTB, VAR_INTB, VAR_SR,
  VAR_VARS_NB, VAR_FRAME_RATE, VAR_INTERLACED, VAR_N,
  VAR_NB_CONSUMED_SAMPLES, VAR_NB_SAMPLES, VAR_POS, VAR_PREV_INPTS,
  VAR_PREV_INT, VAR_PREV_OUTPTS, VAR_PREV_OUTT, VAR_PTS,
  VAR_SAMPLE_RATE, VAR_STARTPTS, VAR_STARTT, VAR_T,
  VAR_TB, VAR_RTCTIME, VAR_RTCSTART, VAR_S,
  VAR_SR, VAR_VARS_NB, VAR_W, VAR_H,
  VAR_CW, VAR_CH, VAR_HSUB, VAR_VSUB,
  VARS_NB, VAR_IN_W, VAR_IW, VAR_IN_H,
  VAR_IH, VAR_OUT_W, VAR_OW, VAR_OUT_H,
  VAR_OH, VAR_A, VAR_SAR, VAR_DAR,
  VAR_HSUB, VAR_VSUB, VAR_X, VAR_Y,
  VAR_N, VAR_POS, VAR_T, VAR_VARS_NB,
  VAR_DAR, VAR_HSUB, VAR_VSUB, VAR_IN_H,
  VAR_IH, VAR_IN_W, VAR_IW, VAR_SAR,
  VAR_X, VAR_Y, VAR_H, VAR_W,
  VAR_T, VARS_NB, VAR_DAR, VAR_HSUB,
  VAR_VSUB, VAR_LINE_H, VAR_LH, VAR_MAIN_H,
  VAR_h, VAR_H, VAR_MAIN_W, VAR_w,
  VAR_W, VAR_MAX_GLYPH_A, VAR_ASCENT, VAR_MAX_GLYPH_D,
  VAR_DESCENT, VAR_MAX_GLYPH_H, VAR_MAX_GLYPH_W, VAR_N,
  VAR_SAR, VAR_T, VAR_TEXT_H, VAR_TH,
  VAR_TEXT_W, VAR_TW, VAR_X, VAR_Y,
  VAR_PICT_TYPE, VAR_VARS_NB, VAR_N, VAR_PTS,
  VAR_R, VAR_T, VAR_TB, VAR_NB,
  VAR_W, VAR_H, VAR_VAL, VAR_MAXVAL,
  VAR_MINVAL, VAR_NEGVAL, VAR_CLIPVAL, VAR_VARS_NB,
  VAR_MAIN_W, VAR_MW, VAR_MAIN_H, VAR_MH,
  VAR_OVERLAY_W, VAR_OW, VAR_OVERLAY_H, VAR_OH,
  VAR_HSUB, VAR_VSUB, VAR_X, VAR_Y,
  VAR_N, VAR_POS, VAR_T, VAR_VARS_NB,
  VAR_IN_W, VAR_IW, VAR_IN_H, VAR_IH,
  VAR_OUT_W, VAR_OW, VAR_OUT_H, VAR_OH,
  VAR_X, VAR_Y, VAR_A, VAR_SAR,
  VAR_DAR, VAR_HSUB, VAR_VSUB, VARS_NB,
  VAR_IN_W, VAR_IW, VAR_IN_H, VAR_IH,
  VAR_OUT_W, VAR_OW, VAR_OUT_H, VAR_OH,
  VAR_HSUB, VAR_VSUB, VAR_N, VAR_T,
  VAR_VARS_NB, VAR_IN_W, VAR_IW, VAR_IN_H,
  VAR_IH, VAR_OUT_W, VAR_OW, VAR_OUT_H,
  VAR_OH, VAR_A, VAR_SAR, VAR_DAR,
  VAR_HSUB, VAR_VSUB, VARS_NB, VAR_W,
  VAR_H, VAR_N, VAR_PTS, VAR_R,
  VAR_T, VAR_TB, VAR_NB, VAR_X,
  VAR_Y, VAR_W, VAR_H, VAR_TIME,
  VAR_SPEED, VAR_TEMPO, VAR_ORDER, VAR_PATTERN,
  VAR_ROW, VAR_VARS_NB
}
 
enum  expansion_mode { EXP_NONE, EXP_NORMAL, EXP_STRFTIME }
 

Functions

static double drand (void *opaque, double min, double max)
 
 AVFILTER_DEFINE_CLASS (drawtext)
 
static int glyph_cmp (void *key, const void *b)
 
static int load_glyph (AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code)
 Load glyphs corresponding to the UTF-32 codepoint code.
 
static int load_font_file (AVFilterContext *ctx, const char *path, int index, const char **error)
 
static int load_font (AVFilterContext *ctx)
 
static int load_textfile (AVFilterContext *ctx)
 
static av_cold int init (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int glyph_enu_free (void *opaque, void *elem)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int is_newline (uint32_t c)
 
static int config_input (AVFilterLink *inlink)
 
static int command (AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
 
static int func_pict_type (AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag)
 
static int func_pts (AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag)
 
static int func_frame_num (AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag)
 
static int func_metadata (AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag)
 
static void localtime_r (const time_t *t, struct tm *tm)
 
static int func_strftime (AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag)
 
static int func_eval_expr (AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv, int tag)
 
static int eval_function (AVFilterContext *ctx, AVBPrint *bp, char *fct, unsigned argc, char **argv)
 
static int expand_function (AVFilterContext *ctx, AVBPrint *bp, char **rtext)
 
static int expand_text (AVFilterContext *ctx)
 
static int draw_glyphs (DrawTextContext *s, AVFrame *frame, int width, int height, const uint8_t rgbcolor[4], FFDrawColor *color, int x, int y)
 
static int draw_text (AVFilterContext *ctx, AVFrame *frame, int width, int height)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *frame)
 

Variables

static const char *const var_names []
 
static const char *const fun2_names []
 
static const eval_func2 fun2 []
 
static const AVOption drawtext_options []
 
struct ft_error ft_errors []
 
static struct drawtext_function functions []
 
static const AVFilterPad avfilter_vf_drawtext_inputs []
 
static const AVFilterPad avfilter_vf_drawtext_outputs []
 
AVFilter avfilter_vf_drawtext
 

Detailed Description

drawtext filter, based on the original vhook/drawtext.c filter by Gustavo Sverzut Barbieri

Definition in file vf_drawtext.c.

Macro Definition Documentation

#define OFFSET (   x)    offsetof(DrawTextContext, x)

Definition at line 172 of file vf_drawtext.c.

Definition at line 173 of file vf_drawtext.c.

#define FT_ERROR_START_LIST   {

Definition at line 231 of file vf_drawtext.c.

#define FT_ERRORDEF (   e,
  v,
  s 
)    { (e), (s) },

Definition at line 232 of file vf_drawtext.c.

#define FT_ERROR_END_LIST   { 0, NULL } };

Definition at line 233 of file vf_drawtext.c.

#define FT_ERRMSG (   e)    ft_errors[e].err_msg

Referenced by init(), and load_font_file().

Typedef Documentation

typedef double(* eval_func2)(void *, double a, double b)

Definition at line 87 of file vf_drawtext.c.

Enumeration Type Documentation

enum var_name
Enumerator:
VAR_B1 
VAR_B2 
VAR_S1 
VAR_S2 
VAR_T1 
VAR_T2 
VAR_NB 
VAR_N 
VAR_T 
VAR_S 
VAR_VARS_NB 
VAR_TB 
VAR_PTS 
VAR_START_PTS 
VAR_PREV_PTS 
VAR_PREV_SELECTED_PTS 
VAR_T 
VAR_START_T 
VAR_PREV_T 
VAR_PREV_SELECTED_T 
VAR_PICT_TYPE 
VAR_I 
VAR_P 
VAR_B 
VAR_S 
VAR_SI 
VAR_SP 
VAR_BI 
VAR_PICT_TYPE_I 
VAR_PICT_TYPE_P 
VAR_PICT_TYPE_B 
VAR_PICT_TYPE_S 
VAR_PICT_TYPE_SI 
VAR_PICT_TYPE_SP 
VAR_PICT_TYPE_BI 
VAR_INTERLACE_TYPE 
VAR_INTERLACE_TYPE_P 
VAR_INTERLACE_TYPE_T 
VAR_INTERLACE_TYPE_B 
VAR_CONSUMED_SAMPLES_N 
VAR_SAMPLES_N 
VAR_SAMPLE_RATE 
VAR_N 
VAR_SELECTED_N 
VAR_PREV_SELECTED_N 
VAR_KEY 
VAR_POS 
V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 
VAR_MINVAL 
VAR_NEGVAL 
VAR_CLIPVAL 
VAR_VARS_NB 
VAR_MAIN_W 
VAR_MW 
VAR_MAIN_H 
VAR_MH 
VAR_OVERLAY_W 
VAR_OW 
VAR_OVERLAY_H 
VAR_OH 
VAR_HSUB 
VAR_VSUB 
VAR_X 
VAR_Y 
VAR_N 
VAR_POS 
VAR_T 
VAR_VARS_NB 
VAR_IN_W 
VAR_IW 
VAR_IN_H 
VAR_IH 
VAR_OUT_W 
VAR_OW 
VAR_OUT_H 
VAR_OH 
VAR_X 
VAR_Y 
VAR_A 
VAR_SAR 
VAR_DAR 
VAR_HSUB 
VAR_VSUB 
VARS_NB 
VAR_IN_W 
VAR_IW 
VAR_IN_H 
VAR_IH 
VAR_OUT_W 
VAR_OW 
VAR_OUT_H 
VAR_OH 
VAR_HSUB 
VAR_VSUB 
VAR_N 
VAR_T 
VAR_VARS_NB 
VAR_IN_W 
VAR_IW 
VAR_IN_H 
VAR_IH 
VAR_OUT_W 
VAR_OW 
VAR_OUT_H 
VAR_OH 
VAR_A 
VAR_SAR 
VAR_DAR 
VAR_HSUB 
VAR_VSUB 
VARS_NB 
VAR_W 
VAR_H 
VAR_N 
VAR_PTS 
VAR_R 
VAR_T 
VAR_TB 
VAR_NB 
VAR_X 
VAR_Y 
VAR_W 
VAR_H 
VAR_TIME 
VAR_SPEED 
VAR_TEMPO 
VAR_ORDER 
VAR_PATTERN 
VAR_ROW 
VAR_VARS_NB 

Definition at line 94 of file vf_drawtext.c.

Enumerator:
EXP_NONE 
EXP_NORMAL 
EXP_STRFTIME 

Definition at line 115 of file vf_drawtext.c.

Function Documentation

static double drand ( void opaque,
double  min,
double  max 
)
static

Definition at line 82 of file vf_drawtext.c.

AVFILTER_DEFINE_CLASS ( drawtext  )
static int glyph_cmp ( void key,
const void b 
)
static

Definition at line 254 of file vf_drawtext.c.

Referenced by draw_glyphs(), draw_text(), and load_glyph().

static int load_glyph ( AVFilterContext ctx,
Glyph **  glyph_ptr,
uint32_t  code 
)
static

Load glyphs corresponding to the UTF-32 codepoint code.

Definition at line 264 of file vf_drawtext.c.

Referenced by draw_text(), and init().

static int load_font_file ( AVFilterContext ctx,
const char *  path,
int  index,
const char **  error 
)
static

Definition at line 315 of file vf_drawtext.c.

Referenced by load_font().

static int load_font ( AVFilterContext ctx)
static

Definition at line 380 of file vf_drawtext.c.

Referenced by init().

static int load_textfile ( AVFilterContext ctx)
static

Definition at line 400 of file vf_drawtext.c.

Referenced by filter_frame(), and init().

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 423 of file vf_drawtext.c.

Referenced by command().

static int query_formats ( AVFilterContext ctx)
static

Definition at line 508 of file vf_drawtext.c.

static int glyph_enu_free ( void opaque,
void elem 
)
static

Definition at line 514 of file vf_drawtext.c.

Referenced by uninit().

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 524 of file vf_drawtext.c.

Referenced by command().

static int is_newline ( uint32_t  c)
inlinestatic

Definition at line 548 of file vf_drawtext.c.

Referenced by draw_text().

static int config_input ( AVFilterLink inlink)
static

Definition at line 553 of file vf_drawtext.c.

Referenced by command().

static int command ( AVFilterContext ctx,
const char *  cmd,
const char *  arg,
char *  res,
int  res_len,
int  flags 
)
static
static int func_pict_type ( AVFilterContext ctx,
AVBPrint bp,
char *  fct,
unsigned  argc,
char **  argv,
int  tag 
)
static

Definition at line 617 of file vf_drawtext.c.

static int func_pts ( AVFilterContext ctx,
AVBPrint bp,
char *  fct,
unsigned  argc,
char **  argv,
int  tag 
)
static

Definition at line 626 of file vf_drawtext.c.

static int func_frame_num ( AVFilterContext ctx,
AVBPrint bp,
char *  fct,
unsigned  argc,
char **  argv,
int  tag 
)
static

Definition at line 635 of file vf_drawtext.c.

static int func_metadata ( AVFilterContext ctx,
AVBPrint bp,
char *  fct,
unsigned  argc,
char **  argv,
int  tag 
)
static

Definition at line 644 of file vf_drawtext.c.

static void localtime_r ( const time_t *  t,
struct tm *  tm 
)
static

Definition at line 656 of file vf_drawtext.c.

Referenced by draw_text(), func_strftime(), and insert_datetime().

static int func_strftime ( AVFilterContext ctx,
AVBPrint bp,
char *  fct,
unsigned  argc,
char **  argv,
int  tag 
)
static

Definition at line 662 of file vf_drawtext.c.

static int func_eval_expr ( AVFilterContext ctx,
AVBPrint bp,
char *  fct,
unsigned  argc,
char **  argv,
int  tag 
)
static

Definition at line 678 of file vf_drawtext.c.

static int eval_function ( AVFilterContext ctx,
AVBPrint bp,
char *  fct,
unsigned  argc,
char **  argv 
)
static

Definition at line 715 of file vf_drawtext.c.

Referenced by expand_function().

static int expand_function ( AVFilterContext ctx,
AVBPrint bp,
char **  rtext 
)
static

Definition at line 742 of file vf_drawtext.c.

Referenced by expand_text().

static int expand_text ( AVFilterContext ctx)
static

Definition at line 782 of file vf_drawtext.c.

Referenced by draw_text().

static int draw_glyphs ( DrawTextContext s,
AVFrame frame,
int  width,
int  height,
const uint8_t  rgbcolor[4],
FFDrawColor color,
int  x,
int  y 
)
static

Definition at line 808 of file vf_drawtext.c.

Referenced by draw_text().

static int draw_text ( AVFilterContext ctx,
AVFrame frame,
int  width,
int  height 
)
static

Definition at line 846 of file vf_drawtext.c.

Referenced by filter_frame().

static int filter_frame ( AVFilterLink inlink,
AVFrame frame 
)
static

Definition at line 1011 of file vf_drawtext.c.

Variable Documentation

const char* const var_names[]
static
Initial value:
= {
"dar",
"hsub", "vsub",
"line_h", "lh",
"main_h", "h", "H",
"main_w", "w", "W",
"max_glyph_a", "ascent",
"max_glyph_d", "descent",
"max_glyph_h",
"max_glyph_w",
"n",
"sar",
"t",
"text_h", "th",
"text_w", "tw",
"x",
"y",
"pict_type",
NULL
}

Definition at line 57 of file vf_drawtext.c.

Referenced by config_input(), and func_eval_expr().

const char* const fun2_names[]
static
Initial value:
= {
"rand"
}

Definition at line 78 of file vf_drawtext.c.

Referenced by config_input(), and func_eval_expr().

const eval_func2 fun2[]
static
Initial value:
= {
NULL
}

Definition at line 89 of file vf_drawtext.c.

Referenced by config_input(), and func_eval_expr().

const AVOption drawtext_options[]
static

Definition at line 175 of file vf_drawtext.c.

struct ft_error ft_errors[]
Initial value:
=
#define FT_ERRMSG(e)
typedef struct {
FT_Glyph *glyph;
uint32_t code;
FT_Bitmap bitmap;
FT_BBox bbox;
int advance;
int bitmap_left;
int bitmap_top;
} Glyph
struct drawtext_function functions[]
static
Initial value:
= {
{ "expr", 1, 1, 0, func_eval_expr },
{ "e", 1, 1, 0, func_eval_expr },
{ "pict_type", 0, 0, 0, func_pict_type },
{ "pts", 0, 0, 0, func_pts },
{ "gmtime", 0, 1, 'G', func_strftime },
{ "localtime", 0, 1, 'L', func_strftime },
{ "frame_num", 0, 0, 0, func_frame_num },
{ "n", 0, 0, 0, func_frame_num },
{ "metadata", 1, 1, 0, func_metadata },
}

Referenced by eval_function().

const AVFilterPad avfilter_vf_drawtext_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
.needs_writable = 1,
},
{ NULL }
}

Definition at line 1039 of file vf_drawtext.c.

const AVFilterPad avfilter_vf_drawtext_outputs[]
static
Initial value:
= {
{
.name = "default",
},
{ NULL }
}

Definition at line 1050 of file vf_drawtext.c.

AVFilter avfilter_vf_drawtext
Initial value:
= {
.name = "drawtext",
.description = NULL_IF_CONFIG_SMALL("Draw text on top of video frames using libfreetype library."),
.priv_size = sizeof(DrawTextContext),
.priv_class = &drawtext_class,
.init = init,
}

Definition at line 1058 of file vf_drawtext.c.