[FFmpeg-cvslog] avformat/mov: compute dts_shift with trun cts

Alexandre Sicard git at videolan.org
Fri Jun 7 16:30:42 CEST 2013


ffmpeg | branch: master | Alexandre Sicard <alexandre.sicard at smartjog.com> | Fri Jun  7 14:56:16 2013 +0200| [8912029031d3cf4c42918931104d2ceec21d509a] | committer: Clément Bœsch

avformat/mov: compute dts_shift with trun cts

Some movies have negative composition time offsets in their trun, causing pts <
dts errors. This patch makes use of dts_shift to handle them.

Signed-off-by: Alexandre Sicard <alexandre.sicard at smartjog.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8912029031d3cf4c42918931104d2ceec21d509a
---

 libavformat/mov.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 1c03b15..407b52f 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1839,6 +1839,13 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     return 0;
 }
 
+static void mov_update_dts_shift(MOVStreamContext *sc, int duration)
+{
+    if (duration < 0) {
+        sc->dts_shift = FFMAX(sc->dts_shift, -duration);
+    }
+}
+
 static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     AVStream *st;
@@ -1881,8 +1888,8 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
             return 0;
         }
 
-        if (duration < 0 && i+2<entries)
-            sc->dts_shift = FFMAX(sc->dts_shift, -duration);
+        if (i+2<entries)
+            mov_update_dts_shift(sc, duration);
     }
 
     sc->ctts_count = i;
@@ -2562,6 +2569,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         sc->ctts_data[sc->ctts_count].count = 1;
         sc->ctts_data[sc->ctts_count].duration = (flags & MOV_TRUN_SAMPLE_CTS) ?
                                                   avio_rb32(pb) : 0;
+        mov_update_dts_shift(sc, sc->ctts_data[sc->ctts_count].duration);
         sc->ctts_count++;
         if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
             keyframe = 1;



More information about the ffmpeg-cvslog mailing list