libavfilter/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 "libavutil/colorspace.h"
#include "libavutil/file.h"
#include "libavutil/eval.h"
#include "libavutil/opt.h"
#include "libavutil/random_seed.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/tree.h"
#include "libavutil/lfg.h"
#include "avfilter.h"
#include "drawutils.h"
#include <ft2build.h>
#include <freetype/config/ftheader.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

Defines

#define OFFSET(x)   offsetof(DrawTextContext, x)
#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
#define GET_BITMAP_VAL(r, c)
#define SET_PIXEL_YUV(picref, yuva_color, val, x, y, hsub, vsub)
#define SET_PIXEL_RGB(picref, rgba_color, val, x, y, pixel_step, r_off, g_off, b_off, a_off)

Typedefs

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

Enumerations

enum  var_name {
  VAR_N, VAR_T, VAR_S, 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_MAIN_W, VAR_w,
  VAR_W, VAR_MAIN_H, VAR_h, VAR_H,
  VAR_TW, VAR_TEXT_W, VAR_TH, VAR_TEXT_H,
  VAR_MAX_GLYPH_W, VAR_MAX_GLYPH_H, VAR_MAX_GLYPH_A, VAR_ASCENT,
  VAR_MAX_GLYPH_D, VAR_DESCENT, VAR_LINE_H, VAR_LH,
  VAR_SAR, VAR_DAR, VAR_HSUB, VAR_VSUB,
  VAR_X, VAR_Y, VAR_N, VAR_T,
  VAR_VARS_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_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_A, VAR_SAR,
  VAR_DAR, VAR_HSUB, VAR_VSUB, 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_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_N, VAR_SELECTED_N, VAR_PREV_SELECTED_N,
  VAR_KEY, VAR_POS, VAR_VARS_NB, VAR_INTERLACED,
  VAR_N, VAR_POS, VAR_PREV_INPTS, VAR_PREV_OUTPTS,
  VAR_PTS, VAR_STARTPTS, VAR_TB, VAR_VARS_NB,
  VAR_AVTB, VAR_INTB, VAR_VARS_NB, VAR_X,
  VAR_Y, VAR_W, VAR_H, VAR_TIME,
  VAR_SPEED, VAR_TEMPO, VAR_ORDER, VAR_PATTERN,
  VAR_ROW, VAR_VARS_NB
}

Functions

static double drand (void *opaque, double min, double max)
static const char * drawtext_get_name (void *ctx)
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 av_cold int init (AVFilterContext *ctx, const char *args, void *opaque)
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 draw_glyph_yuv (AVFilterBufferRef *picref, FT_Bitmap *bitmap, int x, int y, int width, int height, const uint8_t yuva_color[4], int hsub, int vsub)
static int draw_glyph_rgb (AVFilterBufferRef *picref, FT_Bitmap *bitmap, int x, int y, int width, int height, int pixel_step, const uint8_t rgba_color[4], const uint8_t rgba_map[4])
static void drawbox (AVFilterBufferRef *picref, int x, int y, int width, int height, uint8_t *line[4], int pixel_step[4], uint8_t color[4], int hsub, int vsub, int is_rgba_packed, uint8_t rgba_map[4])
static int draw_glyphs (DrawTextContext *dtext, AVFilterBufferRef *picref, int width, int height, const uint8_t rgbcolor[4], const uint8_t yuvcolor[4], int x, int y)
static int draw_text (AVFilterContext *ctx, AVFilterBufferRef *picref, int width, int height)
static void null_draw_slice (AVFilterLink *link, int y, int h, int slice_dir)
static void end_frame (AVFilterLink *inlink)

Variables

static const char *const var_names []
static const char * fun2_names []
static const eval_func2 fun2 []
static const AVOption drawtext_options []
static const AVClass drawtext_class
struct ft_error ft_errors []
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.


Define Documentation

#define FT_ERRMSG (  )     ft_errors[e].err_msg

Referenced by init().

#define FT_ERROR_END_LIST   { 0, NULL } };

Definition at line 212 of file vf_drawtext.c.

#define FT_ERROR_START_LIST   {

Definition at line 210 of file vf_drawtext.c.

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

Definition at line 211 of file vf_drawtext.c.

#define GET_BITMAP_VAL ( r,
c   ) 

Value:

bitmap->pixel_mode == FT_PIXEL_MODE_MONO ?                          \
        (bitmap->buffer[(r) * bitmap->pitch + ((c)>>3)] & (0x80 >> ((c)&7))) * 255 : \
         bitmap->buffer[(r) * bitmap->pitch +  (c)]

Definition at line 525 of file vf_drawtext.c.

Referenced by draw_glyph_rgb(), and draw_glyph_yuv().

#define OFFSET (  )     offsetof(DrawTextContext, x)

Definition at line 159 of file vf_drawtext.c.

#define SET_PIXEL_RGB ( picref,
rgba_color,
val,
x,
y,
pixel_step,
r_off,
g_off,
b_off,
a_off   ) 

Value:

{ \
    p   = picref->data[0] + (x) * pixel_step + ((y) * picref->linesize[0]); \
    alpha = rgba_color[3] * (val) * 129;                              \
    *(p+r_off) = (alpha * rgba_color[0] + (255*255*129 - alpha) * *(p+r_off)) >> 23; \
    *(p+g_off) = (alpha * rgba_color[1] + (255*255*129 - alpha) * *(p+g_off)) >> 23; \
    *(p+b_off) = (alpha * rgba_color[2] + (255*255*129 - alpha) * *(p+b_off)) >> 23; \
}

Definition at line 567 of file vf_drawtext.c.

#define SET_PIXEL_YUV ( picref,
yuva_color,
val,
x,
y,
hsub,
vsub   ) 

Value:

{           \
    luma_pos    = ((x)          ) + ((y)          ) * picref->linesize[0]; \
    alpha = yuva_color[3] * (val) * 129;                               \
    picref->data[0][luma_pos]    = (alpha * yuva_color[0] + (255*255*129 - alpha) * picref->data[0][luma_pos]   ) >> 23; \
    if (((x) & ((1<<(hsub)) - 1)) == 0 && ((y) & ((1<<(vsub)) - 1)) == 0) {\
        chroma_pos1 = ((x) >> (hsub)) + ((y) >> (vsub)) * picref->linesize[1]; \
        chroma_pos2 = ((x) >> (hsub)) + ((y) >> (vsub)) * picref->linesize[2]; \
        picref->data[1][chroma_pos1] = (alpha * yuva_color[1] + (255*255*129 - alpha) * picref->data[1][chroma_pos1]) >> 23; \
        picref->data[2][chroma_pos2] = (alpha * yuva_color[2] + (255*255*129 - alpha) * picref->data[2][chroma_pos2]) >> 23; \
    }\
}

Definition at line 530 of file vf_drawtext.c.

Referenced by draw_glyph_yuv(), and drawbox().


Typedef Documentation

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

Definition at line 81 of file vf_drawtext.c.


Enumeration Type Documentation

enum var_name

Enumerator:
VAR_N 
VAR_T 
VAR_S 
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_MAIN_W 
VAR_w 
VAR_W 
VAR_MAIN_H 
VAR_h 
VAR_H 
VAR_TW 
VAR_TEXT_W 
VAR_TH 
VAR_TEXT_H 
VAR_MAX_GLYPH_W 
VAR_MAX_GLYPH_H 
VAR_MAX_GLYPH_A 
VAR_ASCENT 
VAR_MAX_GLYPH_D 
VAR_DESCENT 
VAR_LINE_H 
VAR_LH 
VAR_SAR 
VAR_DAR 
VAR_HSUB 
VAR_VSUB 
VAR_X 
VAR_Y 
VAR_N 
VAR_T 
VAR_VARS_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_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_A 
VAR_SAR 
VAR_DAR 
VAR_HSUB 
VAR_VSUB 
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_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_N 
VAR_SELECTED_N 
VAR_PREV_SELECTED_N 
VAR_KEY 
VAR_POS 
VAR_VARS_NB 
VAR_INTERLACED 
VAR_N 
VAR_POS 
VAR_PREV_INPTS 
VAR_PREV_OUTPTS 
VAR_PTS 
VAR_STARTPTS 
VAR_TB 
VAR_VARS_NB 
VAR_AVTB 
VAR_INTB 
VAR_VARS_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 88 of file vf_drawtext.c.


Function Documentation

static int command ( AVFilterContext ctx,
const char *  cmd,
const char *  arg,
char *  res,
int  res_len,
int  flags 
) [static]

Definition at line 509 of file vf_drawtext.c.

Referenced by cdg_decode_frame(), idcin_read_packet(), and transcode().

static int config_input ( AVFilterLink inlink  )  [static]

Definition at line 453 of file vf_drawtext.c.

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

Definition at line 76 of file vf_drawtext.c.

static int draw_glyph_rgb ( AVFilterBufferRef picref,
FT_Bitmap *  bitmap,
int  x,
int  y,
int  width,
int  height,
int  pixel_step,
const uint8_t  rgba_color[4],
const uint8_t  rgba_map[4] 
) [inline, static]

Definition at line 575 of file vf_drawtext.c.

Referenced by draw_glyphs().

static int draw_glyph_yuv ( AVFilterBufferRef picref,
FT_Bitmap *  bitmap,
int  x,
int  y,
int  width,
int  height,
const uint8_t  yuva_color[4],
int  hsub,
int  vsub 
) [inline, static]

Definition at line 542 of file vf_drawtext.c.

Referenced by draw_glyphs().

static int draw_glyphs ( DrawTextContext dtext,
AVFilterBufferRef picref,
int  width,
int  height,
const uint8_t  rgbcolor[4],
const uint8_t  yuvcolor[4],
int  x,
int  y 
) [static]

Definition at line 627 of file vf_drawtext.c.

Referenced by draw_text().

static int draw_text ( AVFilterContext ctx,
AVFilterBufferRef picref,
int  width,
int  height 
) [static]

Definition at line 668 of file vf_drawtext.c.

Referenced by end_frame().

static void drawbox ( AVFilterBufferRef picref,
int  x,
int  y,
int  width,
int  height,
uint8_t *  line[4],
int  pixel_step[4],
uint8_t  color[4],
int  hsub,
int  vsub,
int  is_rgba_packed,
uint8_t  rgba_map[4] 
) [inline, static]

Definition at line 600 of file vf_drawtext.c.

Referenced by avfilter_register_all(), config_input(), draw_slice(), draw_text(), and init().

static const char* drawtext_get_name ( void *  ctx  )  [static]

Definition at line 198 of file vf_drawtext.c.

static void end_frame ( AVFilterLink inlink  )  [static]

Definition at line 826 of file vf_drawtext.c.

static int glyph_cmp ( void *  key,
const void *  b 
) [static]

Definition at line 233 of file vf_drawtext.c.

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

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

Definition at line 409 of file vf_drawtext.c.

Referenced by uninit().

static av_cold int init ( AVFilterContext ctx,
const char *  args,
void *  opaque 
) [static]

Definition at line 294 of file vf_drawtext.c.

static int is_newline ( uint32_t  c  )  [inline, static]

Definition at line 448 of file vf_drawtext.c.

Referenced by draw_text().

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 243 of file vf_drawtext.c.

Referenced by draw_text(), and init().

static void null_draw_slice ( AVFilterLink link,
int  y,
int  h,
int  slice_dir 
) [static]

Definition at line 824 of file vf_drawtext.c.

static int query_formats ( AVFilterContext ctx  )  [static]

Definition at line 393 of file vf_drawtext.c.

static av_cold void uninit ( AVFilterContext ctx  )  [static]

Definition at line 415 of file vf_drawtext.c.


Variable Documentation

Initial value:

 {
    .name          = "drawtext",
    .description   = NULL_IF_CONFIG_SMALL("Draw text on top of video frames using libfreetype library."),
    .priv_size     = sizeof(DrawTextContext),
    .init          = init,
    .uninit        = uninit,
    .query_formats = query_formats,

    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
                                    .type             = AVMEDIA_TYPE_VIDEO,
                                    .get_video_buffer = avfilter_null_get_video_buffer,
                                    .start_frame      = avfilter_null_start_frame,
                                    .draw_slice       = null_draw_slice,
                                    .end_frame        = end_frame,
                                    .config_props     = config_input,
                                    .min_perms        = AV_PERM_WRITE |
                                                        AV_PERM_READ,
                                    .rej_perms        = AV_PERM_PRESERVE },
                                  { .name = NULL}},
    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
                                    .type             = AVMEDIA_TYPE_VIDEO, },
                                  { .name = NULL}},
    .process_command = command,
}

Definition at line 849 of file vf_drawtext.c.

const AVClass drawtext_class [static]

Initial value:

 {
    "DrawTextContext",
    drawtext_get_name,
    drawtext_options
}

Definition at line 203 of file vf_drawtext.c.

const AVOption drawtext_options[] [static]

Definition at line 161 of file vf_drawtext.c.

struct ft_error ft_errors[]

const eval_func2 fun2[] [static]

Initial value:

 {
    drand,
    NULL
}

Definition at line 83 of file vf_drawtext.c.

Referenced by config_input().

const char* fun2_names[] [static]

Initial value:

 {
    "rand",
}

Definition at line 72 of file vf_drawtext.c.

Referenced by config_input().

const char* const var_names[] [static]

Initial value:

 {
    "main_w", "w", "W",       
    "main_h", "h", "H",       
    "tw", "text_w",           
    "th", "text_h",           
    "max_glyph_w",            
    "max_glyph_h",            
    "max_glyph_a", "ascent",  
    "max_glyph_d", "descent", 
    "line_h", "lh",           
    "sar",
    "dar",
    "hsub",
    "vsub",
    "x",
    "y",
    "n",                      
    "t",                      
    NULL
}

Definition at line 51 of file vf_drawtext.c.


Generated on Fri Oct 26 02:43:51 2012 for FFmpeg by  doxygen 1.5.8