33 #define STYLE_FLAG_BOLD (1<<0) 34 #define STYLE_FLAG_ITALIC (1<<1) 35 #define STYLE_FLAG_UNDERLINE (1<<2) 36 #define STYLE_RECORD_SIZE 12 39 #define STYL_BOX (1<<0) 40 #define HLIT_BOX (1<<1) 41 #define HCLR_BOX (1<<2) 43 #define DEFAULT_STYLE_FONT_ID 0x01 44 #define DEFAULT_STYLE_FONTSIZE 0x12 45 #define DEFAULT_STYLE_COLOR 0xffffffff 46 #define DEFAULT_STYLE_FLAG 0x00 48 #define BGR_TO_RGB(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((uint32_t)(c) >> 16) & 0xff)) 49 #define FONTSIZE_SCALE(s,fs) ((fs) * (s)->font_scale_factor + 0.5) 50 #define av_bprint_append_any(buf, data, size) av_bprint_append_data(buf, ((const char*)data), size) 56 uint16_t style_fontID;
107 uint16_t style_entries;
110 tsmb_size =
AV_RB32(&tsmb_size);
111 tsmb_type =
AV_RB32(&tsmb_type);
118 for (
unsigned j = 0; j < s->
count; j++) {
119 uint16_t style_start, style_end, style_fontID;
120 uint32_t style_color;
144 tsmb_size =
AV_RB32(&tsmb_size);
145 tsmb_type =
AV_RB32(&tsmb_type);
157 uint32_t tsmb_size,
color;
160 tsmb_size =
AV_RB32(&tsmb_size);
161 tsmb_type =
AV_RB32(&tsmb_type);
193 uint32_t tsmb_size, tsmb_type, back_color = 0, style_color;
194 uint16_t style_start, style_end, fontID, count;
195 int font_names_total_len = 0;
198 static const uint8_t display_and_justification[] = {
199 0x00, 0x00, 0x00, 0x00,
204 static const uint8_t box_record[] = {
260 sizeof(display_and_justification));
261 back_color =
AV_RB32(&back_color);
267 style_start =
AV_RB16(&s->
d.style_start);
268 style_end =
AV_RB16(&s->
d.style_end);
269 fontID =
AV_RB16(&s->
d.style_fontID);
270 style_color =
AV_RB32(&s->
d.style_color);
287 font_names_total_len += strlen(style->
font_name);
310 tsmb_size =
AV_RB32(&tsmb_size);
311 tsmb_type =
MKBETAG(
'f',
't',
'a',
'b');
312 tsmb_type =
AV_RB32(&tsmb_type);
324 len = strlen(s->
fonts[i]);
470 }
else if (color_id == 2) {
508 else if (alpha_id == 2) {
528 if (!strcmp(name, s->
fonts[i]))
607 if (!style_name || !*style_name)
617 uint16_t
i = 0, ret = 0;
622 else if ((c & 0xE0) == 0xC0)
624 else if ((c & 0xF0) == 0xE0)
626 else if ((c & 0xF8) == 0xF0)
685 #if FF_API_ASS_TIMING 686 if (!strncmp(ass,
"Dialogue: ", 10)) {
689 for (; dialog && num--; dialog++) {
701 #if FF_API_ASS_TIMING 723 if (s->
buffer.len > bufsize - 3) {
730 length = s->
buffer.len + 2;
737 #define OFFSET(x) offsetof(MovTextContext, x) 738 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM 757 .priv_class = &mov_text_encoder_class,
char * style
name of the ASSStyle to use with this dialog
static const AVOption options[]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog)
fields extracted from the [Events] section
#define LIBAVUTIL_VERSION_INT
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
ASSDialog * ff_ass_split_dialog2(ASSSplitContext *ctx, const char *buf)
Split one ASS Dialogue line from a string buffer.
static const size_t box_count
ASSSplitContext * ff_ass_split(const char *buf)
Split a full ASS file or a ASS header from a string buffer and store the split structure in a newly a...
const char * av_default_item_name(void *ptr)
Return the context name.
static void mov_text_font_size_set(MovTextContext *s, int size)
structure containing the whole split ASS data
static av_cold int mov_text_encode_init(AVCodecContext *avctx)
#define DEFAULT_STYLE_FONT_ID
int back_color
color of the subtitle outline or shadow
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
static void mov_text_cancel_overrides_cb(void *priv, const char *style_name)
char * text
actual text which will be displayed as a subtitle, can include style override control codes (see ff_a...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
This struct can be casted to ASS to access to the split data.
void ff_ass_free_dialog(ASSDialog **dialogp)
Free a dialogue obtained from ff_ass_split_dialog2().
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
static void mov_text_font_name_set(MovTextContext *s, const char *name)
ASSSplitContext * ass_ctx
static av_cold int end(AVCodecContext *avctx)
int bold
whether text is bold (1) or not (0)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, const char *buf)
Split override codes out of a ASS "Dialogue" Text field.
static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color_id)
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
#define FONTSIZE_SCALE(s, fs)
static void mov_text_text_cb(void *priv, const char *text, int len)
static void mov_text_color_set(MovTextContext *s, uint32_t color)
static const AVClass mov_text_encoder_class
static int mov_text_style_start(MovTextContext *s)
void(* encode)(MovTextContext *s, uint32_t tsmb_type)
unsigned style_attributes_bytes_allocated
ASSDialog * ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf, int cache, int *number)
Split one or several ASS "Dialogue" lines from a string buffer and store them in an already initializ...
static void mov_text_alpha_set(MovTextContext *s, uint8_t alpha)
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define STYLE_FLAG_UNDERLINE
#define AV_BPRINT_SIZE_UNLIMITED
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
simple assert() macros that are a bit more flexible than ISO C assert().
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
#define DEFAULT_STYLE_COLOR
#define STYLE_FLAG_ITALIC
static const Box box_types[]
int play_res_y
video height that ASS coords are referring to
static void mov_text_cleanup(MovTextContext *s)
#define DEFAULT_STYLE_FONTSIZE
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
static uint16_t utf8_strlen(const char *text, int len)
static uint16_t find_font_id(MovTextContext *s, const char *name)
static void mov_text_font_name_cb(void *priv, const char *name)
static uint8_t mov_text_style_to_flag(const char style)
int italic
whether text is italic (1) or not (0)
static int encode_sample_description(AVCodecContext *avctx)
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Set of callback functions corresponding to each override codes that can be encountered in a "Dialogue...
AVCodec ff_movtext_encoder
static void mov_text_style_set(MovTextContext *s, uint8_t style_flags)
#define FF_ARRAY_ELEMS(a)
static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
int primary_color
color that a subtitle will normally appear in
Libavcodec external API header.
typedef void(RENAME(mix_any_func_type))
static const ASSCodesCallbacks mov_text_callbacks
static void encode_hclr(MovTextContext *s, uint32_t tsmb_type)
static const int16_t alpha[]
#define STYLE_RECORD_SIZE
main external API structure.
static int mov_text_encode_close(AVCodecContext *avctx)
static void encode(AVCodecContext *ctx, AVFrame *frame, AVPacket *pkt, FILE *output)
Describe the class of an AVClass context structure.
static void mov_text_end_cb(void *priv)
char * font_name
font face (case sensitive)
ASSScriptInfo script_info
general information about the SSA script
fields extracted from the [V4(+) Styles] section
ASSStyle * ff_ass_style_get(ASSSplitContext *ctx, const char *style)
Find an ASSStyle structure by its name.
static void mov_text_ass_style_set(MovTextContext *s, ASSStyle *style)
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
static void encode_hlit(MovTextContext *s, uint32_t tsmb_type)
common internal and external API header
static void mov_text_font_size_cb(void *priv, int size)
void(* text)(void *priv, const char *text, int len)
StyleBox * style_attributes
static void mov_text_new_line_cb(void *priv, int forced)
#define MKBETAG(a, b, c, d)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static void mov_text_style_cb(void *priv, const char style, int close)
static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id)
Formatted text, the ass field must be set by the decoder and is authoritative.
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add the pointer to an element to a dynamic array.
#define av_bprint_append_any(buf, data, size)
int styles_count
number of ASSStyle in the styles array
char * ass
0 terminated ASS/SSA compatible event line.
#define DEFAULT_STYLE_FLAG
StyleBox style_attributes_temp
void ff_ass_split_free(ASSSplitContext *ctx)
Free all the memory allocated for an ASSSplitContext.
static void encode_styl(MovTextContext *s, uint32_t tsmb_type)
ASSStyle * ass_dialog_style
int underline
whether text is underlined (1) or not (0)
ASSStyle * styles
array of split out styles
uint8_t * subtitle_header
Header containing style information for text subtitles.