[FFmpeg-cvslog] r18810 - in trunk/libavformat: isom.h mov.c

bcoudurier subversion
Wed May 13 09:55:03 CEST 2009


Author: bcoudurier
Date: Wed May 13 09:55:03 2009
New Revision: 18810

Log:
Parse 'cslg' atom to retrieve dts shift when 'ctts' duration is negative.
We have now dts <= pts, note that for some B frames dts+1 == pts can happen
if a crappy timebase is used instead of correct /1001.

Modified:
   trunk/libavformat/isom.h
   trunk/libavformat/mov.c

Modified: trunk/libavformat/isom.h
==============================================================================
--- trunk/libavformat/isom.h	Wed May 13 08:06:59 2009	(r18809)
+++ trunk/libavformat/isom.h	Wed May 13 09:55:03 2009	(r18810)
@@ -115,9 +115,10 @@ typedef struct MOVStreamContext {
     unsigned drefs_count;
     MOVDref *drefs;
     int dref_id;
-    int wrong_dts; ///< dts are wrong due to negative ctts
+    int wrong_dts; ///< dts are wrong due to huge ctts offset (iMovie files)
     int width;  ///< tkhd width
     int height; ///< tkhd height
+    int dts_shift; ///< dts shift when ctts is negative
 } MOVStreamContext;
 
 typedef struct MOVContext {

Modified: trunk/libavformat/mov.c
==============================================================================
--- trunk/libavformat/mov.c	Wed May 13 08:06:59 2009	(r18809)
+++ trunk/libavformat/mov.c	Wed May 13 09:55:03 2009	(r18810)
@@ -1236,6 +1236,31 @@ static int mov_read_stts(MOVContext *c, 
     return 0;
 }
 
+static int mov_read_cslg(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
+{
+    AVStream *st;
+    MOVStreamContext *sc;
+
+    if (c->fc->nb_streams < 1) // will happen with jp2 files
+        return 0;
+    st = c->fc->streams[c->fc->nb_streams-1];
+    sc = st->priv_data;
+
+    get_be32(pb); // version + flags
+
+    sc->dts_shift = get_be32(pb);
+    dprintf(c->fc, "dts shift %d\n", sc->dts_shift);
+
+    sc->time_rate= av_gcd(sc->time_rate, FFABS(sc->dts_shift));
+
+    get_be32(pb); // least dts to pts delta
+    get_be32(pb); // greatest dts to pts delta
+    get_be32(pb); // pts start
+    get_be32(pb); // pts end
+
+    return 0;
+}
+
 static int mov_read_ctts(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
 {
     AVStream *st = c->fc->streams[c->fc->nb_streams-1];
@@ -1259,10 +1284,6 @@ static int mov_read_ctts(MOVContext *c, 
         int count    =get_be32(pb);
         int duration =get_be32(pb);
 
-        if (duration < 0) {
-            sc->wrong_dts = 1;
-            st->codec->has_b_frames = 1;
-        }
         sc->ctts_data[i].count   = count;
         sc->ctts_data[i].duration= duration;
 
@@ -1303,6 +1324,9 @@ static void mov_build_index(MOVContext *
         unsigned int distance = 0;
         int key_off = sc->keyframes && sc->keyframes[0] == 1;
 
+        sc->dts_shift /= sc->time_rate;
+        current_dts -= sc->dts_shift;
+
         st->nb_frames = sc->sample_count;
         for (i = 0; i < sc->chunk_count; i++) {
             current_offset = sc->chunk_offsets[i];
@@ -1809,6 +1833,7 @@ static int mov_read_elst(MOVContext *c, 
 static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('a','v','s','s'), mov_read_extradata },
 { MKTAG('c','o','6','4'), mov_read_stco },
+{ MKTAG('c','s','l','g'), mov_read_cslg },
 { MKTAG('c','t','t','s'), mov_read_ctts }, /* composition time to sample */
 { MKTAG('d','i','n','f'), mov_read_default },
 { MKTAG('d','r','e','f'), mov_read_dref },
@@ -1988,7 +2013,7 @@ static int mov_read_packet(AVFormatConte
     pkt->dts = sample->timestamp;
     if (sc->ctts_data) {
         assert(sc->ctts_data[sc->ctts_index].duration % sc->time_rate == 0);
-        pkt->pts = pkt->dts + sc->ctts_data[sc->ctts_index].duration / sc->time_rate;
+        pkt->pts = pkt->dts + sc->dts_shift + sc->ctts_data[sc->ctts_index].duration / sc->time_rate;
         /* update ctts context */
         sc->ctts_sample++;
         if (sc->ctts_index < sc->ctts_count &&



More information about the ffmpeg-cvslog mailing list