FFmpeg
Loading...
Searching...
No Matches
movtextenc.c
Go to the documentation of this file.
1/*
2 * 3GPP TS 26.245 Timed Text encoder
3 * Copyright (c) 2012 Philip Langdale <philipl@overt.org>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdarg.h>
23#include "avcodec.h"
25#include "libavutil/opt.h"
27#include "libavutil/mem.h"
28#include "libavutil/common.h"
29#include "ass_split.h"
30#include "ass.h"
31#include "bytestream.h"
32#include "codec_internal.h"
33
34#define STYLE_FLAG_BOLD (1<<0)
35#define STYLE_FLAG_ITALIC (1<<1)
36#define STYLE_FLAG_UNDERLINE (1<<2)
37#define STYLE_RECORD_SIZE 12
38#define SIZE_ADD 10
39
40#define STYL_BOX (1<<0)
41#define HLIT_BOX (1<<1)
42#define HCLR_BOX (1<<2)
43
44#define DEFAULT_STYLE_FONT_ID 0x01
45#define DEFAULT_STYLE_FONTSIZE 0x12
46#define DEFAULT_STYLE_COLOR 0xffffffff
47#define DEFAULT_STYLE_FLAG 0x00
48
49#define BGR_TO_RGB(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((uint32_t)(c) >> 16) & 0xff))
50#define FONTSIZE_SCALE(s,fs) ((fs) * (s)->font_scale_factor + 0.5)
51#define av_bprint_append_any(buf, data, size) av_bprint_append_data(buf, ((const char*)data), size)
52
53typedef struct {
54 uint16_t style_start;
55 uint16_t style_end;
56 uint8_t style_flag;
57 uint16_t style_fontID;
59 uint32_t style_color;
60} StyleBox;
61
62typedef struct {
63 uint16_t start;
64 uint16_t end;
66
67typedef struct {
68 uint32_t color;
70
71typedef struct {
72 AVClass *class;
74
78 unsigned count;
81 AVBPrint buffer;
84 uint8_t box_flags;
86 uint16_t text_pos;
87 char **fonts;
90 int frame_height;
92
93typedef struct {
95} Box;
96
98{
99 s->count = 0;
100 s->style_attributes_temp = s->d;
101}
102
104{
105 if ((s->box_flags & STYL_BOX) && s->count) {
106 uint8_t buf[12], *p = buf;
107
108 bytestream_put_be32(&p, s->count * STYLE_RECORD_SIZE + SIZE_ADD);
109 bytestream_put_be32(&p, MKBETAG('s','t','y','l'));
110 bytestream_put_be16(&p, s->count);
111 /*The above three attributes are hard coded for now
112 but will come from ASS style in the future*/
113 av_bprint_append_any(&s->buffer, buf, 10);
114 for (unsigned j = 0; j < s->count; j++) {
115 const StyleBox *style = &s->style_attributes[j];
116
117 p = buf;
118 bytestream_put_be16(&p, style->style_start);
119 bytestream_put_be16(&p, style->style_end);
120 bytestream_put_be16(&p, style->style_fontID);
121 bytestream_put_byte(&p, style->style_flag);
122 bytestream_put_byte(&p, style->style_fontsize);
123 bytestream_put_be32(&p, style->style_color);
124
125 av_bprint_append_any(&s->buffer, buf, 12);
126 }
127 }
129}
130
132{
133 if (s->box_flags & HLIT_BOX) {
134 uint8_t buf[12], *p = buf;
135
136 bytestream_put_be32(&p, 12);
137 bytestream_put_be32(&p, MKBETAG('h','l','i','t'));
138 bytestream_put_be16(&p, s->hlit.start);
139 bytestream_put_be16(&p, s->hlit.end);
140
141 av_bprint_append_any(&s->buffer, buf, 12);
142 }
143}
144
146{
147 if (s->box_flags & HCLR_BOX) {
148 uint8_t buf[12], *p = buf;
149
150 bytestream_put_be32(&p, 12);
151 bytestream_put_be32(&p, MKBETAG('h','c','l','r'));
152 bytestream_put_be32(&p, s->hclr.color);
153
154 av_bprint_append_any(&s->buffer, buf, 12);
155 }
156}
157
158static const Box box_types[] = {
159 { encode_styl },
160 { encode_hlit },
161 { encode_hclr },
162};
163
164const static size_t box_count = FF_ARRAY_ELEMS(box_types);
165
167{
168 MovTextContext *s = avctx->priv_data;
169
170 ff_ass_split_free(s->ass_ctx);
171 av_freep(&s->style_attributes);
172 av_freep(&s->fonts);
173 return 0;
174}
175
177{
178 ASS *ass;
179 ASSStyle *style;
180 int i, j;
181 uint32_t back_color = 0;
182 int font_names_total_len = 0;
183 MovTextContext *s = avctx->priv_data;
184 uint8_t buf[30], *p = buf;
185 int ret;
186
187 av_bprint_init(&s->buffer, 0, INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE + 1);
188
189 // 0x00, 0x00, 0x00, 0x00, // uint32_t displayFlags
190 // 0x01, // int8_t horizontal-justification
191 // 0xFF, // int8_t vertical-justification
192 // 0x00, 0x00, 0x00, 0x00, // uint8_t background-color-rgba[4]
193 // BoxRecord {
194 // 0x00, 0x00, // int16_t top
195 // 0x00, 0x00, // int16_t left
196 // 0x00, 0x00, // int16_t bottom
197 // 0x00, 0x00, // int16_t right
198 // };
199 // StyleRecord {
200 // 0x00, 0x00, // uint16_t startChar
201 // 0x00, 0x00, // uint16_t endChar
202 // 0x00, 0x01, // uint16_t font-ID
203 // 0x00, // uint8_t face-style-flags
204 // 0x12, // uint8_t font-size
205 // 0xFF, 0xFF, 0xFF, 0xFF, // uint8_t text-color-rgba[4]
206 // };
207 // FontTableBox {
208 // 0x00, 0x00, 0x00, 0x12, // uint32_t size
209 // 'f', 't', 'a', 'b', // uint8_t name[4]
210 // 0x00, 0x01, // uint16_t entry-count
211 // FontRecord {
212 // 0x00, 0x01, // uint16_t font-ID
213 // 0x05, // uint8_t font-name-length
214 // 'S', 'e', 'r', 'i', 'f',// uint8_t font[font-name-length]
215 // };
216 // };
217
218 // Populate sample description from ASS header
219 ass = (ASS*)s->ass_ctx;
220 // Compute font scaling factor based on (optionally) provided
221 // output video height and ASS script play_res_y
222 if (s->frame_height && ass->script_info.play_res_y)
223 s->font_scale_factor = (double)s->frame_height / ass->script_info.play_res_y;
224 else
225 s->font_scale_factor = 1;
226
227 style = ff_ass_style_get(s->ass_ctx, "Default");
228 if (!style && ass->styles_count) {
229 style = &ass->styles[0];
230 }
231 s->d.style_fontID = DEFAULT_STYLE_FONT_ID;
232 s->d.style_fontsize = DEFAULT_STYLE_FONTSIZE;
233 s->d.style_color = DEFAULT_STYLE_COLOR;
234 s->d.style_flag = DEFAULT_STYLE_FLAG;
235 if (style) {
236 s->d.style_fontsize = FONTSIZE_SCALE(s, style->font_size);
237 s->d.style_color = BGR_TO_RGB(style->primary_color & 0xffffff) << 8 |
238 255 - ((uint32_t)style->primary_color >> 24);
239 s->d.style_flag = (!!style->bold * STYLE_FLAG_BOLD) |
240 (!!style->italic * STYLE_FLAG_ITALIC) |
241 (!!style->underline * STYLE_FLAG_UNDERLINE);
242 back_color = (BGR_TO_RGB(style->back_color & 0xffffff) << 8) |
243 (255 - ((uint32_t)style->back_color >> 24));
244 }
245
246 bytestream_put_be32(&p, 0); // displayFlags
247 bytestream_put_be16(&p, 0x01FF); // horizontal/vertical justification (2x int8_t)
248 bytestream_put_be32(&p, back_color);
249 bytestream_put_be64(&p, 0); // BoxRecord - 4xint16_t: top, left, bottom, right
250 // StyleRecord {
251 bytestream_put_be16(&p, s->d.style_start);
252 bytestream_put_be16(&p, s->d.style_end);
253 bytestream_put_be16(&p, s->d.style_fontID);
254 bytestream_put_byte(&p, s->d.style_flag);
255 bytestream_put_byte(&p, s->d.style_fontsize);
256 bytestream_put_be32(&p, s->d.style_color);
257 // };
258 av_bprint_append_any(&s->buffer, buf, 30);
259
260 // Build font table
261 // We can't build a complete font table since that would require
262 // scanning all dialogs first. But we can at least fill in what
263 // is available in the ASS header
264 if (style && ass->styles_count) {
265 // Find unique font names
266 if (style->font_name) {
267 av_dynarray_add(&s->fonts, &s->font_count, style->font_name);
268 font_names_total_len += strlen(style->font_name);
269 }
270 for (i = 0; i < ass->styles_count; i++) {
271 int found = 0;
272 if (!ass->styles[i].font_name)
273 continue;
274 for (j = 0; j < s->font_count; j++) {
275 if (!strcmp(s->fonts[j], ass->styles[i].font_name)) {
276 found = 1;
277 break;
278 }
279 }
280 if (!found) {
281 av_dynarray_add(&s->fonts, &s->font_count,
282 ass->styles[i].font_name);
283 font_names_total_len += strlen(ass->styles[i].font_name);
284 }
285 }
286 } else {
287 av_dynarray_add(&s->fonts, &s->font_count, (char*)"Serif");
288 font_names_total_len = strlen("Serif");
289 }
290
291 // FontTableBox {
292 p = buf;
293 bytestream_put_be32(&p, SIZE_ADD + 3 * s->font_count + font_names_total_len); // Size
294 bytestream_put_be32(&p, MKBETAG('f','t','a','b'));
295 bytestream_put_be16(&p, s->font_count);
296
297 av_bprint_append_any(&s->buffer, buf, 10);
298 // FontRecord {
299 for (i = 0; i < s->font_count; i++) {
300 size_t len = strlen(s->fonts[i]);
301
302 p = buf;
303 bytestream_put_be16(&p, i + 1); //fontID
304 bytestream_put_byte(&p, len);
305
306 av_bprint_append_any(&s->buffer, buf, 3);
307 av_bprint_append_any(&s->buffer, s->fonts[i], len);
308 }
309 // };
310 // };
311
312 if (!av_bprint_is_complete(&s->buffer)) {
313 ret = AVERROR(ENOMEM);
314 goto fail;
315 }
316
317 avctx->extradata_size = s->buffer.len;
319 if (!avctx->extradata) {
320 ret = AVERROR(ENOMEM);
321 goto fail;
322 }
323
324 memcpy(avctx->extradata, s->buffer.str, avctx->extradata_size);
325 ret = 0;
326fail:
327 av_bprint_finalize(&s->buffer, NULL);
328
329 return ret;
330}
331
333{
334 int ret;
335 MovTextContext *s = avctx->priv_data;
336 s->avctx = avctx;
337
338 s->ass_ctx = ff_ass_split(avctx->subtitle_header);
339 if (!s->ass_ctx)
340 return AVERROR_INVALIDDATA;
341 ret = encode_sample_description(avctx);
342 if (ret < 0)
343 return ret;
344
345 return 0;
346}
347
348// Start a new style box if needed
350{
351 // there's an existing style entry
352 if (s->style_attributes_temp.style_start == s->text_pos)
353 // Still at same text pos, use same entry
354 return 1;
355 if (s->style_attributes_temp.style_flag != s->d.style_flag ||
356 s->style_attributes_temp.style_color != s->d.style_color ||
357 s->style_attributes_temp.style_fontID != s->d.style_fontID ||
358 s->style_attributes_temp.style_fontsize != s->d.style_fontsize) {
359 StyleBox *tmp;
360
361 // last style != defaults, end the style entry and start a new one
362 if (s->count + 1 > FFMIN(SIZE_MAX / sizeof(*s->style_attributes), UINT16_MAX) ||
363 !(tmp = av_fast_realloc(s->style_attributes,
364 &s->style_attributes_bytes_allocated,
365 (s->count + 1) * sizeof(*s->style_attributes)))) {
367 av_bprint_clear(&s->buffer);
368 s->box_flags &= ~STYL_BOX;
369 return 0;
370 }
371 s->style_attributes = tmp;
372 s->style_attributes_temp.style_end = s->text_pos;
373 s->style_attributes[s->count++] = s->style_attributes_temp;
374 s->box_flags |= STYL_BOX;
375 s->style_attributes_temp = s->d;
376 s->style_attributes_temp.style_start = s->text_pos;
377 } else { // style entry matches defaults, drop entry
378 s->style_attributes_temp = s->d;
379 s->style_attributes_temp.style_start = s->text_pos;
380 }
381 return 1;
382}
383
384static uint8_t mov_text_style_to_flag(const char style)
385{
386 uint8_t style_flag = 0;
387
388 switch (style){
389 case 'b':
390 style_flag = STYLE_FLAG_BOLD;
391 break;
392 case 'i':
393 style_flag = STYLE_FLAG_ITALIC;
394 break;
395 case 'u':
396 style_flag = STYLE_FLAG_UNDERLINE;
397 break;
398 }
399 return style_flag;
400}
401
402static void mov_text_style_set(MovTextContext *s, uint8_t style_flags)
403{
404 if (!((s->style_attributes_temp.style_flag & style_flags) ^ style_flags)) {
405 // setting flags that that are already set
406 return;
407 }
409 s->style_attributes_temp.style_flag |= style_flags;
410}
411
412static void mov_text_style_cb(void *priv, const char style, int close)
413{
414 MovTextContext *s = priv;
415 uint8_t style_flag = mov_text_style_to_flag(style);
416
417 if (!!(s->style_attributes_temp.style_flag & style_flag) != close) {
418 // setting flag that is already set
419 return;
420 }
421 if (mov_text_style_start(s)) {
422 if (!close)
423 s->style_attributes_temp.style_flag |= style_flag;
424 else
425 s->style_attributes_temp.style_flag &= ~style_flag;
426 }
427}
428
430{
431 if ((s->style_attributes_temp.style_color & 0xffffff00) == color) {
432 // color hasn't changed
433 return;
434 }
436 s->style_attributes_temp.style_color = (color & 0xffffff00) |
437 (s->style_attributes_temp.style_color & 0xff);
438}
439
440static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color_id)
441{
442 MovTextContext *s = priv;
443
444 color = BGR_TO_RGB(color) << 8;
445 if (color_id == 1) { //primary color changes
447 } else if (color_id == 2) { //secondary color changes
448 if (!(s->box_flags & HCLR_BOX))
449 // Highlight alpha not set yet, use current primary alpha
450 s->hclr.color = s->style_attributes_temp.style_color;
451 if (!(s->box_flags & HLIT_BOX) || s->hlit.start == s->text_pos) {
452 s->box_flags |= HCLR_BOX;
453 s->box_flags |= HLIT_BOX;
454 s->hlit.start = s->text_pos;
455 s->hclr.color = color | (s->hclr.color & 0xFF);
456 }
457 else //close tag
458 s->hlit.end = s->text_pos;
459 /* If there are more than one secondary color changes in ASS,
460 take start of first section and end of last section. Movtext
461 allows only one highlight box per sample.
462 */
463 }
464 // Movtext does not support changes to other color_id (outline, background)
465}
466
468{
469 if ((s->style_attributes_temp.style_color & 0xff) == alpha) {
470 // color hasn't changed
471 return;
472 }
474 s->style_attributes_temp.style_color =
475 (s->style_attributes_temp.style_color & 0xffffff00) | alpha;
476}
477
478static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id)
479{
480 MovTextContext *s = priv;
481
482 alpha = 255 - alpha;
483 if (alpha_id == 1) // primary alpha changes
485 else if (alpha_id == 2) { //secondary alpha changes
486 if (!(s->box_flags & HCLR_BOX))
487 // Highlight color not set yet, use current primary color
488 s->hclr.color = s->style_attributes_temp.style_color;
489 if (!(s->box_flags & HLIT_BOX) || s->hlit.start == s->text_pos) {
490 s->box_flags |= HCLR_BOX;
491 s->box_flags |= HLIT_BOX;
492 s->hlit.start = s->text_pos;
493 s->hclr.color = (s->hclr.color & 0xffffff00) | alpha;
494 }
495 else //close tag
496 s->hlit.end = s->text_pos;
497 }
498 // Movtext does not support changes to other alpha_id (outline, background)
499}
500
501static uint16_t find_font_id(MovTextContext *s, const char *name)
502{
503 if (!name)
504 return 1;
505
506 for (int i = 0; i < s->font_count; i++) {
507 if (!strcmp(name, s->fonts[i]))
508 return i + 1;
509 }
510 return 1;
511}
512
513static void mov_text_font_name_set(MovTextContext *s, const char *name)
514{
515 int fontID = find_font_id(s, name);
516 if (s->style_attributes_temp.style_fontID == fontID) {
517 // color hasn't changed
518 return;
519 }
521 s->style_attributes_temp.style_fontID = fontID;
522}
523
524static void mov_text_font_name_cb(void *priv, const char *name)
525{
527}
528
530{
532 if (s->style_attributes_temp.style_fontsize == size) {
533 // color hasn't changed
534 return;
535 }
537 s->style_attributes_temp.style_fontsize = size;
538}
539
540static void mov_text_font_size_cb(void *priv, int size)
541{
543}
544
545static void mov_text_end_cb(void *priv)
546{
547 // End of text, close any open style record
549}
550
552{
553 uint8_t style_flags, alpha;
554 uint32_t color;
555
556 if (style) {
557 style_flags = (!!style->bold * STYLE_FLAG_BOLD) |
558 (!!style->italic * STYLE_FLAG_ITALIC) |
559 (!!style->underline * STYLE_FLAG_UNDERLINE);
560 mov_text_style_set(s, style_flags);
561 color = BGR_TO_RGB(style->primary_color & 0xffffff) << 8;
563 alpha = 255 - ((uint32_t)style->primary_color >> 24);
567 } else {
568 // End current style record, go back to defaults
570 }
571}
572
574{
575 ASSStyle *style = ff_ass_style_get(s->ass_ctx, dialog->style);
576
577 s->ass_dialog_style = style;
579}
580
581static void mov_text_cancel_overrides_cb(void *priv, const char *style_name)
582{
583 MovTextContext *s = priv;
584 ASSStyle *style;
585
586 if (!style_name || !*style_name)
587 style = s->ass_dialog_style;
588 else
589 style= ff_ass_style_get(s->ass_ctx, style_name);
590
592}
593
594static unsigned utf8_strlen(const char *text, int len)
595{
596 unsigned i = 0, ret = 0;
597 while (i < len) {
598 char c = text[i];
599 if ((c & 0x80) == 0)
600 i += 1;
601 else if ((c & 0xE0) == 0xC0)
602 i += 2;
603 else if ((c & 0xF0) == 0xE0)
604 i += 3;
605 else if ((c & 0xF8) == 0xF0)
606 i += 4;
607 else
608 return 0;
609 ret++;
610 }
611 return ret;
612}
613
614static void mov_text_text_cb(void *priv, const char *text, int len)
615{
616 unsigned utf8_len = utf8_strlen(text, len);
617 MovTextContext *s = priv;
618 av_bprint_append_data(&s->buffer, text, len);
619 // If it's not utf-8, just use the byte length
620 s->text_pos += utf8_len ? utf8_len : len;
621}
622
623static void mov_text_new_line_cb(void *priv, int forced)
624{
625 MovTextContext *s = priv;
626 s->text_pos += 1;
627 av_bprint_chars(&s->buffer, '\n', 1);
628}
629
631 .text = mov_text_text_cb,
632 .new_line = mov_text_new_line_cb,
633 .style = mov_text_style_cb,
634 .color = mov_text_color_cb,
635 .alpha = mov_text_alpha_cb,
636 .font_name = mov_text_font_name_cb,
637 .font_size = mov_text_font_size_cb,
638 .cancel_overrides = mov_text_cancel_overrides_cb,
639 .end = mov_text_end_cb,
640};
641
642static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,
643 int bufsize, const AVSubtitle *sub)
644{
645 MovTextContext *s = avctx->priv_data;
646 ASSDialog *dialog;
647 int i, length;
648
649 if (bufsize < 3)
650 goto too_small;
651
652 s->text_pos = 0;
653 s->count = 0;
654 s->box_flags = 0;
655
656 av_bprint_init_for_buffer(&s->buffer, buf + 2, bufsize - 2);
657 for (i = 0; i < sub->num_rects; i++) {
658 const char *ass = sub->rects[i]->ass;
659
660 if (sub->rects[i]->type != SUBTITLE_ASS) {
661 av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n");
662 return AVERROR(EINVAL);
663 }
664
665 dialog = ff_ass_split_dialog(s->ass_ctx, ass);
666 if (!dialog)
667 return AVERROR(ENOMEM);
668 mov_text_dialog(s, dialog);
670 ff_ass_free_dialog(&dialog);
671 }
672
673 if (s->buffer.len > UINT16_MAX)
674 return AVERROR(ERANGE);
675 AV_WB16(buf, s->buffer.len);
676
677 for (size_t j = 0; j < box_count; j++)
678 box_types[j].encode(s);
679
680 if (!s->buffer.len)
681 return 0;
682
683 if (!av_bprint_is_complete(&s->buffer)) {
684too_small:
685 av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
687 }
688
689 length = s->buffer.len + 2;
690
691 return length;
692}
693
694#define OFFSET(x) offsetof(MovTextContext, x)
695#define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_SUBTITLE_PARAM
696static const AVOption options[] = {
697 { "height", "Frame height, usually video height", OFFSET(frame_height), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
698 { NULL },
699};
700
702 .class_name = "MOV text enoder",
703 .item_name = av_default_item_name,
704 .option = options,
705 .version = LIBAVUTIL_VERSION_INT,
706};
707
709 .p.name = "mov_text",
710 CODEC_LONG_NAME("3GPP Timed Text subtitle"),
711 .p.type = AVMEDIA_TYPE_SUBTITLE,
712 .p.id = AV_CODEC_ID_MOV_TEXT,
713 .priv_data_size = sizeof(MovTextContext),
714 .p.priv_class = &mov_text_encoder_class,
715 .init = mov_text_encode_init,
717 .close = mov_text_encode_close,
718 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
719};
const FFCodec ff_movtext_encoder
Definition movtextenc.c:708
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
av_cold 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...
Definition ass_split.c:382
void ff_ass_free_dialog(ASSDialog **dialogp)
Free a dialogue obtained from ff_ass_split_dialog().
Definition ass_split.c:421
int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, const char *buf)
Split override codes out of a ASS "Dialogue" Text field.
Definition ass_split.c:483
ASSStyle * ff_ass_style_get(ASSSplitContext *ctx, const char *style)
Find an ASSStyle structure by its name.
Definition ass_split.c:578
av_cold void ff_ass_split_free(ASSSplitContext *ctx)
Free all the memory allocated for an ASSSplitContext.
Definition ass_split.c:470
ASSDialog * ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf)
Split one ASS Dialogue line from a string buffer.
Definition ass_split.c:433
Libavcodec external API header.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:68
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FLAGS
Definition cmdutils.c:596
#define FF_CODEC_ENCODE_SUB_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal and external API header
#define NULL
Definition coverity.c:32
static void encode(AVCodecContext *ctx, AVFrame *frame, AVPacket *pkt, FILE *output)
#define fail
Definition test.h:479
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ SUBTITLE_ASS
Formatted text, the ass field must be set by the decoder and is authoritative.
Definition avcodec.h:2070
@ AV_CODEC_ID_MOV_TEXT
Definition codec_id.h:572
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition bprint.h:218
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition bprint.c:234
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Definition bprint.c:147
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition bprint.c:129
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition bprint.c:226
void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size)
Init a print buffer using a pre-existing buffer.
Definition bprint.c:84
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
Definition error.h:53
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add the pointer to an element to a dynamic array.
Definition mem.c:433
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.
Definition mem.c:601
@ AVMEDIA_TYPE_SUBTITLE
Definition avutil.h:203
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static const int16_t alpha[]
Definition ilbcdata.h:55
#define AV_WB16(p, v)
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
#define FFMIN(a, b)
Definition macros.h:49
#define MKBETAG(a, b, c, d)
Definition macros.h:56
Memory handling functions.
#define STYLE_FLAG_UNDERLINE
Definition movtextdec.c:35
static const Box box_types[]
Definition movtextdec.c:325
#define HLIT_BOX
Definition movtextdec.c:40
#define HCLR_BOX
Definition movtextdec.c:41
#define STYLE_FLAG_ITALIC
Definition movtextdec.c:34
#define STYLE_FLAG_BOLD
Definition movtextdec.c:33
static const size_t box_count
Definition movtextdec.c:332
#define STYL_BOX
Definition movtextdec.c:39
static int encode_sample_description(AVCodecContext *avctx)
Definition movtextenc.c:176
#define FONTSIZE_SCALE(s, fs)
Definition movtextenc.c:50
static uint8_t mov_text_style_to_flag(const char style)
Definition movtextenc.c:384
static void mov_text_font_size_cb(void *priv, int size)
Definition movtextenc.c:540
static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, int bufsize, const AVSubtitle *sub)
Definition movtextenc.c:642
static void mov_text_font_name_cb(void *priv, const char *name)
Definition movtextenc.c:524
static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color_id)
Definition movtextenc.c:440
static void mov_text_color_set(MovTextContext *s, uint32_t color)
Definition movtextenc.c:429
static void mov_text_alpha_set(MovTextContext *s, uint8_t alpha)
Definition movtextenc.c:467
static void encode_hclr(MovTextContext *s)
Definition movtextenc.c:145
static void mov_text_end_cb(void *priv)
Definition movtextenc.c:545
static void encode_hlit(MovTextContext *s)
Definition movtextenc.c:131
static void mov_text_dialog(MovTextContext *s, ASSDialog *dialog)
Definition movtextenc.c:573
static void mov_text_text_cb(void *priv, const char *text, int len)
Definition movtextenc.c:614
#define DEFAULT_STYLE_FONT_ID
Definition movtextenc.c:44
static const ASSCodesCallbacks mov_text_callbacks
Definition movtextenc.c:630
static const AVClass mov_text_encoder_class
Definition movtextenc.c:701
static void mov_text_cancel_overrides_cb(void *priv, const char *style_name)
Definition movtextenc.c:581
static void mov_text_font_name_set(MovTextContext *s, const char *name)
Definition movtextenc.c:513
static av_cold int mov_text_encode_close(AVCodecContext *avctx)
Definition movtextenc.c:166
static unsigned utf8_strlen(const char *text, int len)
Definition movtextenc.c:594
static void mov_text_style_cb(void *priv, const char style, int close)
Definition movtextenc.c:412
#define SIZE_ADD
Definition movtextenc.c:38
#define DEFAULT_STYLE_COLOR
Definition movtextenc.c:46
#define BGR_TO_RGB(c)
Definition movtextenc.c:49
static int mov_text_style_start(MovTextContext *s)
Definition movtextenc.c:349
static void mov_text_font_size_set(MovTextContext *s, int size)
Definition movtextenc.c:529
#define STYLE_RECORD_SIZE
Definition movtextenc.c:37
static void mov_text_ass_style_set(MovTextContext *s, ASSStyle *style)
Definition movtextenc.c:551
static av_cold int mov_text_encode_init(AVCodecContext *avctx)
Definition movtextenc.c:332
static void encode_styl(MovTextContext *s)
Definition movtextenc.c:103
static void mov_text_new_line_cb(void *priv, int forced)
Definition movtextenc.c:623
static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id)
Definition movtextenc.c:478
static uint16_t find_font_id(MovTextContext *s, const char *name)
Definition movtextenc.c:501
#define OFFSET(x)
Definition movtextenc.c:694
static void mov_text_style_set(MovTextContext *s, uint8_t style_flags)
Definition movtextenc.c:402
#define DEFAULT_STYLE_FLAG
Definition movtextenc.c:47
static void mov_text_cleanup(MovTextContext *s)
Definition movtextenc.c:97
#define DEFAULT_STYLE_FONTSIZE
Definition movtextenc.c:45
#define av_bprint_append_any(buf, data, size)
Definition movtextenc.c:51
AVOptions.
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
Set of callback functions corresponding to each override codes that can be encountered in a "Dialogue...
Definition ass_split.h:138
fields extracted from the [Events] section
Definition ass_split.h:71
char * style
name of the ASSStyle to use with this dialog
Definition ass_split.h:76
char * text
actual text which will be displayed as a subtitle, can include style override control codes (see ff_a...
Definition ass_split.h:82
int play_res_y
video height that ASS coords are referring to
Definition ass_split.h:32
This struct can be casted to ASS to access to the split data.
Definition ass_split.c:205
fields extracted from the [V4(+) Styles] section
Definition ass_split.h:39
int primary_color
color that a subtitle will normally appear in
Definition ass_split.h:43
int italic
whether text is italic (1) or not (0)
Definition ass_split.h:48
int bold
whether text is bold (1) or not (0)
Definition ass_split.h:47
int underline
whether text is underlined (1) or not (0)
Definition ass_split.h:49
char * font_name
font face (case sensitive)
Definition ass_split.h:41
int back_color
color of the subtitle outline or shadow
Definition ass_split.h:46
int font_size
font height
Definition ass_split.h:42
structure containing the whole split ASS data
Definition ass_split.h:90
int styles_count
number of ASSStyle in the styles array
Definition ass_split.h:93
ASSStyle * styles
array of split out styles
Definition ass_split.h:92
ASSScriptInfo script_info
general information about the SSA script
Definition ass_split.h:91
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
uint8_t * subtitle_header
Definition avcodec.h:1749
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
int extradata_size
Definition avcodec.h:527
void * priv_data
Definition avcodec.h:470
AVOption.
Definition opt.h:428
char * ass
0 terminated ASS/SSA compatible event line.
Definition avcodec.h:2099
enum AVSubtitleType type
Definition avcodec.h:2090
unsigned num_rects
Definition avcodec.h:2106
AVSubtitleRect ** rects
Definition avcodec.h:2107
void(* encode)(MovTextContext *s)
Definition movtextenc.c:94
uint16_t end
Definition movtextenc.c:64
uint16_t start
Definition movtextenc.c:63
uint32_t color
Definition movtextenc.c:68
ASSSplitContext * ass_ctx
Definition movtextenc.c:75
StyleBox style_attributes_temp
Definition movtextenc.c:80
HilightcolorBox hclr
Definition movtextenc.c:83
uint8_t box_flags
Definition movtextdec.c:103
uint16_t text_pos
Definition movtextenc.c:86
ASSStyle * ass_dialog_style
Definition movtextenc.c:76
char ** fonts
Definition movtextenc.c:87
MovTextDefault d
Definition movtextdec.c:102
AVCodecContext * avctx
Definition movtextenc.c:73
HighlightBox hlit
Definition movtextenc.c:82
StyleBox * style_attributes
Definition movtextenc.c:77
AVBPrint buffer
Definition movtextenc.c:81
unsigned style_attributes_bytes_allocated
Definition movtextenc.c:79
unsigned count
Definition movtextenc.c:78
double font_scale_factor
Definition movtextenc.c:89
uint8_t style_flag
Definition movtextenc.c:56
uint8_t style_fontsize
Definition movtextenc.c:58
uint16_t style_fontID
Definition movtextenc.c:57
uint32_t style_color
Definition movtextenc.c:59
uint16_t style_start
Definition movtextenc.c:54
uint16_t style_end
Definition movtextenc.c:55
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
int size
int len
static double c[64]