[FFmpeg-cvslog] movdec: fix dts generation in fragmented files

Janne Grunau git at videolan.org
Fri Feb 3 04:15:59 CET 2012


ffmpeg | branch: master | Janne Grunau <janne-libav at jannau.net> | Thu Feb  2 16:30:27 2012 +0100| [7f19bdc2a29e0f9e3fff0da8c5fc1d2f7f972efc] | committer: Janne Grunau

movdec: fix dts generation in fragmented files

Do not use AVStream's duration for dts generation since it contains in
some cases the duration of the whole file instead of duration of the
samples in the moov. This happens if the mdhd holds the duration of the
whole file but has no entries or a zero duration in its stts.

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

 libavformat/isom.h |    1 +
 libavformat/mov.c  |    5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 16d7776..91fbf75 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -126,6 +126,7 @@ typedef struct MOVStreamContext {
     uint32_t palette[256];
     int has_palette;
     int64_t data_size;
+    int64_t track_end;    ///< used for dts generation in fragmented movie files
 } MOVStreamContext;
 
 typedef struct MOVContext {
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 0ce32e0..3c1927f 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1639,6 +1639,7 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     st->nb_frames= total_sample_count;
     if (duration)
         st->duration= duration;
+    sc->track_end = duration;
     return 0;
 }
 
@@ -2233,7 +2234,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 
     if (flags & 0x001) data_offset        = avio_rb32(pb);
     if (flags & 0x004) first_sample_flags = avio_rb32(pb);
-    dts = st->duration - sc->time_offset;
+    dts    = sc->track_end - sc->time_offset;
     offset = frag->base_data_offset + data_offset;
     distance = 0;
     av_dlog(c->fc, "first sample flags 0x%x\n", first_sample_flags);
@@ -2263,7 +2264,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         sc->data_size += sample_size;
     }
     frag->moof_offset = offset;
-    st->duration = dts + sc->time_offset;
+    st->duration = sc->track_end = dts + sc->time_offset;
     return 0;
 }
 



More information about the ffmpeg-cvslog mailing list