[FFmpeg-devel] [RFC] Non monotonically increasing timestamps

Stefano Sabatini stefano.sabatini-lala at poste.it
Mon Mar 28 01:30:35 CEST 2011


On date Sunday 2011-03-27 13:04:11 -0400, Mike Scheutzow encoded:
> Stefano Sabatini wrote:
> > On date Monday 2011-03-21 18:26:36 +0100, Stefano Sabatini encoded:
> >> The problem shows up tipically when copying with -vcodec copy, when
> >>  transcoding I suppose DTS is recomputed and so it never results in
> >>  duplicated DTSs.
> >>
> >> So I'm asking if someone can suggest which is a good / the best way
> >>  to fix the DTS duplication problem.
> >>
> >> A simple solution may consists of simply dropping the packets with
> >>  the duplicated DTS, which may result in video corruption (e.g. in
> >>  the abovementioned case, where the packet is a key packet), or fix
> >>  the dts somehow.
> >>
> >> A full-fledged solution may involve the implementation of a
> >> packet-level filtering API (which would be useful also for ffprobe,
> >>  e.g. for selecting only particular packets, e.g.
> >> type=A|V|S/stream=X/PTS>X etc.).
> >
> > Well, I investigated more with the issues. A possible fix may require
> > adding a check in ffmpeg (see attached), which issues a warning and
> > fixes the DTS/PTS accordingly (BUT: maybe this should be moved into
> > the library, and enable the check according to some flag).
> >
> > But then I discover that there is a problem while reading, in certain
> > cases ffmpeg generates incorrect DTSes.
> >
> > Precisely when we have this situation: pkt1: PTS1=DTS1 pkt2:
> > DTS=AV_NOPTS_VALUE
> >
> > in this case FFmpeg (libavformat/utils.c:compute_pkt_fields) sets:
> > DTS2 = pkt.dts = st->last_IP_pts
> >
> > which corresponds to PTS1=DTS1, so we have DTS2 == DTS1 and ffmpeg
> > fails when remuxing the file.
> >
> > Note that the attached code doesn't prevent the error for remuxed
> > MPEG-PS streams (with -*codec copy), indeed the MPEG-PS demuxer
> > sometimes doesn't read the DTS written to the output, DTS is set to
> > AV_NOPTS_VALUE and we're back to the abovementioned situation.
> >
> > A possible solution: add an AVStream.last_IP_dts, and replace the
> > above instruction with: DTS2 = pkt.dts = st->last_IP_dts+1;
> >
> > and/or add sanitizing code: dts = FFMAX(st->last_IP_dts+1, dts);
> >
> > Comments?
> 
> Stefano,
> 
> I added some preliminary investigation to the roundup page. I'm not
> sure that this particular sample is worth the effort to fix.
> 
> I have no specific comment on your patch right now.

Interesting analysis:
https://roundup.ffmpeg.org/issue1551

Indeed the other samples which show the issue are DVB-T captures.

In attachment a tentative patch, I can't test as we have some related
fate regression, it fixes the problem when reading
non_monotone_timestamps20091117.ts.

I also note that with other samples this alone is not sufficient, as
the timestamp correction code in ffmpeg.c sometimes breaks
monotonicity of the input DTSes (and I need the other ffmpeg.c patch).
-- 
FFmpeg = Faithful & Fanciful Multipurpose Programmable Elastic Geisha
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-lavf-avoid-illegal-DTS-interpolation-in-compute_pkt_.patch
Type: text/x-diff
Size: 3375 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110328/09fa55fb/attachment.bin>


More information about the ffmpeg-devel mailing list