diff options
author | Clément Bœsch <u@pkh.me> | 2016-01-06 13:43:23 +0100 |
---|---|---|
committer | Clément Bœsch <u@pkh.me> | 2016-02-26 21:49:34 +0100 |
commit | 29412821241050c846dbceaad4b9752857659977 (patch) | |
tree | eb42444a7a6bf5d2dc66cdec8c7aa26be32bed99 /libavcodec/ass_split.c | |
parent | 805685fffd3115d3f9260d8df15ef36b6b3b8006 (diff) | |
download | ffmpeg-29412821241050c846dbceaad4b9752857659977.tar.gz |
lavc: allow subtitle text format to be ASS without timing
Diffstat (limited to 'libavcodec/ass_split.c')
-rw-r--r-- | libavcodec/ass_split.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/libavcodec/ass_split.c b/libavcodec/ass_split.c index f84a686b03..beaba7eb7c 100644 --- a/libavcodec/ass_split.c +++ b/libavcodec/ass_split.c @@ -409,6 +409,55 @@ ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf, return dialog; } +void ff_ass_free_dialog(ASSDialog **dialogp) +{ + ASSDialog *dialog = *dialogp; + if (!dialog) + return; + av_freep(&dialog->style); + av_freep(&dialog->name); + av_freep(&dialog->effect); + av_freep(&dialog->text); + av_freep(dialogp); +} + +ASSDialog *ff_ass_split_dialog2(ASSSplitContext *ctx, const char *buf) +{ + int i; + static const ASSFields fields[] = { + {"ReadOrder", ASS_INT, offsetof(ASSDialog, readorder)}, + {"Layer", ASS_INT, offsetof(ASSDialog, layer) }, + {"Style", ASS_STR, offsetof(ASSDialog, style) }, + {"Name", ASS_STR, offsetof(ASSDialog, name) }, + {"MarginL", ASS_INT, offsetof(ASSDialog, margin_l) }, + {"MarginR", ASS_INT, offsetof(ASSDialog, margin_r) }, + {"MarginV", ASS_INT, offsetof(ASSDialog, margin_v) }, + {"Effect", ASS_STR, offsetof(ASSDialog, effect) }, + {"Text", ASS_STR, offsetof(ASSDialog, text) }, + }; + + ASSDialog *dialog = av_mallocz(sizeof(*dialog)); + if (!dialog) + return NULL; + + for (i = 0; i < FF_ARRAY_ELEMS(fields); i++) { + size_t len; + const int last = i == FF_ARRAY_ELEMS(fields) - 1; + const ASSFieldType type = fields[i].type; + uint8_t *ptr = (uint8_t *)dialog + fields[i].offset; + buf = skip_space(buf); + len = last ? strlen(buf) : strcspn(buf, ","); + if (len >= INT_MAX) { + ff_ass_free_dialog(&dialog); + return NULL; + } + convert_func[type](ptr, buf, len); + buf += len; + if (*buf) buf++; + } + return dialog; +} + void ff_ass_split_free(ASSSplitContext *ctx) { if (ctx) { |