[FFmpeg-devel] [PATCH 09/25] avformat/matroskaenc: Don't waste bytes on ChapterAtoms length fields
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Mon Jan 17 01:03:49 EET 2022
Also check the (user-provided) metadata tags for being too long.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
libavformat/matroskaenc.c | 22 ++++++++++++----------
tests/ref/fate/webm-dash-chapters | 4 ++--
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 236dd3ae8d..fa58f1e171 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2013,12 +2013,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",
@@ -2027,17 +2028,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,
diff --git a/tests/ref/fate/webm-dash-chapters b/tests/ref/fate/webm-dash-chapters
index c2f87b2d7c..95114e6526 100644
--- a/tests/ref/fate/webm-dash-chapters
+++ b/tests/ref/fate/webm-dash-chapters
@@ -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
--
2.32.0
More information about the ffmpeg-devel
mailing list