FFmpeg
Data Structures | Macros | Functions | Variables
movtextenc.c File Reference
#include <stdarg.h>
#include "avcodec.h"
#include "libavutil/opt.h"
#include "libavutil/avstring.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/common.h"
#include "ass_split.h"
#include "ass.h"
#include "bytestream.h"
#include "codec_internal.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) | (((uint32_t)(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)
 
static void encode_hlit (MovTextContext *s)
 
static void encode_hclr (MovTextContext *s)
 
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 unsigned 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 []
 
const static 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
 
const FFCodec ff_movtext_encoder
 

Macro Definition Documentation

◆ STYLE_FLAG_BOLD

#define STYLE_FLAG_BOLD   (1<<0)

Definition at line 34 of file movtextenc.c.

◆ STYLE_FLAG_ITALIC

#define STYLE_FLAG_ITALIC   (1<<1)

Definition at line 35 of file movtextenc.c.

◆ STYLE_FLAG_UNDERLINE

#define STYLE_FLAG_UNDERLINE   (1<<2)

Definition at line 36 of file movtextenc.c.

◆ STYLE_RECORD_SIZE

#define STYLE_RECORD_SIZE   12

Definition at line 37 of file movtextenc.c.

◆ SIZE_ADD

#define SIZE_ADD   10

Definition at line 38 of file movtextenc.c.

◆ STYL_BOX

#define STYL_BOX   (1<<0)

Definition at line 40 of file movtextenc.c.

◆ HLIT_BOX

#define HLIT_BOX   (1<<1)

Definition at line 41 of file movtextenc.c.

◆ HCLR_BOX

#define HCLR_BOX   (1<<2)

Definition at line 42 of file movtextenc.c.

◆ DEFAULT_STYLE_FONT_ID

#define DEFAULT_STYLE_FONT_ID   0x01

Definition at line 44 of file movtextenc.c.

◆ DEFAULT_STYLE_FONTSIZE

#define DEFAULT_STYLE_FONTSIZE   0x12

Definition at line 45 of file movtextenc.c.

◆ DEFAULT_STYLE_COLOR

#define DEFAULT_STYLE_COLOR   0xffffffff

Definition at line 46 of file movtextenc.c.

◆ DEFAULT_STYLE_FLAG

#define DEFAULT_STYLE_FLAG   0x00

Definition at line 47 of file movtextenc.c.

◆ BGR_TO_RGB

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

Definition at line 49 of file movtextenc.c.

◆ FONTSIZE_SCALE

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

Definition at line 50 of file movtextenc.c.

◆ av_bprint_append_any

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

Definition at line 51 of file movtextenc.c.

◆ OFFSET

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

Definition at line 688 of file movtextenc.c.

◆ FLAGS

Definition at line 689 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)
static

Definition at line 103 of file movtextenc.c.

◆ encode_hlit()

static void encode_hlit ( MovTextContext s)
static

Definition at line 131 of file movtextenc.c.

◆ encode_hclr()

static void encode_hclr ( MovTextContext s)
static

Definition at line 145 of file movtextenc.c.

◆ mov_text_encode_close()

static int mov_text_encode_close ( AVCodecContext avctx)
static

Definition at line 166 of file movtextenc.c.

◆ encode_sample_description()

static int encode_sample_description ( AVCodecContext avctx)
static

Definition at line 177 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 324 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 378 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 396 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 406 of file movtextenc.c.

◆ mov_text_color_set()

static void mov_text_color_set ( MovTextContext s,
uint32_t  color 
)
static

Definition at line 423 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 434 of file movtextenc.c.

◆ mov_text_alpha_set()

static void mov_text_alpha_set ( MovTextContext s,
uint8_t  alpha 
)
static

Definition at line 461 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 472 of file movtextenc.c.

◆ find_font_id()

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

Definition at line 495 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 507 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 518 of file movtextenc.c.

◆ mov_text_font_size_set()

static void mov_text_font_size_set ( MovTextContext s,
int  size 
)
static

Definition at line 523 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 534 of file movtextenc.c.

◆ mov_text_end_cb()

static void mov_text_end_cb ( void *  priv)
static

Definition at line 539 of file movtextenc.c.

◆ mov_text_ass_style_set()

static void mov_text_ass_style_set ( MovTextContext s,
ASSStyle style 
)
static

Definition at line 545 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 567 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 575 of file movtextenc.c.

◆ utf8_strlen()

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

Definition at line 588 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 608 of file movtextenc.c.

◆ mov_text_new_line_cb()

static void mov_text_new_line_cb ( void *  priv,
int  forced 
)
static

Definition at line 617 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 636 of file movtextenc.c.

Variable Documentation

◆ box_types

const Box box_types[]
static
Initial value:
= {
}

Definition at line 158 of file movtextenc.c.

Referenced by mov_text_encode_frame().

◆ box_count

const static size_t box_count = FF_ARRAY_ELEMS(box_types)
static

Definition at line 164 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,
}

Definition at line 624 of file movtextenc.c.

Referenced by mov_text_encode_frame().

◆ 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 },
}

Definition at line 690 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,
}

Definition at line 695 of file movtextenc.c.

◆ ff_movtext_encoder

const FFCodec ff_movtext_encoder
Initial value:
= {
.p.name = "mov_text",
CODEC_LONG_NAME("3GPP Timed Text subtitle"),
.priv_data_size = sizeof(MovTextContext),
.p.priv_class = &mov_text_encoder_class,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 702 of file movtextenc.c.

AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
mov_text_cancel_overrides_cb
static void mov_text_cancel_overrides_cb(void *priv, const char *style_name)
Definition: movtextenc.c:575
options
static const AVOption options[]
Definition: movtextenc.c:690
mov_text_encode_init
static av_cold int mov_text_encode_init(AVCodecContext *avctx)
Definition: movtextenc.c:324
OFFSET
#define OFFSET(x)
Definition: movtextenc.c:688
mov_text_encoder_class
static const AVClass mov_text_encoder_class
Definition: movtextenc.c:695
mov_text_color_cb
static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color_id)
Definition: movtextenc.c:434
mov_text_text_cb
static void mov_text_text_cb(void *priv, const char *text, int len)
Definition: movtextenc.c:608
FLAGS
#define FLAGS
Definition: movtextenc.c:689
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
AV_CODEC_ID_MOV_TEXT
@ AV_CODEC_ID_MOV_TEXT
Definition: codec_id.h:549
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
FF_CODEC_ENCODE_SUB_CB
#define FF_CODEC_ENCODE_SUB_CB(func)
Definition: codec_internal.h:318
encode_styl
static void encode_styl(MovTextContext *s)
Definition: movtextenc.c:103
mov_text_encode_close
static int mov_text_encode_close(AVCodecContext *avctx)
Definition: movtextenc.c:166
mov_text_font_name_cb
static void mov_text_font_name_cb(void *priv, const char *name)
Definition: movtextenc.c:518
mov_text_encode_frame
static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
Definition: movtextenc.c:636
encode_hlit
static void encode_hlit(MovTextContext *s)
Definition: movtextenc.c:131
mov_text_new_line_cb
static void mov_text_new_line_cb(void *priv, int forced)
Definition: movtextenc.c:617
mov_text_end_cb
static void mov_text_end_cb(void *priv)
Definition: movtextenc.c:539
encode_hclr
static void encode_hclr(MovTextContext *s)
Definition: movtextenc.c:145
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
mov_text_font_size_cb
static void mov_text_font_size_cb(void *priv, int size)
Definition: movtextenc.c:534
mov_text_style_cb
static void mov_text_style_cb(void *priv, const char style, int close)
Definition: movtextenc.c:406
mov_text_alpha_cb
static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id)
Definition: movtextenc.c:472
MovTextContext
Definition: movtextdec.c:95