avformat/matroskaenc: Don't waste bytes on ChapterAtoms length fields

Also check the (user-provided) metadata tags for being too long.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
release/5.1
Andreas Rheinhardt 3 years ago
parent e8065c7def
commit a04c917399
  1. 22
      libavformat/matroskaenc.c
  2. 4
      tests/ref/fate/webm-dash-chapters

@ -2012,12 +2012,13 @@ static int mkv_write_chapters(AVFormatContext *s)
create_new_ids = mkv_new_chapter_ids_needed(s);
for (unsigned i = 0; i < s->nb_chapters; i++) {
ebml_master chapteratom, chapterdisplay;
const AVChapter *c = s->chapters[i];
int64_t chapterstart = av_rescale_q(c->start, c->time_base, scale);
int64_t chapterend = av_rescale_q(c->end, c->time_base, scale);
const AVDictionaryEntry *t;
uint64_t uid = create_new_ids ? i + 1ULL : c->id;
EBML_WRITER(7);
if (chapterstart < 0 || chapterstart > chapterend || chapterend < 0) {
av_log(s, AV_LOG_ERROR,
"Invalid chapter start (%"PRId64") or end (%"PRId64").\n",
@ -2026,17 +2027,18 @@ static int mkv_write_chapters(AVFormatContext *s)
goto fail;
}
chapteratom = start_ebml_master(dyn_cp, MATROSKA_ID_CHAPTERATOM, 0);
put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERUID, uid);
put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMESTART, chapterstart);
put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMEEND, chapterend);
ebml_writer_open_master(&writer, MATROSKA_ID_CHAPTERATOM);
ebml_writer_add_uint(&writer, MATROSKA_ID_CHAPTERUID, uid);
ebml_writer_add_uint(&writer, MATROSKA_ID_CHAPTERTIMESTART, chapterstart);
ebml_writer_add_uint(&writer, MATROSKA_ID_CHAPTERTIMEEND, chapterend);
if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {
chapterdisplay = start_ebml_master(dyn_cp, MATROSKA_ID_CHAPTERDISPLAY, 0);
put_ebml_string(dyn_cp, MATROSKA_ID_CHAPSTRING, t->value);
put_ebml_string(dyn_cp, MATROSKA_ID_CHAPLANG , "und");
end_ebml_master(dyn_cp, chapterdisplay);
ebml_writer_open_master(&writer, MATROSKA_ID_CHAPTERDISPLAY);
ebml_writer_add_string(&writer, MATROSKA_ID_CHAPSTRING, t->value);
ebml_writer_add_string(&writer, MATROSKA_ID_CHAPLANG , "und");
}
end_ebml_master(dyn_cp, chapteratom);
ret = ebml_writer_write(&writer, dyn_cp);
if (ret < 0)
goto fail;
if (tags && mkv_check_tag(c->metadata, MATROSKA_ID_TAGTARGETS_CHAPTERUID)) {
ret = mkv_write_tag(mkv, c->metadata, tags, NULL,

@ -1,5 +1,5 @@
d3a67db17fdca71b9f8cf57c341a031b *tests/data/fate/webm-dash-chapters.webm
111218 tests/data/fate/webm-dash-chapters.webm
01732642a0750de3959fd348092929a5 *tests/data/fate/webm-dash-chapters.webm
111162 tests/data/fate/webm-dash-chapters.webm
#extradata 0: 3469, 0xc6769ddc
#tb 0: 1/1000
#media_type 0: audio

Loading…
Cancel
Save