[FFmpeg-devel] [PATCH] lavf/mov.c: Set skip_samples according to first edit list, when -ignore_editlist is set.

Sasi Inguva isasi at google.com
Sat Nov 12 08:02:28 EET 2016


Signed-off-by: Sasi Inguva <isasi at google.com>
---
 libavformat/isom.h |  2 ++
 libavformat/mov.c  | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index d684502..6a8a4e3 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -164,6 +164,8 @@ typedef struct MOVStreamContext {
     uint32_t tmcd_flags;  ///< tmcd track flags
     int64_t track_end;    ///< used for dts generation in fragmented movie files
     int start_pad;        ///< amount of samples to skip due to enc-dec delay
+    int first_elist_start_time;   ///< first edit list start time.
+    int num_non_empty_elst;       ///< number of non empty edit lists.
     unsigned int rap_group_count;
     MOVSbgp *rap_group;
 
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 9ec7d03..676694e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3245,6 +3245,12 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
         }
     }
 
+    /* Adjust skip_samples correctly when ignore_editlist is set, to support gapless playback */
+    if (mov->ignore_editlist && sc->num_non_empty_elst <= 1 &&
+        st->codecpar->codec_id == AV_CODEC_ID_AAC && sc->first_elist_start_time > 0) {
+        sc->start_pad = sc->first_elist_start_time;
+    }
+
     /* only use old uncompressed audio chunk demuxing when stts specifies it */
     if (!(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
           sc->stts_count == 1 && sc->stts_data[0].duration == 1)) {
@@ -4424,9 +4430,11 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     MOVStreamContext *sc;
     int i, edit_count, version;
 
-    if (c->fc->nb_streams < 1 || c->ignore_editlist)
+    if (c->fc->nb_streams < 1)
         return 0;
     sc = c->fc->streams[c->fc->nb_streams-1]->priv_data;
+    sc->first_elist_start_time = 0;
+    sc->num_non_empty_elst = 0;
 
     version = avio_r8(pb); /* version */
     avio_rb24(pb); /* flags */
@@ -4463,9 +4471,21 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
                    c->fc->nb_streams-1, i, e->time);
             return AVERROR_INVALIDDATA;
         }
+
+        if (!sc->first_elist_start_time && e->time > 0) {
+            sc->first_elist_start_time = e->time;
+        }
+
+        if (e->time >= 0) {
+            sc->num_non_empty_elst++;
+        }
     }
     sc->elst_count = i;
 
+    if (c->ignore_editlist) {
+        av_freep(&sc->elst_data);
+        sc->elst_count = 0;
+    }
     return 0;
 }
 
-- 
2.8.0.rc3.226.g39d4020



More information about the ffmpeg-devel mailing list