[FFmpeg-devel] [PATCH] lavf/mov.c: Add -editlist_fix_index option for mov format.

Sasi Inguva isasi at google.com
Fri Dec 30 01:04:07 EET 2016


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

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 12cefc9..ff3a234 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -225,6 +225,7 @@ typedef struct MOVContext {
     unsigned int nb_chapter_tracks;
     int use_absolute_path;
     int ignore_editlist;
+    int editlist_fix_index;
     int ignore_chapters;
     int seek_individually;
     int64_t next_root_atom; ///< offset of the next root atom
diff --git a/libavformat/mov.c b/libavformat/mov.c
index d1b9291..98f8c4c 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3227,7 +3227,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
     uint64_t stream_size = 0;
 
     if (sc->elst_count) {
-        int i, edit_start_index = 0;
+        int i, edit_start_index = 0, multiple_edits = 0;
         int64_t empty_duration = 0; // empty duration of the first edit list entry
         int64_t start_time = 0; // start time of the media
 
@@ -3240,15 +3240,28 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
                 edit_start_index = 1;
             } else if (i == edit_start_index && e->time >= 0) {
                 start_time = e->time;
+            } else {
+                multiple_edits = 1;
             }
         }
 
+        if (multiple_edits && !mov->editlist_fix_index)
+            av_log(mov->fc, AV_LOG_WARNING, "multiple edit list entries, "
+                   "Use -editlist_fix_index to correctly decode otherwise "
+                   "a/v desync might occur\n");
+
         /* adjust first dts according to edit list */
         if ((empty_duration || start_time) && mov->time_scale > 0) {
             if (empty_duration)
                 empty_duration = av_rescale(empty_duration, sc->time_scale, mov->time_scale);
             sc->time_offset = start_time - empty_duration;
+            if (!mov->editlist_fix_index)
+                current_dts = -sc->time_offset;
         }
+
+        if (!multiple_edits && !mov->editlist_fix_index &&
+            st->codecpar->codec_id == AV_CODEC_ID_AAC && start_time > 0)
+            sc->start_pad = start_time;
     }
 
     /* only use old uncompressed audio chunk demuxing when stts specifies it */
@@ -3482,8 +3495,10 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
         }
     }
 
-    // Fix index according to edit lists.
-    mov_fix_index(mov, st);
+    if (!mov->ignore_editlist && mov->editlist_fix_index) {
+        // Fix index according to edit lists.
+        mov_fix_index(mov, st);
+    }
 }
 
 static int test_same_origin(const char *src, const char *ref) {
@@ -6349,6 +6364,8 @@ static const AVOption mov_options[] = {
         0, 1, FLAGS},
     {"ignore_editlist", "", OFFSET(ignore_editlist), AV_OPT_TYPE_BOOL, {.i64 = 0},
         0, 1, FLAGS},
+    {"editlist_fix_index", "", OFFSET(editlist_fix_index), AV_OPT_TYPE_BOOL, {.i64 = 1},
+        0, 1, FLAGS},
     {"ignore_chapters", "", OFFSET(ignore_chapters), AV_OPT_TYPE_BOOL, {.i64 = 0},
         0, 1, FLAGS},
     {"use_mfra_for",
-- 
2.8.0.rc3.226.g39d4020



More information about the ffmpeg-devel mailing list