52 .offset = offsetof(
ASS, script_info),
61 { .section =
"V4+ Styles",
62 .format_header =
"Format",
63 .fields_header =
"Style",
66 .offset_count = offsetof(
ASS, styles_count),
93 { .section =
"V4 Styles",
94 .format_header =
"Format",
95 .fields_header =
"Style",
98 .offset_count = offsetof(
ASS, styles_count),
120 { .section =
"Events",
121 .format_header =
"Format",
122 .fields_header =
"Dialogue",
125 .offset_count = offsetof(
ASS, dialogs_count),
152 *(
char **)dest =
str;
158 return sscanf(buf,
"%d", (
int *)dest) == 1;
162 return sscanf(buf,
"%f", (
float *)dest) == 1;
166 return sscanf(buf,
"&H%8x", (
int *)dest) == 1 ||
167 sscanf(buf,
"%d", (
int *)dest) == 1;
172 if ((
c = sscanf(buf,
"%d:%02d:%02d.%02d", &
h, &m, &
s, &cs)) == 4)
173 *(
int *)dest = 360000*
h + 6000*m + 100*
s + cs;
179 if (sscanf(buf,
"%d", &
a) == 1) {
181 *(
int *)dest =
a + ((
a&4) >> 1) - 5*!!(
a&8);
222 return buf ==
'\r' || buf ==
'\n' || buf == 0;
250 int *number = &
ctx->field_number[
ctx->current_section];
251 int *order =
ctx->field_order[
ctx->current_section];
254 while (buf && *buf) {
256 ctx->current_section = -1;
259 if (buf[0] ==
';' || (buf[0] ==
'!' && buf[1] ==
':'))
262 len = strcspn(buf,
":\r\n");
263 if (buf[
len] ==
':' &&
268 ctx->current_section =
i;
270 number = &
ctx->field_number[
ctx->current_section];
271 order =
ctx->field_order[
ctx->current_section];
276 if (
section->format_header && !order) {
278 if (!strncmp(buf,
section->format_header,
len) && buf[
len] ==
':') {
282 len = strcspn(buf,
", \r\n");
295 ctx->field_order[
ctx->current_section] = order;
301 if (!strncmp(buf,
section->fields_header,
len) && buf[
len] ==
':') {
303 if (!struct_ptr)
return NULL;
310 ctx->field_order[
ctx->current_section] = order;
314 for (
i=0; !
is_eol(*buf) &&
i < *number;
i++) {
315 int last =
i == *number - 1;
317 len = strcspn(buf, last ?
"\r\n" :
",\r\n");
320 ptr = struct_ptr +
section->fields[order[
i]].offset;
324 if (!last && *buf) buf++;
329 len = strcspn(buf,
":\r\n");
330 if (buf[
len] ==
':') {
343 buf += strcspn(buf,
"\n");
354 if (
ctx->current_section >= 0)
357 while (buf && *buf) {
358 if (sscanf(buf,
"[%15[0-9A-Za-z+ ]]%c",
section, &
c) == 2) {
359 buf += strcspn(buf,
"\n");
363 ctx->current_section =
i;
367 buf += strcspn(buf,
"\n");
379 if (buf && !strncmp(buf,
"\xef\xbb\xbf", 3))
381 ctx->current_section = -1;
392 int i, j, *count,
c = 1;
401 for (
i=0;
i<*count;
i++, ptr +=
section->size)
414 int cache,
int *number)
424 count =
ctx->ass.dialogs_count;
426 dialog =
ctx->ass.dialogs + count;
428 *number =
ctx->ass.dialogs_count - count;
469 len = last ? strlen(buf) : strcspn(buf,
",");
470 if (
len >= INT_MAX) {
497 const char *text =
NULL;
501 while (buf && *buf) {
503 (sscanf(buf,
"\\%1[nN]", new_line) == 1 ||
504 !strncmp(buf,
"{\\", 2))) {
508 if (sscanf(buf,
"\\%1[nN]", new_line) == 1) {
510 callbacks->new_line(priv, new_line[0] ==
'N');
512 }
else if (!strncmp(buf,
"{\\", 2)) {
514 while (*buf ==
'\\') {
515 char style[2],
c[2], sep[2], c_num[2] =
"0",
tmp[128] = {0};
516 unsigned int color = 0xFFFFFFFF;
518 int x1, y1, x2, y2,
t1 = -1,
t2 = -1;
519 if (sscanf(buf,
"\\%1[bisu]%1[01\\}]%n", style,
c, &
len) > 1) {
520 int close =
c[0] ==
'0' ? 1 :
c[0] ==
'1' ? 0 : -1;
524 }
else if (sscanf(buf,
"\\c%1[\\}]%n", sep, &
len) > 0 ||
525 sscanf(buf,
"\\c&H%X&%1[\\}]%n", &
color, sep, &
len) > 1 ||
526 sscanf(buf,
"\\%1[1234]c%1[\\}]%n", c_num, sep, &
len) > 1 ||
527 sscanf(buf,
"\\%1[1234]c&H%X&%1[\\}]%n", c_num, &
color, sep, &
len) > 2) {
530 }
else if (sscanf(buf,
"\\alpha%1[\\}]%n", sep, &
len) > 0 ||
531 sscanf(buf,
"\\alpha&H%2X&%1[\\}]%n", &
alpha, sep, &
len) > 1 ||
532 sscanf(buf,
"\\%1[1234]a%1[\\}]%n", c_num, sep, &
len) > 1 ||
533 sscanf(buf,
"\\%1[1234]a&H%2X&%1[\\}]%n", c_num, &
alpha, sep, &
len) > 2) {
536 }
else if (sscanf(buf,
"\\fn%1[\\}]%n", sep, &
len) > 0 ||
537 sscanf(buf,
"\\fn%127[^\\}]%1[\\}]%n",
tmp, sep, &
len) > 1) {
540 }
else if (sscanf(buf,
"\\fs%1[\\}]%n", sep, &
len) > 0 ||
541 sscanf(buf,
"\\fs%u%1[\\}]%n", &
size, sep, &
len) > 1) {
544 }
else if (sscanf(buf,
"\\a%1[\\}]%n", sep, &
len) > 0 ||
545 sscanf(buf,
"\\a%2u%1[\\}]%n", &an, sep, &
len) > 1 ||
546 sscanf(buf,
"\\an%1[\\}]%n", sep, &
len) > 0 ||
547 sscanf(buf,
"\\an%1u%1[\\}]%n", &an, sep, &
len) > 1) {
548 if (an != -1 && buf[2] !=
'n')
549 an = (an&3) + (an&4 ? 6 : an&8 ? 3 : 0);
552 }
else if (sscanf(buf,
"\\r%1[\\}]%n", sep, &
len) > 0 ||
553 sscanf(buf,
"\\r%127[^\\}]%1[\\}]%n",
tmp, sep, &
len) > 1) {
556 }
else if (sscanf(buf,
"\\move(%d,%d,%d,%d)%1[\\}]%n", &x1, &y1, &x2, &y2, sep, &
len) > 4 ||
557 sscanf(buf,
"\\move(%d,%d,%d,%d,%d,%d)%1[\\}]%n", &x1, &y1, &x2, &y2, &
t1, &
t2, sep, &
len) > 6) {
560 }
else if (sscanf(buf,
"\\pos(%d,%d)%1[\\}]%n", &x1, &y1, sep, &
len) > 2) {
562 callbacks->move(priv, x1, y1, x1, y1, -1, -1);
563 }
else if (sscanf(buf,
"\\org(%d,%d)%1[\\}]%n", &x1, &y1, sep, &
len) > 2) {
567 len = strcspn(buf+1,
"\\}") + 2;
594 if (!style || !*style)
static int convert_color(void *dest, const char *buf, int len)
static void free_section(ASSSplitContext *ctx, const ASSSection *section)
static uint8_t * realloc_section_array(ASSSplitContext *ctx)
static int * get_default_field_orders(const ASSSection *section, int *number)
static const char * skip_space(const char *buf)
ASSDialog * ff_ass_split_dialog2(ASSSplitContext *ctx, const char *buf)
Split one ASS Dialogue line from a string buffer.
static const ASSConvertFunc convert_func[]
static int convert_str(void *dest, const char *buf, int len)
void ff_ass_free_dialog(ASSDialog **dialogp)
Free a dialogue obtained from ff_ass_split_dialog2().
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...
int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, const char *buf)
Split override codes out of a ASS "Dialogue" Text field.
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...
static int convert_flt(void *dest, const char *buf, int len)
static int ass_split(ASSSplitContext *ctx, const char *buf)
static int convert_int(void *dest, const char *buf, int len)
static int is_eol(char buf)
static const char * ass_split_section(ASSSplitContext *ctx, const char *buf)
static const ASSSection ass_sections[]
static int convert_alignment(void *dest, const char *buf, int len)
static int convert_timestamp(void *dest, const char *buf, int len)
int(* ASSConvertFunc)(void *dest, const char *buf, int len)
ASSStyle * ff_ass_style_get(ASSSplitContext *ctx, const char *style)
Find an ASSStyle structure by its name.
void ff_ass_split_free(ASSSplitContext *ctx)
Free all the memory allocated for an ASSSplitContext.
Libavcodec external API header.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
static const int16_t alpha[]
static const OMX_CALLBACKTYPE callbacks
#define FF_ARRAY_ELEMS(a)
Set of callback functions corresponding to each override codes that can be encountered in a "Dialogue...
fields extracted from the [Events] section
char * style
name of the ASSStyle to use with this dialog
char * text
actual text which will be displayed as a subtitle, can include style override control codes (see ff_a...
fields extracted from the [Script Info] section
const char * fields_header
const char * format_header
This struct can be casted to ASS to access to the split data.
int * field_order[FF_ARRAY_ELEMS(ass_sections)]
int field_number[FF_ARRAY_ELEMS(ass_sections)]
fields extracted from the [V4(+) Styles] section
char * name
name of the tyle (case sensitive)
structure containing the whole split ASS data
int styles_count
number of ASSStyle in the styles array
ASSStyle * styles
array of split out styles
#define av_malloc_array(a, b)
static const uint8_t offset[127][2]