32 #define STYLE_FLAG_BOLD (1<<0)
33 #define STYLE_FLAG_ITALIC (1<<1)
34 #define STYLE_FLAG_UNDERLINE (1<<2)
36 #define BOX_SIZE_INITIAL 40
38 #define STYL_BOX (1<<0)
39 #define HLIT_BOX (1<<1)
40 #define HCLR_BOX (1<<2)
41 #define TWRP_BOX (1<<3)
44 #define BOTTOM_CENTER 2
45 #define BOTTOM_RIGHT 3
47 #define MIDDLE_CENTER 5
48 #define MIDDLE_RIGHT 6
53 #define RGB_TO_BGR(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff))
143 int8_t v_align, h_align;
144 unsigned ftab_entries;
154 h_align = bytestream_get_byte(&tx3g_ptr);
155 v_align = bytestream_get_byte(&tx3g_ptr);
188 m->
d.
fontID = bytestream_get_be16(&tx3g_ptr);
190 s_default.
style_flag = bytestream_get_byte(&tx3g_ptr);
195 m->
d.
fontsize = bytestream_get_byte(&tx3g_ptr);
197 m->
d.
color = bytestream_get_be24(&tx3g_ptr);
198 m->
d.
alpha = bytestream_get_byte(&tx3g_ptr);
208 ftab_entries = bytestream_get_be16(&tx3g_ptr);
211 remaining -= 3 * ftab_entries;
220 m->
ftab[
i].
fontID = bytestream_get_be16(&tx3g_ptr);
223 font_length = bytestream_get_byte(&tx3g_ptr);
225 remaining -= font_length;
254 m->
h.
hlit_end = bytestream_get_be16(&tsmb);
268 int style_entries = bytestream_get_be16(&tsmb);
286 style->
style_end = bytestream_get_be16(&tsmb);
301 style->
style_flag = bytestream_get_byte(&tsmb);
305 style->
fontsize = bytestream_get_byte(&tsmb);
306 style->
color = bytestream_get_be24(&tsmb);
307 style->
alpha = bytestream_get_byte(&tsmb);
324 const char *start = text;
335 static int text_to_ass(AVBPrint *buf,
const char *text,
const char *text_end,
344 if (text < text_end && m->box_flags &
TWRP_BOX) {
352 while (text < text_end) {
363 if (entry < m->style_entries && text_pos == style->
style_start) {
397 av_bprintf(buf,
"{\\1c&H000000&}{\\2c&HFFFFFF&}");
467 char *ptr = avpkt->
data;
469 int text_length, tsmb_type, ret_tsmb;
474 if (!ptr || avpkt->
size < 2)
484 if (avpkt->
size == 2)
493 end = ptr +
FFMIN(2 + text_length, avpkt->
size);
504 if (text_length + 2 != avpkt->
size) {
513 if (tsmb_size == 1) {
523 if (tsmb_size == 0) {
551 *got_sub_ptr =
sub->num_rects > 0;
570 #define OFFSET(x) offsetof(MovTextContext, x)
571 #define FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
static void flush(AVCodecContext *avctx)
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.
static av_cold int init(AVCodecContext *avctx)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
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 AV_BPRINT_SIZE_UNLIMITED
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
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.
#define MKBETAG(a, b, c, d)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static float sub(float src0, float src1)
#define AV_CODEC_FLAG2_RO_FLUSH_NOOP
Do not reset ASS ReadOrder field on flush (subtitles decoding)
#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)
Allocate, reallocate, or free an array.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
#define LIBAVUTIL_VERSION_INT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Memory handling functions.
static int mov_text_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *avpkt)
#define STYLE_FLAG_UNDERLINE
static int mov_text_decode_close(AVCodecContext *avctx)
static int decode_hlit(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
static const AVClass mov_text_decoder_class
static const AVOption options[]
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 void mov_text_flush(AVCodecContext *avctx)
#define STYLE_FLAG_ITALIC
static const size_t box_count
static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
AVCodec ff_movtext_decoder
static int mov_text_init(AVCodecContext *avctx)
static int decode_hclr(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end, AVCodecContext *avctx)
static int decode_twrp(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
static void mov_text_cleanup_ftab(MovTextContext *m)
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
int flags2
AV_CODEC_FLAG2_*.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
const char * name
Name of the codec implementation.
This structure stores compressed data.
int(* decode)(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt)
static void error(const char *err)