33#define STYLE_FLAG_BOLD (1<<0)
34#define STYLE_FLAG_ITALIC (1<<1)
35#define STYLE_FLAG_UNDERLINE (1<<2)
37#define BOX_SIZE_INITIAL 40
39#define STYL_BOX (1<<0)
40#define HLIT_BOX (1<<1)
41#define HCLR_BOX (1<<2)
42#define TWRP_BOX (1<<3)
45#define BOTTOM_CENTER 2
48#define MIDDLE_CENTER 5
54#define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff))
135 style->
font_id = bytestream_get_be16(ptr);
137 style->
flags = bytestream_get_byte(ptr);
142 style->
fontsize = bytestream_get_byte(ptr);
144 style->
color = bytestream_get_be24(ptr);
146 style->
alpha = bytestream_get_byte(ptr);
151 const uint8_t *tx3g_ptr = avctx->
extradata;
153 int8_t v_align, h_align;
154 unsigned ftab_entries;
163 h_align = bytestream_get_byte(&tx3g_ptr);
164 v_align = bytestream_get_byte(&tx3g_ptr);
207 ftab_entries = bytestream_get_be16(&tx3g_ptr);
210 remaining -= 3 * ftab_entries;
222 font_length = bytestream_get_byte(&tx3g_ptr);
224 remaining -= font_length;
253 m->
h.
hlit_end = bytestream_get_be16(&tsmb);
266#define CMP(field) ((a)->field == (b)->field)
275 int style_entries = bytestream_get_be16(&tsmb);
279 if (2 + style_entries * 12 >
size)
292 style->
start = bytestream_get_be16(&tsmb);
293 style->
end = bytestream_get_be16(&tsmb);
313 }
else if (
i && style->
start == style[-1].
end &&
316 style[-1].
end = style->
end;
337 const char *start = text;
340 GET_UTF8(
c, text < text_end ? (uint8_t)*text++ : (err = 1, 0),
goto error;);
348static int text_to_ass(AVBPrint *buf,
const char *text,
const char *text_end,
358 if (text < text_end && m->box_flags &
TWRP_BOX) {
366 while (text < text_end) {
371 if (text_pos == style->
end) {
378 if (style->
bold ^ default_style->
bold)
411 av_bprintf(buf,
"{\\1c&H000000&}{\\2c&HFFFFFF&}");
465 (255U - default_style->
alpha) << 24 | default_style->
color,
466 (255U - default_style->
alpha) << 24 | default_style->
color,
476 int *got_sub_ptr,
const AVPacket *avpkt)
481 const char *ptr = avpkt->
data, *end;
485 if (!ptr || avpkt->
size < 2)
495 if (avpkt->
size == 2)
504 end = ptr +
FFMIN(2 + text_length, avpkt->
size);
513 if (text_length + 2 < avpkt->
size) {
514 const uint8_t *tsmb = end;
515 const uint8_t *
const tsmb_end = avpkt->
data + avpkt->
size;
517 while (tsmb_end - tsmb >= 8) {
518 uint64_t tsmb_size = bytestream_get_be32(&tsmb);
519 uint32_t tsmb_type = bytestream_get_be32(&tsmb);
520 int size_var, ret_tsmb;
522 if (tsmb_size == 1) {
523 if (tsmb_end - tsmb < 8)
525 tsmb_size = bytestream_get_be64(&tsmb);
531 if (tsmb_size < size_var) {
535 tsmb_size -= size_var;
537 if (tsmb_end - tsmb < tsmb_size)
544 ret_tsmb =
box_types[
i].decode(tsmb, m, tsmb_size);
579#define OFFSET(x) offsetof(MovTextContext, x)
580#define FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
588 .class_name =
"MOV text decoder",
595 .p.name =
"mov_text",
const FFCodec ff_movtext_decoder
int ff_ass_subtitle_header_full(AVCodecContext *avctx, int play_res_x, int play_res_y, const char *font, int font_size, int primary_color, int secondary_color, int outline_color, int back_color, int bold, int italic, int underline, int border_style, int alignment)
Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS.
int ff_ass_subtitle_header_default(AVCodecContext *avctx)
Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS with default style.
int ff_ass_add_rect(AVSubtitle *sub, const char *dialog, int readorder, int layer, const char *style, const char *speaker)
Add an ASS dialog to a subtitle.
#define ASS_DEFAULT_PLAYRESY
#define ASS_DEFAULT_PLAYRESX
#define ASS_DEFAULT_BORDERSTYLE
Libavcodec external API header.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
#define i(width, name, range_min, range_max)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_DECODE_SUB_CB(func)
common internal and external API header
#define GET_UTF8(val, GET_BYTE, ERROR)
Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_FLAG2_RO_FLUSH_NOOP
Do not reset ASS ReadOrder field on flush (subtitles decoding)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
#define LIBAVUTIL_VERSION_INT
static const int16_t alpha[]
#define MKBETAG(a, b, c, d)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
#define STYLE_FLAG_UNDERLINE
static int styles_equivalent(const StyleBox *a, const StyleBox *b)
static av_cold int mov_text_decode_close(AVCodecContext *avctx)
static const AVClass mov_text_decoder_class
static void mov_text_parse_style_record(StyleBox *style, const uint8_t **ptr)
static int decode_hclr(const uint8_t *tsmb, MovTextContext *m, uint64_t size)
static int get_utf8_length_at(const char *text, const char *text_end)
static const Box box_types[]
static void mov_text_cleanup(MovTextContext *m)
static int decode_styl(const uint8_t *tsmb, MovTextContext *m, uint64_t size)
static int decode_twrp(const uint8_t *tsmb, MovTextContext *m, uint64_t size)
#define STYLE_FLAG_ITALIC
static int decode_hlit(const uint8_t *tsmb, MovTextContext *m, uint64_t size)
static const size_t box_count
static int mov_text_decode_frame(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
static av_cold int mov_text_init(AVCodecContext *avctx)
static av_cold void mov_text_flush(AVCodecContext *avctx)
static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, AVCodecContext *avctx)
static void mov_text_cleanup_ftab(MovTextContext *m)
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
main external API structure.
int flags2
AV_CODEC_FLAG2_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
This structure stores compressed data.
int(* decode)(const uint8_t *tsmb, MovTextContext *m, uint64_t size)
static void error(const char *err)