[FFmpeg-devel] [PATCH] mov: fix DTS calculation for samples with negative stts duration

Michael Niedermayer michaelni at gmx.at
Fri May 29 18:52:06 CEST 2015


On Fri, May 29, 2015 at 03:27:36PM +0200, Andreas Cadhalpun wrote:
> On 29.05.2015 05:03, Michael Niedermayer wrote:
> > On Thu, May 28, 2015 at 06:49:02PM +0200, Andreas Cadhalpun wrote:
> >> @@ -2522,7 +2519,27 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
> >>  
> >>                  current_offset += sample_size;
> >>                  stream_size += sample_size;
> >> +
> >> +                /* A negative sample duration is invalid based on the spec,
> >> +                 * but some samples need it to correct the DTS. */
> >> +                if (sc->stts_data[stts_index].duration < 0) {
> >> +                    av_log(mov->fc, AV_LOG_WARNING,
> >> +                           "Invalid SampleDelta %d in STTS, at %d st:%d\n",
> >> +                           sc->stts_data[stts_index].duration, stts_index,
> >> +                           st->index);
> >> +                    dts_correction += sc->stts_data[stts_index].duration - 1;
> >> +                    sc->stts_data[stts_index].duration = 1;
> >> +                }
> >>                  current_dts += sc->stts_data[stts_index].duration;
> >> +                if (current_dts + dts_correction > last_dts) {
> >> +                    current_dts += dts_correction;
> >> +                    dts_correction = 0;
> >> +                } else {
> >> +                    /* Avoid creating non-monotonous DTS */
> >> +                    dts_correction += current_dts - last_dts - 1;
> >> +                    current_dts = last_dts + 1;
> > 
> > this would enfore strict monotonicity not just monotoicity
> > dts[i-1] == dts[i] was previously left as is
> > is there a reason to change this ?
> 
> If the dts doesn't change, the packet duration is passed through. This
> leads to a wrong packet duration, when dts_correction is in effect.
> 
> > Ive not checked what the spec says about it but i suspect there are
> > files which have such dts
> 
> I haven't found an explicit mentioning of duration 0 in the spec, but
> if you think it's better not to change how this was handled previously
> for samples which didn't have a negative duration, one can simply
> add '!dts_correction ||' before the 'current_dts + dts_correction > last_dts'
> check. Attached patch includes this change.
> 
> Best regards,
> Andreas
> 

>  mov.c |   29 +++++++++++++++++++++++------
>  1 file changed, 23 insertions(+), 6 deletions(-)
> d6041f950d69f7b2717d4df347cf0f6db4ccdd58  0001-mov-fix-DTS-calculation-for-samples-with-negative-st.patch
> From 266bb402dcc6c53200637c8c37572239192bb0d3 Mon Sep 17 00:00:00 2001
> From: Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com>
> Date: Wed, 27 May 2015 23:57:50 +0200
> Subject: [PATCH] mov: fix DTS calculation for samples with negative stts
>  duration
> 
> A negative sample duration is invalid according to the spec, but there
> are samples that use it for the DTS calculation, e.g.:
> http://files.1f0.de/samples/mp4-negative-stts-problem.mp4
> 
> These currently get out of A/V sync.
> 
> Also change the logging type to AV_LOG_WARNING, because decoding the
> sample can continue.

LGTM

thanks

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150529/89dceeaf/attachment.asc>


More information about the ffmpeg-devel mailing list