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),
79 { .section =
"V4 Styles",
80 .format_header =
"Format",
81 .fields_header =
"Style",
84 .offset_count = offsetof(
ASS, styles_count),
96 { .section =
"Events",
97 .format_header =
"Format",
98 .fields_header =
"Dialogue",
101 .offset_count = offsetof(
ASS, dialogs_count),
119 memcpy(str, buf, len);
123 *(
char **)dest = str;
129 return sscanf(buf,
"%d", (
int *)dest) == 1;
133 return sscanf(buf,
"%f", (
float *)dest) == 1;
137 return sscanf(buf,
"&H%8x", (
int *)dest) == 1 ||
138 sscanf(buf,
"%d", (
int *)dest) == 1;
143 if ((c = sscanf(buf,
"%d:%02d:%02d.%02d", &h, &m, &s, &cs)) == 4)
144 *(
int *)dest = 360000*h + 6000*m + 100*s + cs;
150 if (sscanf(buf,
"%d", &a) == 1) {
152 *(
int *)dest = a + ((a&4) >> 1) - 5*!!(a&8);
185 tmp += *count * section->
size;
186 memset(tmp, 0, section->
size);
193 return buf ==
'\r' || buf ==
'\n' || buf == 0;
210 while (buf && *buf) {
215 if (buf[0] ==
';' || (buf[0] ==
'!' && buf[1] ==
':')) {
219 if (strncmp(buf, section->
format_header, len) || buf[len] !=
':')
224 len = strcspn(buf,
", \r\n");
225 if (!(tmp =
av_realloc(order, (*number + 1) *
sizeof(*order))))
230 if (!strncmp(buf, section->
fields[i].
name, len)) {
235 buf =
skip_space(buf + len + (buf[len] ==
','));
240 if (!strncmp(buf, section->
fields_header, len) && buf[len] ==
':') {
242 if (!struct_ptr)
return NULL;
244 for (i=0; !
is_eol(*buf) && i < *number; i++) {
245 int last = i == *number - 1;
247 len = strcspn(buf, last ?
"\r\n" :
",\r\n");
254 if (!last && *buf) buf++;
259 len = strcspn(buf,
":\r\n");
260 if (buf[len] ==
':') {
262 if (!strncmp(buf, section->
fields[i].
name, len)) {
272 buf += strcspn(buf,
"\n");
286 while (buf && *buf) {
287 if (sscanf(buf,
"[%15[0-9A-Za-z+ ]]%c", section, &c) == 2) {
288 buf += strcspn(buf,
"\n");
291 if (!strcmp(section, ass_sections[i].section)) {
296 buf += strcspn(buf,
"\n");
326 for (i=0; i<*
count; i++, ptr += section->
size)
339 int cache,
int *number)
345 if (!strcmp(ass_sections[i].
section,
"Events")) {
377 while (buf && *buf) {
378 if (text && callbacks->
text &&
379 (sscanf(buf,
"\\%1[nN]", new_line) == 1 ||
380 !strncmp(buf,
"{\\", 2))) {
381 callbacks->
text(priv, text, text_len);
384 if (sscanf(buf,
"\\%1[nN]", new_line) == 1) {
386 callbacks->
new_line(priv, new_line[0] ==
'N');
388 }
else if (!strncmp(buf,
"{\\", 2)) {
390 while (*buf ==
'\\') {
391 char style[2],
c[2], sep[2], c_num[2] =
"0", tmp[128] = {0};
392 unsigned int color = 0xFFFFFFFF;
395 if (sscanf(buf,
"\\%1[bisu]%1[01\\}]%n", style, c, &len) > 1) {
396 int close = c[0] ==
'0' ? 1 : c[0] ==
'1' ? 0 : -1;
398 if (callbacks->
style)
399 callbacks->
style(priv, style[0], close);
400 }
else if (sscanf(buf,
"\\c%1[\\}]%n", sep, &len) > 0 ||
401 sscanf(buf,
"\\c&H%X&%1[\\}]%n", &color, sep, &len) > 1 ||
402 sscanf(buf,
"\\%1[1234]c%1[\\}]%n", c_num, sep, &len) > 1 ||
403 sscanf(buf,
"\\%1[1234]c&H%X&%1[\\}]%n", c_num, &color, sep, &len) > 2) {
404 if (callbacks->
color)
405 callbacks->
color(priv, color, c_num[0] -
'0');
406 }
else if (sscanf(buf,
"\\alpha%1[\\}]%n", sep, &len) > 0 ||
407 sscanf(buf,
"\\alpha&H%2X&%1[\\}]%n", &
alpha, sep, &len) > 1 ||
408 sscanf(buf,
"\\%1[1234]a%1[\\}]%n", c_num, sep, &len) > 1 ||
409 sscanf(buf,
"\\%1[1234]a&H%2X&%1[\\}]%n", c_num, &
alpha, sep, &len) > 2) {
410 if (callbacks->
alpha)
411 callbacks->
alpha(priv,
alpha, c_num[0] -
'0');
412 }
else if (sscanf(buf,
"\\fn%1[\\}]%n", sep, &len) > 0 ||
413 sscanf(buf,
"\\fn%127[^\\}]%1[\\}]%n", tmp, sep, &len) > 1) {
416 }
else if (sscanf(buf,
"\\fs%1[\\}]%n", sep, &len) > 0 ||
417 sscanf(buf,
"\\fs%u%1[\\}]%n", &size, sep, &len) > 1) {
420 }
else if (sscanf(buf,
"\\a%1[\\}]%n", sep, &len) > 0 ||
421 sscanf(buf,
"\\a%2u%1[\\}]%n", &an, sep, &len) > 1 ||
422 sscanf(buf,
"\\an%1[\\}]%n", sep, &len) > 0 ||
423 sscanf(buf,
"\\an%1u%1[\\}]%n", &an, sep, &len) > 1) {
424 if (an != -1 && buf[2] !=
'n')
425 an = (an&3) + (an&4 ? 6 : an&8 ? 3 : 0);
428 }
else if (sscanf(buf,
"\\r%1[\\}]%n", sep, &len) > 0 ||
429 sscanf(buf,
"\\r%127[^\\}]%1[\\}]%n", tmp, sep, &len) > 1) {
432 }
else if (sscanf(buf,
"\\move(%d,%d,%d,%d)%1[\\}]%n", &x1, &y1, &x2, &y2, sep, &len) > 4 ||
433 sscanf(buf,
"\\move(%d,%d,%d,%d,%d,%d)%1[\\}]%n", &x1, &y1, &x2, &y2, &t1, &
t2, sep, &len) > 6) {
435 callbacks->
move(priv, x1, y1, x2, y2, t1,
t2);
436 }
else if (sscanf(buf,
"\\pos(%d,%d)%1[\\}]%n", &x1, &y1, sep, &len) > 2) {
438 callbacks->
move(priv, x1, y1, x1, y1, -1, -1);
439 }
else if (sscanf(buf,
"\\org(%d,%d)%1[\\}]%n", &x1, &y1, sep, &len) > 2) {
441 callbacks->
origin(priv, x1, y1);
443 len = strcspn(buf+1,
"\\}") + 2;
458 if (text && callbacks->
text)
459 callbacks->
text(priv, text, text_len);
461 callbacks->
end(priv);
470 if (!style || !*style)
int(* ASSConvertFunc)(void *dest, const char *buf, int len)
static const char * skip_space(const char *buf)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void(* new_line)(void *priv, int forced)
fields extracted from the [Events] section
static int convert_alignment(void *dest, const char *buf, int len)
void(* move)(void *priv, int x1, int y1, int x2, int y2, int t1, int t2)
static int convert_str(void *dest, const char *buf, int len)
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 const ASSSection ass_sections[]
ASSDialog * dialogs
array of split out dialogs
const char * format_header
static int convert_color(void *dest, const char *buf, int len)
structure containing the whole split ASS data
void(* cancel_overrides)(void *priv, const char *style)
static int ass_split(ASSSplitContext *ctx, const char *buf)
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
#define FF_ARRAY_ELEMS(a)
static const char * ass_split_section(ASSSplitContext *ctx, const char *buf)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, const char *buf)
Split override codes out of a ASS "Dialogue" Text field.
const char * fields_header
static int is_eol(char buf)
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 a already initialize...
void(* color)(void *priv, unsigned int, unsigned int color_id)
static double alpha(void *priv, double x, double y)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void(* font_name)(void *priv, const char *name)
static const uint8_t offset[127][2]
void(* font_size)(void *priv, int size)
Set of callback functions corresponding to each override codes that can be encountered in a "Dialogue...
static int convert_flt(void *dest, const char *buf, int len)
static const ASSConvertFunc convert_func[]
void(* origin)(void *priv, int x, int y)
static void close(AVCodecParserContext *s)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
synthesis window for stochastic i
void(* alignment)(void *priv, int alignment)
static void free_section(ASSSplitContext *ctx, const ASSSection *section)
static uint8_t * realloc_section_array(ASSSplitContext *ctx)
fields extracted from the [V4(+) Styles] section
ASSStyle * ff_ass_style_get(ASSSplitContext *ctx, const char *style)
Find an ASSStyle structure by its name.
void(* alpha)(void *priv, int alpha, int alpha_id)
static int convert_timestamp(void *dest, const char *buf, int len)
static int convert_int(void *dest, const char *buf, int len)
char * name
name of the tyle (case sensitive)
void(* text)(void *priv, const char *text, int len)
int dialogs_count
number of ASSDialog in the dialogs array
int styles_count
number of ASSStyle in the styles array
void ff_ass_split_free(ASSSplitContext *ctx)
Free all the memory allocated for an ASSSplitContext.
fields extracted from the [Script Info] section
void(* style)(void *priv, char style, int close)
ASSStyle * styles
array of split out styles
int * field_order[FF_ARRAY_ELEMS(ass_sections)]
int field_number[FF_ARRAY_ELEMS(ass_sections)]