FFmpeg  4.3
Data Structures | Macros | Functions | Variables
movtextenc.c File Reference
#include <stdarg.h>
#include "avcodec.h"
#include "libavutil/opt.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/common.h"
#include "ass_split.h"
#include "ass.h"

Go to the source code of this file.

Data Structures

struct  StyleBox
 
struct  HighlightBox
 
struct  HilightcolorBox
 
struct  MovTextContext
 
struct  Box
 

Macros

#define STYLE_FLAG_BOLD   (1<<0)
 
#define STYLE_FLAG_ITALIC   (1<<1)
 
#define STYLE_FLAG_UNDERLINE   (1<<2)
 
#define STYLE_RECORD_SIZE   12
 
#define SIZE_ADD   10
 
#define STYL_BOX   (1<<0)
 
#define HLIT_BOX   (1<<1)
 
#define HCLR_BOX   (1<<2)
 
#define DEFAULT_STYLE_FONT_ID   0x01
 
#define DEFAULT_STYLE_FONTSIZE   0x12
 
#define DEFAULT_STYLE_COLOR   0xffffffff
 
#define DEFAULT_STYLE_FLAG   0x00
 
#define BGR_TO_RGB(c)   (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff))
 
#define FONTSIZE_SCALE(s, fs)   ((fs) * (s)->font_scale_factor + 0.5)
 
#define av_bprint_append_any(buf, data, size)   av_bprint_append_data(buf, ((const char*)data), size)
 
#define OFFSET(x)   offsetof(MovTextContext, x)
 
#define FLAGS   AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
 

Functions

static void mov_text_cleanup (MovTextContext *s)
 
static void encode_styl (MovTextContext *s, uint32_t tsmb_type)
 
static void encode_hlit (MovTextContext *s, uint32_t tsmb_type)
 
static void encode_hclr (MovTextContext *s, uint32_t tsmb_type)
 
static int mov_text_encode_close (AVCodecContext *avctx)
 
static int encode_sample_description (AVCodecContext *avctx)
 
static av_cold int mov_text_encode_init (AVCodecContext *avctx)
 
static int mov_text_style_start (MovTextContext *s)
 
static uint8_t mov_text_style_to_flag (const char style)
 
static void mov_text_style_set (MovTextContext *s, uint8_t style_flags)
 
static void mov_text_style_cb (void *priv, const char style, int close)
 
static void mov_text_color_set (MovTextContext *s, uint32_t color)
 
static void mov_text_color_cb (void *priv, unsigned int color, unsigned int color_id)
 
static void mov_text_alpha_set (MovTextContext *s, uint8_t alpha)
 
static void mov_text_alpha_cb (void *priv, int alpha, int alpha_id)
 
static uint16_t find_font_id (MovTextContext *s, const char *name)
 
static void mov_text_font_name_set (MovTextContext *s, const char *name)
 
static void mov_text_font_name_cb (void *priv, const char *name)
 
static void mov_text_font_size_set (MovTextContext *s, int size)
 
static void mov_text_font_size_cb (void *priv, int size)
 
static void mov_text_end_cb (void *priv)
 
static void mov_text_ass_style_set (MovTextContext *s, ASSStyle *style)
 
static void mov_text_dialog (MovTextContext *s, ASSDialog *dialog)
 
static void mov_text_cancel_overrides_cb (void *priv, const char *style_name)
 
static uint16_t utf8_strlen (const char *text, int len)
 
static void mov_text_text_cb (void *priv, const char *text, int len)
 
static void mov_text_new_line_cb (void *priv, int forced)
 
static int mov_text_encode_frame (AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
 

Variables

static const Box box_types []
 
static const size_t box_count = FF_ARRAY_ELEMS(box_types)
 
static const ASSCodesCallbacks mov_text_callbacks
 
static const AVOption options []
 
static const AVClass mov_text_encoder_class
 
AVCodec ff_movtext_encoder
 

Macro Definition Documentation

◆ STYLE_FLAG_BOLD

#define STYLE_FLAG_BOLD   (1<<0)

◆ STYLE_FLAG_ITALIC

#define STYLE_FLAG_ITALIC   (1<<1)

◆ STYLE_FLAG_UNDERLINE

#define STYLE_FLAG_UNDERLINE   (1<<2)

◆ STYLE_RECORD_SIZE

#define STYLE_RECORD_SIZE   12

Definition at line 36 of file movtextenc.c.

Referenced by encode_styl().

◆ SIZE_ADD

#define SIZE_ADD   10

Definition at line 37 of file movtextenc.c.

Referenced by encode_sample_description(), and encode_styl().

◆ STYL_BOX

#define STYL_BOX   (1<<0)

Definition at line 39 of file movtextenc.c.

Referenced by encode_styl(), mov_text_cleanup(), and mov_text_style_start().

◆ HLIT_BOX

#define HLIT_BOX   (1<<1)

Definition at line 40 of file movtextenc.c.

Referenced by encode_hlit(), mov_text_alpha_cb(), and mov_text_color_cb().

◆ HCLR_BOX

#define HCLR_BOX   (1<<2)

Definition at line 41 of file movtextenc.c.

Referenced by encode_hclr(), mov_text_alpha_cb(), and mov_text_color_cb().

◆ DEFAULT_STYLE_FONT_ID

#define DEFAULT_STYLE_FONT_ID   0x01

Definition at line 43 of file movtextenc.c.

Referenced by encode_sample_description().

◆ DEFAULT_STYLE_FONTSIZE

#define DEFAULT_STYLE_FONTSIZE   0x12

Definition at line 44 of file movtextenc.c.

Referenced by encode_sample_description().

◆ DEFAULT_STYLE_COLOR

#define DEFAULT_STYLE_COLOR   0xffffffff

Definition at line 45 of file movtextenc.c.

Referenced by encode_sample_description().

◆ DEFAULT_STYLE_FLAG

#define DEFAULT_STYLE_FLAG   0x00

Definition at line 46 of file movtextenc.c.

Referenced by encode_sample_description().

◆ BGR_TO_RGB

#define BGR_TO_RGB (   c)    (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff))

◆ FONTSIZE_SCALE

#define FONTSIZE_SCALE (   s,
  fs 
)    ((fs) * (s)->font_scale_factor + 0.5)

Definition at line 49 of file movtextenc.c.

Referenced by encode_sample_description(), and mov_text_font_size_set().

◆ av_bprint_append_any

#define av_bprint_append_any (   buf,
  data,
  size 
)    av_bprint_append_data(buf, ((const char*)data), size)

Definition at line 50 of file movtextenc.c.

Referenced by encode_hclr(), encode_hlit(), encode_sample_description(), and encode_styl().

◆ OFFSET

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

Definition at line 751 of file movtextenc.c.

◆ FLAGS

Definition at line 752 of file movtextenc.c.

Function Documentation

◆ mov_text_cleanup()

static void mov_text_cleanup ( MovTextContext s)
static

Definition at line 97 of file movtextenc.c.

Referenced by encode_styl(), and mov_text_style_start().

◆ encode_styl()

static void encode_styl ( MovTextContext s,
uint32_t  tsmb_type 
)
static

Definition at line 111 of file movtextenc.c.

◆ encode_hlit()

static void encode_hlit ( MovTextContext s,
uint32_t  tsmb_type 
)
static

Definition at line 145 of file movtextenc.c.

◆ encode_hclr()

static void encode_hclr ( MovTextContext s,
uint32_t  tsmb_type 
)
static

Definition at line 161 of file movtextenc.c.

◆ mov_text_encode_close()

static int mov_text_encode_close ( AVCodecContext avctx)
static

Definition at line 182 of file movtextenc.c.

Referenced by mov_text_encode_init().

◆ encode_sample_description()

static int encode_sample_description ( AVCodecContext avctx)
static

Definition at line 200 of file movtextenc.c.

Referenced by mov_text_encode_init().

◆ mov_text_encode_init()

static av_cold int mov_text_encode_init ( AVCodecContext avctx)
static

Definition at line 353 of file movtextenc.c.

◆ mov_text_style_start()

static int mov_text_style_start ( MovTextContext s)
static

◆ mov_text_style_to_flag()

static uint8_t mov_text_style_to_flag ( const char  style)
static

Definition at line 415 of file movtextenc.c.

Referenced by mov_text_style_cb().

◆ mov_text_style_set()

static void mov_text_style_set ( MovTextContext s,
uint8_t  style_flags 
)
static

Definition at line 433 of file movtextenc.c.

Referenced by mov_text_ass_style_set().

◆ mov_text_style_cb()

static void mov_text_style_cb ( void priv,
const char  style,
int  close 
)
static

Definition at line 444 of file movtextenc.c.

◆ mov_text_color_set()

static void mov_text_color_set ( MovTextContext s,
uint32_t  color 
)
static

Definition at line 462 of file movtextenc.c.

Referenced by mov_text_ass_style_set(), and mov_text_color_cb().

◆ mov_text_color_cb()

static void mov_text_color_cb ( void priv,
unsigned int  color,
unsigned int  color_id 
)
static

Definition at line 474 of file movtextenc.c.

◆ mov_text_alpha_set()

static void mov_text_alpha_set ( MovTextContext s,
uint8_t  alpha 
)
static

Definition at line 501 of file movtextenc.c.

Referenced by mov_text_alpha_cb(), and mov_text_ass_style_set().

◆ mov_text_alpha_cb()

static void mov_text_alpha_cb ( void priv,
int  alpha,
int  alpha_id 
)
static

Definition at line 513 of file movtextenc.c.

◆ find_font_id()

static uint16_t find_font_id ( MovTextContext s,
const char *  name 
)
static

Definition at line 536 of file movtextenc.c.

Referenced by mov_text_font_name_set().

◆ mov_text_font_name_set()

static void mov_text_font_name_set ( MovTextContext s,
const char *  name 
)
static

Definition at line 546 of file movtextenc.c.

Referenced by mov_text_ass_style_set(), and mov_text_font_name_cb().

◆ mov_text_font_name_cb()

static void mov_text_font_name_cb ( void priv,
const char *  name 
)
static

Definition at line 558 of file movtextenc.c.

◆ mov_text_font_size_set()

static void mov_text_font_size_set ( MovTextContext s,
int  size 
)
static

Definition at line 563 of file movtextenc.c.

Referenced by mov_text_ass_style_set(), and mov_text_font_size_cb().

◆ mov_text_font_size_cb()

static void mov_text_font_size_cb ( void priv,
int  size 
)
static

Definition at line 575 of file movtextenc.c.

◆ mov_text_end_cb()

static void mov_text_end_cb ( void priv)
static

Definition at line 580 of file movtextenc.c.

◆ mov_text_ass_style_set()

static void mov_text_ass_style_set ( MovTextContext s,
ASSStyle style 
)
static

Definition at line 586 of file movtextenc.c.

Referenced by mov_text_cancel_overrides_cb(), and mov_text_dialog().

◆ mov_text_dialog()

static void mov_text_dialog ( MovTextContext s,
ASSDialog dialog 
)
static

Definition at line 608 of file movtextenc.c.

Referenced by mov_text_encode_frame().

◆ mov_text_cancel_overrides_cb()

static void mov_text_cancel_overrides_cb ( void priv,
const char *  style_name 
)
static

Definition at line 616 of file movtextenc.c.

◆ utf8_strlen()

static uint16_t utf8_strlen ( const char *  text,
int  len 
)
static

Definition at line 629 of file movtextenc.c.

Referenced by mov_text_text_cb().

◆ mov_text_text_cb()

static void mov_text_text_cb ( void priv,
const char *  text,
int  len 
)
static

Definition at line 649 of file movtextenc.c.

◆ mov_text_new_line_cb()

static void mov_text_new_line_cb ( void priv,
int  forced 
)
static

Definition at line 659 of file movtextenc.c.

◆ mov_text_encode_frame()

static int mov_text_encode_frame ( AVCodecContext avctx,
unsigned char *  buf,
int  bufsize,
const AVSubtitle sub 
)
static

Definition at line 679 of file movtextenc.c.

Variable Documentation

◆ box_types

const Box box_types[]
static
Initial value:
= {
{ MKTAG('s','t','y','l'), encode_styl },
{ MKTAG('h','l','i','t'), encode_hlit },
{ MKTAG('h','c','l','r'), encode_hclr },
}
static void encode_hclr(MovTextContext *s, uint32_t tsmb_type)
Definition: movtextenc.c:161
static void encode_hlit(MovTextContext *s, uint32_t tsmb_type)
Definition: movtextenc.c:145
#define MKTAG(a, b, c, d)
Definition: common.h:406
static void encode_styl(MovTextContext *s, uint32_t tsmb_type)
Definition: movtextenc.c:111

Definition at line 174 of file movtextenc.c.

◆ box_count

const size_t box_count = FF_ARRAY_ELEMS(box_types)
static

Definition at line 180 of file movtextenc.c.

Referenced by mov_text_encode_frame().

◆ mov_text_callbacks

const ASSCodesCallbacks mov_text_callbacks
static
Initial value:
= {
.new_line = mov_text_new_line_cb,
.font_name = mov_text_font_name_cb,
.font_size = mov_text_font_size_cb,
.cancel_overrides = mov_text_cancel_overrides_cb,
}
static void mov_text_cancel_overrides_cb(void *priv, const char *style_name)
Definition: movtextenc.c:616
static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color_id)
Definition: movtextenc.c:474
static void mov_text_text_cb(void *priv, const char *text, int len)
Definition: movtextenc.c:649
static void mov_text_font_name_cb(void *priv, const char *name)
Definition: movtextenc.c:558
static void mov_text_end_cb(void *priv)
Definition: movtextenc.c:580
static void mov_text_font_size_cb(void *priv, int size)
Definition: movtextenc.c:575
static void mov_text_new_line_cb(void *priv, int forced)
Definition: movtextenc.c:659
static void mov_text_style_cb(void *priv, const char style, int close)
Definition: movtextenc.c:444
static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id)
Definition: movtextenc.c:513

Definition at line 667 of file movtextenc.c.

◆ options

const AVOption options[]
static
Initial value:
= {
{ "height", "Frame height, usually video height", OFFSET(frame_height), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
{ NULL },
}
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: movtextenc.c:751
#define FLAGS
Definition: movtextenc.c:752

Definition at line 753 of file movtextenc.c.

◆ mov_text_encoder_class

const AVClass mov_text_encoder_class
static
Initial value:
= {
.class_name = "MOV text enoder",
.item_name = av_default_item_name,
.option = options,
}
static const AVOption options[]
Definition: movtextenc.c:753
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235

Definition at line 758 of file movtextenc.c.

◆ ff_movtext_encoder

AVCodec ff_movtext_encoder
Initial value:
= {
.name = "mov_text",
.long_name = NULL_IF_CONFIG_SMALL("3GPP Timed Text subtitle"),
.priv_data_size = sizeof(MovTextContext),
.priv_class = &mov_text_encoder_class,
.encode_sub = mov_text_encode_frame,
}
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static av_cold int mov_text_encode_init(AVCodecContext *avctx)
Definition: movtextenc.c:353
static const AVClass mov_text_encoder_class
Definition: movtextenc.c:758
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
Definition: movtextenc.c:679
static int mov_text_encode_close(AVCodecContext *avctx)
Definition: movtextenc.c:182

Definition at line 765 of file movtextenc.c.