[FFmpeg-devel] lavf/movdec: flag chapter streams as such, even when not reading them

Submitted by Rodger Combs on Aug. 11, 2017, 9:42 a.m.

Details

Message ID 20170811094207.8080-1-rodger.combs@gmail.com
State New
Headers show

Commit Message

Rodger Combs Aug. 11, 2017, 9:42 a.m.
This allows the use of the `ignore_chapters` option to avoid performing
extra seeks at startup without producing "subtitle" chapter streams.
---
 libavformat/mov.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 63f84be782..5f83c695e6 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5762,6 +5762,7 @@  static void mov_read_chapters(AVFormatContext *s)
     int64_t cur_pos;
     int i, j;
     int chapter_track;
+    int read_contents = (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mov->ignore_chapters;
 
     for (j = 0; j < mov->nb_chapter_tracks; j++) {
         chapter_track = mov->chapter_tracks[j];
@@ -5781,7 +5782,7 @@  static void mov_read_chapters(AVFormatContext *s)
 
         if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
             st->disposition |= AV_DISPOSITION_ATTACHED_PIC | AV_DISPOSITION_TIMED_THUMBNAILS;
-            if (st->nb_index_entries) {
+            if (st->nb_index_entries && read_contents) {
                 // Retrieve the first frame, if possible
                 AVPacket pkt;
                 AVIndexEntry *sample = &st->index_entries[0];
@@ -5801,6 +5802,10 @@  static void mov_read_chapters(AVFormatContext *s)
             st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
             st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA;
             st->discard = AVDISCARD_ALL;
+
+            if (!read_contents)
+                continue;
+
             for (i = 0; i < st->nb_index_entries; i++) {
                 AVIndexEntry *sample = &st->index_entries[i];
                 int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration;
@@ -5851,7 +5856,8 @@  static void mov_read_chapters(AVFormatContext *s)
             }
         }
 finish:
-        avio_seek(sc->pb, cur_pos, SEEK_SET);
+        if (read_contents)
+            avio_seek(sc->pb, cur_pos, SEEK_SET);
     }
 }
 
@@ -6181,9 +6187,11 @@  static int mov_read_header(AVFormatContext *s)
     }
     av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb));
 
+
+    if (mov->nb_chapter_tracks > 0)
+        mov_read_chapters(s);
+
     if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
-        if (mov->nb_chapter_tracks > 0 && !mov->ignore_chapters)
-            mov_read_chapters(s);
         for (i = 0; i < s->nb_streams; i++)
             if (s->streams[i]->codecpar->codec_tag == AV_RL32("tmcd")) {
                 mov_read_timecode_track(s, s->streams[i]);