diff mbox series

[FFmpeg-devel,5/7] avformat/matroskaenc: Make sure UIDs of delayed chapters are != 0

Message ID 20200428083645.4909-5-andreas.rheinhardt@gmail.com
State Accepted
Commit 0aed3002ad3104489d0e378dc9893271d14e0e5b
Headers show
Series [FFmpeg-devel,1/7] avformat/matroskaenc: Write SeekHead when livestreaming | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 28, 2020, 8:36 a.m. UTC
This has previously only been checked if the chapters were initially
available, but not if they were only written in the trailer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
Any Tags pertaining to Chapters added late are currently ignored/lost,
too. The Matroska specifications allow multiple Tags elements (our
demuxer doesn't ...), so one could write a second Tags element at the
end. I'm working on it.

 libavformat/matroskaenc.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 3513a1697a..668b18e9ee 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1437,6 +1437,12 @@  static int mkv_write_chapters(AVFormatContext *s)
     if (!s->nb_chapters || mkv->wrote_chapters)
         return 0;
 
+    for (i = 0; i < s->nb_chapters; i++)
+        if (!s->chapters[i]->id) {
+            mkv->chapter_id_offset = 1;
+            break;
+        }
+
     mkv_add_seekhead_entry(mkv, MATROSKA_ID_CHAPTERS, avio_tell(pb));
 
     ret = start_ebml_master_crc32(&dyn_cp, mkv);
@@ -1863,12 +1869,6 @@  static int mkv_write_header(AVFormatContext *s)
     if (ret < 0)
         return ret;
 
-    for (i = 0; i < s->nb_chapters; i++)
-        if (!s->chapters[i]->id) {
-            mkv->chapter_id_offset = 1;
-            break;
-        }
-
     ret = mkv_write_chapters(s);
     if (ret < 0)
         return ret;
@@ -1879,6 +1879,7 @@  static int mkv_write_header(AVFormatContext *s)
             return ret;
     }
 
+    /* Must come after mkv_write_chapters() because of chapter_id_offset */
     ret = mkv_write_tags(s);
     if (ret < 0)
         return ret;