FFmpeg
Data Structures | Macros | Functions | Variables
movtextenc.c File Reference
#include <stdarg.h>
#include "avcodec.h"
#include "libavutil/opt.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 33 of file movtextenc.c.

◆ STYLE_FLAG_ITALIC

#define STYLE_FLAG_ITALIC   (1<<1)

Definition at line 34 of file movtextenc.c.

◆ STYLE_FLAG_UNDERLINE

#define STYLE_FLAG_UNDERLINE   (1<<2)

Definition at line 35 of file movtextenc.c.

◆ STYLE_RECORD_SIZE

#define STYLE_RECORD_SIZE   12

Definition at line 36 of file movtextenc.c.

◆ SIZE_ADD

#define SIZE_ADD   10

Definition at line 37 of file movtextenc.c.

◆ STYL_BOX

#define STYL_BOX   (1<<0)

Definition at line 39 of file movtextenc.c.

◆ HLIT_BOX

#define HLIT_BOX   (1<<1)

Definition at line 40 of file movtextenc.c.

◆ HCLR_BOX

#define HCLR_BOX   (1<<2)

Definition at line 41 of file movtextenc.c.

◆ DEFAULT_STYLE_FONT_ID

#define DEFAULT_STYLE_FONT_ID   0x01

Definition at line 43 of file movtextenc.c.

◆ DEFAULT_STYLE_FONTSIZE

#define DEFAULT_STYLE_FONTSIZE   0x12

Definition at line 44 of file movtextenc.c.

◆ DEFAULT_STYLE_COLOR

#define DEFAULT_STYLE_COLOR   0xffffffff

Definition at line 45 of file movtextenc.c.

◆ DEFAULT_STYLE_FLAG

#define DEFAULT_STYLE_FLAG   0x00

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

◆ FONTSIZE_SCALE

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

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

◆ OFFSET

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

Definition at line 691 of file movtextenc.c.

◆ FLAGS

Definition at line 692 of file movtextenc.c.

Function Documentation

◆ mov_text_cleanup()

static void mov_text_cleanup ( MovTextContext s)
static

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

◆ encode_hlit()

static void encode_hlit ( MovTextContext s)
static

Definition at line 130 of file movtextenc.c.

◆ encode_hclr()

static void encode_hclr ( MovTextContext s)
static

Definition at line 144 of file movtextenc.c.

◆ mov_text_encode_close()

static int mov_text_encode_close ( AVCodecContext avctx)
static

Definition at line 165 of file movtextenc.c.

◆ encode_sample_description()

static int encode_sample_description ( AVCodecContext avctx)
static

Definition at line 175 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 329 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 381 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 399 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 409 of file movtextenc.c.

◆ mov_text_color_set()

static void mov_text_color_set ( MovTextContext s,
uint32_t  color 
)
static

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

◆ mov_text_alpha_set()

static void mov_text_alpha_set ( MovTextContext s,
uint8_t  alpha 
)
static

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

◆ find_font_id()

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

Definition at line 498 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 510 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 521 of file movtextenc.c.

◆ mov_text_font_size_set()

static void mov_text_font_size_set ( MovTextContext s,
int  size 
)
static

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

◆ mov_text_end_cb()

static void mov_text_end_cb ( void *  priv)
static

Definition at line 542 of file movtextenc.c.

◆ mov_text_ass_style_set()

static void mov_text_ass_style_set ( MovTextContext s,
ASSStyle style 
)
static

Definition at line 548 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 570 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 578 of file movtextenc.c.

◆ utf8_strlen()

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

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

◆ mov_text_new_line_cb()

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

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

Variable Documentation

◆ box_types

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

Definition at line 157 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 163 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 627 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 693 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 698 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 705 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:43
mov_text_cancel_overrides_cb
static void mov_text_cancel_overrides_cb(void *priv, const char *style_name)
Definition: movtextenc.c:578
options
static const AVOption options[]
Definition: movtextenc.c:693
mov_text_encode_init
static av_cold int mov_text_encode_init(AVCodecContext *avctx)
Definition: movtextenc.c:329
OFFSET
#define OFFSET(x)
Definition: movtextenc.c:691
mov_text_encoder_class
static const AVClass mov_text_encoder_class
Definition: movtextenc.c:698
mov_text_color_cb
static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color_id)
Definition: movtextenc.c:437
mov_text_text_cb
static void mov_text_text_cb(void *priv, const char *text, int len)
Definition: movtextenc.c:611
FLAGS
#define FLAGS
Definition: movtextenc.c:692
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
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:561
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:323
encode_styl
static void encode_styl(MovTextContext *s)
Definition: movtextenc.c:102
mov_text_encode_close
static int mov_text_encode_close(AVCodecContext *avctx)
Definition: movtextenc.c:165
mov_text_font_name_cb
static void mov_text_font_name_cb(void *priv, const char *name)
Definition: movtextenc.c:521
mov_text_encode_frame
static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
Definition: movtextenc.c:639
encode_hlit
static void encode_hlit(MovTextContext *s)
Definition: movtextenc.c:130
mov_text_new_line_cb
static void mov_text_new_line_cb(void *priv, int forced)
Definition: movtextenc.c:620
mov_text_end_cb
static void mov_text_end_cb(void *priv)
Definition: movtextenc.c:542
encode_hclr
static void encode_hclr(MovTextContext *s)
Definition: movtextenc.c:144
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
mov_text_font_size_cb
static void mov_text_font_size_cb(void *priv, int size)
Definition: movtextenc.c:537
mov_text_style_cb
static void mov_text_style_cb(void *priv, const char style, int close)
Definition: movtextenc.c:409
mov_text_alpha_cb
static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id)
Definition: movtextenc.c:475
MovTextContext
Definition: movtextdec.c:95