FFmpeg
Loading...
Searching...
No Matches
vf_drawtext.c File Reference

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

#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <fenv.h>
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
#include "libavutil/common.h"
#include "libavutil/eval.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/random_seed.h"
#include "libavutil/parseutils.h"
#include "libavutil/timecode.h"
#include "libavutil/time_internal.h"
#include "libavutil/tree.h"
#include "libavutil/lfg.h"
#include "libavutil/detection_bbox.h"
#include "avfilter.h"
#include "drawutils.h"
#include "filters.h"
#include "formats.h"
#include "textutils.h"
#include "video.h"
#include <ft2build.h>
#include <FT_FREETYPE_H>
#include <FT_GLYPH_H>
#include <FT_STROKER_H>
#include <hb.h>
#include <hb-ft.h>
#include <FT_ERRORS_H>

Go to the source code of this file.

Data Structures

struct  HarfbuzzData
 
struct  GlyphInfo
 Information about a single glyph in a text line. More...
 
struct  TextLine
 Information about a single line of text. More...
 
struct  Glyph
 A glyph as loaded and rendered using libfreetype. More...
 
struct  TextMetrics
 Global text metrics. More...
 
struct  DrawTextContext
 
struct  ft_error
 

Macros

#define POS_CEIL(x, y)
 
#define OFFSET(x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define TFLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 
#define FT_ERROR_START_LIST   {
 
#define FT_ERRORDEF(e, v, s)
 
#define FT_ERROR_END_LIST   { 0, NULL } };
 
#define FT_ERRMSG(e)
 

Typedefs

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

Enumerations

enum  var_name {
  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_FONT_A , VAR_FONT_D , VAR_TOP_A ,
  VAR_BOTTOM_D , VAR_N , VAR_SAR , VAR_T ,
  VAR_TEXT_H , VAR_TH , VAR_TEXT_W , VAR_TW ,
  VAR_X , VAR_Y , VAR_PICT_TYPE , VAR_DURATION ,
  VAR_VARS_NB
}
 
enum  expansion_mode { EXP_NONE , EXP_NORMAL , EXP_STRFTIME }
 
enum  y_alignment { YA_TEXT , YA_BASELINE , YA_FONT }
 
enum  text_alignment { TA_LEFT = (1 << 0) , TA_RIGHT = (1 << 1) , TA_TOP = (1 << 2) , TA_BOTTOM = (1 << 3) }
 

Functions

static double drand (void *opaque, double min, double max)
 
 AVFILTER_DEFINE_CLASS (drawtext)
 
static av_cold int init (AVFilterContext *ctx)
 
static int query_formats (const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
 
static int glyph_enu_border_free (void *opaque, void *elem)
 
static int glyph_enu_free (void *opaque, void *elem)
 
static av_cold void uninit (AVFilterContext *ctx)
 
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 void update_color_with_alpha (DrawTextContext *s, FFDrawColor *color, const FFDrawColor incolor)
 
static void update_alpha (DrawTextContext *s)
 
static int draw_glyphs (AVFilterContext *ctx, AVFrame *frame, FFDrawColor *color, TextMetrics *metrics, int x, int y, int borderw)
 
static int shape_text_hb (AVFilterContext *ctx, DrawTextContext *s, HarfbuzzData *hb, const char *text, int textLen)
 
static void hb_destroy (HarfbuzzData *hb)
 
static int measure_text (AVFilterContext *ctx, TextMetrics *metrics)
 
static int draw_text (AVFilterContext *ctx, AVFrame *frame)
 
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 []
 
static const struct ft_error ft_errors []
 
static const AVFilterPad avfilter_vf_drawtext_inputs []
 
const FFFilter ff_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

◆ POS_CEIL

#define POS_CEIL ( x,
y )
Value:
((x)/(y) + ((x)%(y) != 0))

Definition at line 81 of file vf_drawtext.c.

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

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 320 of file vf_drawtext.c.

◆ FLAGS

Definition at line 321 of file vf_drawtext.c.

◆ TFLAGS

◆ FT_ERROR_START_LIST

#define FT_ERROR_START_LIST   {

Definition at line 410 of file vf_drawtext.c.

◆ FT_ERRORDEF

#define FT_ERRORDEF ( e,
v,
s )
Value:
{ (e), (s) },
#define s(width, name)
Definition cbs_vp9.c:198

Definition at line 411 of file vf_drawtext.c.

◆ FT_ERROR_END_LIST

#define FT_ERROR_END_LIST   { 0, NULL } };

Definition at line 412 of file vf_drawtext.c.

◆ FT_ERRMSG

#define FT_ERRMSG ( e)
Value:
ft_errors[e].err_msg
static const struct ft_error ft_errors[]

Referenced by init().

Typedef Documentation

◆ eval_func2

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

Definition at line 118 of file vf_drawtext.c.

Enumeration Type Documentation

◆ var_name

enum var_name
Enumerator
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_FONT_A 
VAR_FONT_D 
VAR_TOP_A 
VAR_BOTTOM_D 
VAR_N 
VAR_SAR 
VAR_T 
VAR_TEXT_H 
VAR_TH 
VAR_TEXT_W 
VAR_TW 
VAR_X 
VAR_Y 
VAR_PICT_TYPE 
VAR_DURATION 
VAR_VARS_NB 

Definition at line 125 of file vf_drawtext.c.

◆ expansion_mode

Enumerator
EXP_NONE 
EXP_NORMAL 
EXP_STRFTIME 

Definition at line 151 of file vf_drawtext.c.

◆ y_alignment

Enumerator
YA_TEXT 
YA_BASELINE 
YA_FONT 

Definition at line 157 of file vf_drawtext.c.

◆ text_alignment

Enumerator
TA_LEFT 
TA_RIGHT 
TA_TOP 
TA_BOTTOM 

Definition at line 163 of file vf_drawtext.c.

Function Documentation

◆ drand()

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

Definition at line 113 of file vf_drawtext.c.

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( drawtext )

◆ init()

static av_cold int init ( AVFilterContext * ctx)
static

Definition at line 969 of file vf_drawtext.c.

◆ query_formats()

static int query_formats ( const AVFilterContext * ctx,
AVFilterFormatsConfig ** cfg_in,
AVFilterFormatsConfig ** cfg_out )
static

Definition at line 1082 of file vf_drawtext.c.

◆ glyph_enu_border_free()

static int glyph_enu_border_free ( void * opaque,
void * elem )
static

Definition at line 1090 of file vf_drawtext.c.

Referenced by command().

◆ glyph_enu_free()

static int glyph_enu_free ( void * opaque,
void * elem )
static

Definition at line 1107 of file vf_drawtext.c.

Referenced by uninit().

◆ uninit()

static av_cold void uninit ( AVFilterContext * ctx)
static

Definition at line 1126 of file vf_drawtext.c.

Referenced by command().

◆ config_input()

static int config_input ( AVFilterLink * inlink)
static

Definition at line 1149 of file vf_drawtext.c.

Referenced by command().

◆ command()

◆ update_color_with_alpha()

static void update_color_with_alpha ( DrawTextContext * s,
FFDrawColor * color,
const FFDrawColor incolor )
static

Definition at line 1259 of file vf_drawtext.c.

Referenced by draw_text().

◆ update_alpha()

static void update_alpha ( DrawTextContext * s)
static

Definition at line 1266 of file vf_drawtext.c.

Referenced by draw_text().

◆ draw_glyphs()

static int draw_glyphs ( AVFilterContext * ctx,
AVFrame * frame,
FFDrawColor * color,
TextMetrics * metrics,
int x,
int y,
int borderw )
static

Definition at line 1281 of file vf_drawtext.c.

Referenced by draw_text().

◆ shape_text_hb()

static int shape_text_hb ( AVFilterContext * ctx,
DrawTextContext * s,
HarfbuzzData * hb,
const char * text,
int textLen )
static

Definition at line 1371 of file vf_drawtext.c.

Referenced by measure_text().

◆ hb_destroy()

static void hb_destroy ( HarfbuzzData * hb)
static

Definition at line 1416 of file vf_drawtext.c.

Referenced by draw_text(), and measure_text().

◆ measure_text()

static int measure_text ( AVFilterContext * ctx,
TextMetrics * metrics )
static

Definition at line 1426 of file vf_drawtext.c.

Referenced by draw_text().

◆ draw_text()

static int draw_text ( AVFilterContext * ctx,
AVFrame * frame )
static

Definition at line 1598 of file vf_drawtext.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink * inlink,
AVFrame * frame )
static

Definition at line 1879 of file vf_drawtext.c.

Variable Documentation

◆ var_names

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",
"font_a",
"font_d",
"top_a",
"bottom_d",
"n",
"sar",
"t",
"text_h", "th",
"text_w", "tw",
"x",
"y",
"pict_type",
"duration",
}
#define NULL
Definition coverity.c:32

Definition at line 83 of file vf_drawtext.c.

◆ fun2_names

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

Definition at line 109 of file vf_drawtext.c.

◆ fun2

const eval_func2 fun2[]
static
Initial value:
= {
}
static double drand(void *opaque, double min, double max)
Definition qrencode.c:185

Definition at line 120 of file vf_drawtext.c.

◆ drawtext_options

const AVOption drawtext_options[]
static

Definition at line 324 of file vf_drawtext.c.

◆ ft_errors

const struct ft_error ft_errors[]
static

◆ avfilter_vf_drawtext_inputs

const AVFilterPad avfilter_vf_drawtext_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
},
}
static int config_input(AVFilterLink *inlink)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Definition filters.h:59

Definition at line 1946 of file vf_drawtext.c.

◆ ff_vf_drawtext

const FFFilter ff_vf_drawtext
Initial value:
= {
.p.name = "drawtext",
.p.description = NULL_IF_CONFIG_SMALL("Draw text on top of video frames using libfreetype library."),
.p.priv_class = &drawtext_class,
.priv_size = sizeof(DrawTextContext),
.init = init,
.process_command = command,
}
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition avfilter.h:196
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static const AVFilterPad avfilter_vf_drawtext_inputs[]
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition video.c:37

Definition at line 1956 of file vf_drawtext.c.