Commit 89120290 authored by Alexandre Sicard's avatar Alexandre Sicard Committed by 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: 's avatarAlexandre Sicard <alexandre.sicard@smartjog.com>
parent c59c0488
...@@ -1839,6 +1839,13 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) ...@@ -1839,6 +1839,13 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0; 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) static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{ {
AVStream *st; AVStream *st;
...@@ -1881,8 +1888,8 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) ...@@ -1881,8 +1888,8 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0; return 0;
} }
if (duration < 0 && i+2<entries) if (i+2<entries)
sc->dts_shift = FFMAX(sc->dts_shift, -duration); mov_update_dts_shift(sc, duration);
} }
sc->ctts_count = i; sc->ctts_count = i;
...@@ -2562,6 +2569,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) ...@@ -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].count = 1;
sc->ctts_data[sc->ctts_count].duration = (flags & MOV_TRUN_SAMPLE_CTS) ? sc->ctts_data[sc->ctts_count].duration = (flags & MOV_TRUN_SAMPLE_CTS) ?
avio_rb32(pb) : 0; avio_rb32(pb) : 0;
mov_update_dts_shift(sc, sc->ctts_data[sc->ctts_count].duration);
sc->ctts_count++; sc->ctts_count++;
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
keyframe = 1; keyframe = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment