From 8912029031d3cf4c42918931104d2ceec21d509a Mon Sep 17 00:00:00 2001 From: Alexandre Sicard Date: Fri, 7 Jun 2013 14:56:16 +0200 Subject: [PATCH] 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 --- libavformat/mov.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 1c03b1553a..407b52f342 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+2dts_shift = FFMAX(sc->dts_shift, -duration); + if (i+2ctts_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;