After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 691481 - avidemux: a/v sync off on sample video when activated in push mode
avidemux: a/v sync off on sample video when activated in push mode
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
1.x
Other Linux
: Normal normal
: 1.1.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-01-10 15:28 UTC by Arnaud Vrac
Modified: 2013-04-23 09:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (1.05 KB, patch)
2013-02-14 21:12 UTC, Matej Knopp
none Details | Review
Patch (3.92 KB, patch)
2013-02-15 15:02 UTC, Matej Knopp
none Details | Review
baseparse: more inter-timestamp tracking (1.36 KB, patch)
2013-02-17 17:28 UTC, Mark Nauwelaerts
none Details | Review
baseparse: more inter-timestamp tracking (1.36 KB, patch)
2013-02-17 22:56 UTC, Mark Nauwelaerts
none Details | Review
baseparse: more inter-timestamp tracking (1.76 KB, patch)
2013-02-17 22:57 UTC, Mark Nauwelaerts
none Details | Review
baseparse: more inter-timestamp tracking (1.76 KB, patch)
2013-02-25 20:46 UTC, Mark Nauwelaerts
none Details | Review
baseparse: more inter-timestamp tracking (4.33 KB, patch)
2013-02-26 18:59 UTC, Mark Nauwelaerts
committed Details | Review

Description Arnaud Vrac 2013-01-10 15:28:58 UTC
The following pipeline has avsync off by 500ms, on 1.0.5 or git master:

gst-launch playbin uri=http://absolut.zogzog.org/share/samples/avi/s7e3.avi

This is because avidemux outputs invalid timestamps for audio in push mode.

pull mode:

chain (23040 bytes, dts: 0:00:00.000000000, pts: 0:00:00.000000000, duration: 0:00:00.024000000, offset: -1, offset_end: -1, flags: 00000040 discont )
chain (1152 bytes, dts: 0:00:00.024000000, pts: 0:00:00.024000000, duration: 0:00:00.480000000, offset: -1, offset_end: -1, flags: 00000000 )
chain (2304 bytes, dts: 0:00:00.504000000, pts: 0:00:00.504000000, duration: 0:00:00.024000000, offset: -1, offset_end: -1, flags: 00000000 )
chain (2304 bytes, dts: 0:00:00.528000000, pts: 0:00:00.528000000, duration: 0:00:00.048000000, offset: -1, offset_end: -1, flags: 00000000 )
chain (1152 bytes, dts: 0:00:00.576000000, pts: 0:00:00.576000000, duration: 0:00:00.048000000, offset: -1, offset_end: -1, flags: 00000000 )

push mode:

chain (23040 bytes, dts: 0:00:00.000000000, pts: none, duration: 0:00:00.024000000, offset: -1, offset_end: -1, flags: 00000040 discont )
chain (1152 bytes, dts: 0:00:00.024000000, pts: none, duration: 0:00:00.024000000, offset: -1, offset_end: -1, flags: 00000000 )
chain (2304 bytes, dts: 0:00:00.048000000, pts: none, duration: 0:00:00.024000000, offset: -1, offset_end: -1, flags: 00000000 )
chain (2304 bytes, dts: 0:00:00.072000000, pts: none, duration: 0:00:00.024000000, offset: -1, offset_end: -1, flags: 00000000 )
chain (1152 bytes, dts: 0:00:00.096000000, pts: none, duration: 0:00:00.024000000, offset: -1, offset_end: -1, flags: 00000000 )
Comment 1 Tim-Philipp Müller 2013-01-10 15:42:27 UTC
I wonder if there's already a bug for this, but maybe it only came up on irc
Comment 2 Mark Nauwelaerts 2013-02-09 11:35:20 UTC
Problem is both in avidemux and baseparse.

The former messes up timestamping for VBR audio in push mode (essentially assuming each chunk to consist of 1 frame).  The latter fails in PTS interpolating/mirroring of DTS (since no PTS is provided by avidemux in push mode).

Fixed by following commits:

commit 314400d45af1a9718a7209a9c162c7a7ee9d95f7
Author: Mark Nauwelaerts <mnauw@users.sourceforge.net>
Date:   Sat Feb 9 12:32:02 2013 +0100

    baseparse: improve PTS interpolating
    
    ... and tracking of DTS.  Fixes cases where PTS is locked on to the
    DTS of an incoming buffer with no PTS with invalid data, leading to
    no outgoing PTS (since it is not allowed smaller than DTS).
    
    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=691481

commit f0645b79c58a162619f2fc2d030971cce4acd514
Author: Mark Nauwelaerts <mnauw@users.sourceforge.net>
Date:   Fri Feb 8 21:28:02 2013 +0100

    avidemux: proper position reporting and push mode timestamping
    
    ... and align current_total semantics in push and pull mode,
    which tracks bytes for CBR and blocks for VBR.
    
    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=691481
Comment 3 Tim-Philipp Müller 2013-02-09 11:47:18 UTC
Might the baseparse commit also help with bug #690152 (which is mis-titled IIRC) ?
Comment 4 Arnaud Vrac 2013-02-09 11:50:03 UTC
Tim: the patch I posted in #690152 does fix the bug, it just needed some review (although it was pushed in master already).
Comment 5 Matej Knopp 2013-02-14 20:34:40 UTC
This patch
http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=314400d45af1a9718a7209a9c162c7a7ee9d95f7
breaks audio timestamps. I have file (MKV with DTS audio) for which it generates non monotonous timestamps
Comment 6 Matej Knopp 2013-02-14 21:12:11 UTC
Created attachment 236160 [details] [review]
Patch

This code
if (next_pts >= parse->priv->next_dts)
        parse->priv->next_pts = next_pts;
doesn't really set priv->next_pts to anything because few lines above 
priv->next_pts is set to GST_CLOCK_TIME_NONE
Comment 7 Tim-Philipp Müller 2013-02-14 22:37:02 UTC
Any chance you could make that file available for us (for future testing/reference)?
Comment 8 Mark Nauwelaerts 2013-02-14 23:08:40 UTC
Erm, yes, a few lines above priv->next_pts is set to _NONE, but AFAICS that particular one is not involved in the comparison mentioned (only next_pts and priv->next_dts), so I am not quite clear on the "because" part and the relation there ...
Comment 9 Matej Knopp 2013-02-14 23:25:30 UTC
You're correct. I was staring at the code for too long. 
This is probably not the right fix. I'm not sure how to make test case for this, as it happens during seeking in a large MKV file. The bug causes the DCA parser to output non monotonous timestamps, sometimes with PTS < DTS.
Comment 10 Matej Knopp 2013-02-15 01:15:33 UTC
The problem here seems to be that priv->next_dts is set to segment->start on seek, but PTS of first buffer is before segment->start.

so priv->next_pts is set from first buffer (after seek), priv->next_dts is set from segment start, which results in priv->next_pts < priv->next_pts.

That doesn't seem right. How is this supposed to work? Why is next_dts set to segment start?
Comment 11 Mark Nauwelaerts 2013-02-15 06:38:02 UTC
It is set to segment start so we can start guestimating timestamps from that point in case buffers have no ts (usually used in the 0 case).

In any case, if incoming buffers have ts, then chain (via adapter) should be picking up those ...
Comment 12 Matej Knopp 2013-02-15 07:40:48 UTC
The issue in my case seems to be that on seek, the DTS start from segment->start, while PTS start from segment->start - n (first buffer PTS).  The buffers only have PTS set.

If the incoming buffer has PTS (but not DTS), shouldn't the interpolated DTS start from that PTS (instead of segment->start, which is completely arbitrary, as the segment->start time doesn't have to be same as first  buffer?)
Comment 13 Matej Knopp 2013-02-15 15:02:02 UTC
Created attachment 236248 [details] [review]
Patch

This patch is not really meant to be committed, it just demonstrates what is going wrong in my case and fixes it.

After seek, I get incoming buffers with PTS < segment->start and no DTS. In case like this, baseparse starts interpolating dts from segment->start, which means that the interpolated dts > buffer PTS.
Comment 14 Mark Nauwelaerts 2013-02-17 17:28:40 UTC
Created attachment 236468 [details] [review]
baseparse: more inter-timestamp tracking

Given that receiving a segment event sets priv->prev_dts/_pts to _NONE, this patch should have the PTS picked up from the DTS of incoming buffers if no valid PTS has been seen on the latter.

If I read things right, this should fix the case described and is along the lines of what is suggested in Comment #12.

It could also simply be said here that matroskademux is wrong or incomplete in that it apparently still simply/only sets _TIMESTAMP rather than anything _DTS/_PTS, and the same might be so for quite some demuxers / baseparse upstream elements out there.

As such, the more general problem in baseparse is what to do with 2 sort-of-independent timelines (PTS/DTS) which may or may not be provided in all sorts of (in)valid combinations on the input.

This patch turns interpolate_pts almost into a "equalize_ts" option, and it might make sense to have such baseparse option (and use that in the 'if' of this patch).  That would probably (?) have all audio cases deal with (legacy) upstream input (equalizing pts / dts, ok for audio typically). OTOH, that would probably not go well for the video cases, which would have to run without that option enabled.  No idea though how to handle all sorts of incomplete input in that case then ...  Best there is to make sure that demuxers always at least set _DTS in stead of _TIMESTAMP, since that is likely the known ts as they provide data in decoding order.
Comment 15 Matej Knopp 2013-02-17 18:58:22 UTC
I don't understand the very first paragraph; There is NO DTS on incoming buffers in my case, only PTS. The PTS doesn't need to be picked, we already get it from demuxer.

It's been a while since I was reading matroska specs, but IIRC matroska doesn't store DTS, only PTS. At very least for video streams this is true, as the timestamps from matroska are not monotonous (so it's easy to confirm).

I don't really understand the point of interpolating the DTS, especially from segment start. Segment start does not guarantee that the incoming buffers are within the segment boundaries. Also, if decoder really relies on having proper DTS (i.e. for buffer under/overflow), the interpolated DTSs probably won't be very helpful.

Just to recap, the problem in my case:

* Incoming buffers only have PTS (no DTS), matroska doesn't store DTS
* PTS gets interpolated from the PTS value of first buffer
* DTS gets interpolated from value of segment->start
* (segment->start) > (PTS of first buffer) because the seek goes 
   to last keyframe before segment start, thus on output, I get buffers
   with DTS > PTS, which breaks number of things
Comment 16 Matej Knopp 2013-02-17 19:02:34 UTC
Actually, the end of my previous comment was not exactly correct, what I really get is audio buffers with non monotonous timestamps, because the baseparse sometimes sets output buffer PTS to calculated DTS .
Comment 17 Matej Knopp 2013-02-17 19:23:52 UTC
Btw, your patch doesn't really work for me, because for some reason parse->priv->prev_dts is always 0 (it's not set to GST_CLOCK_TIME_NONE), so the condition !GST_CLOCK_TIME_IS_VALID (parse->priv->prev_dts) is never true.
Without the condition it works.
Comment 18 Mark Nauwelaerts 2013-02-17 22:56:51 UTC
Created attachment 236501 [details] [review]
baseparse: more inter-timestamp tracking

Hm, yes, first paragraph has PTS and DTS switched.

Updated version with a few tweaks (such as minding to set _NONE).

It may well be that matroska specs refer to _PTS, but the rest of the explanation comes down to saying that baseparse will stay in trouble with ts handling (on 2 timelines) unless we e.g. accept that PTS = DTS for audio and handle it that way.  That does not cover the other cases, but not sure how well those can be covered with limited baseparse semantic awareness in that regard.
Comment 19 Mark Nauwelaerts 2013-02-17 22:57:57 UTC
Created attachment 236502 [details] [review]
baseparse: more inter-timestamp tracking

Erm, now really the updated version ...
Comment 20 Matej Knopp 2013-02-18 00:30:34 UTC
Thanks Mark, the new patch seems to be working. I'm perfectly fine with assuming PTS = DTS for audio, I didn't realize you only meant that for audio.
Comment 21 Mark Nauwelaerts 2013-02-25 20:46:20 UTC
Created attachment 237392 [details] [review]
baseparse: more inter-timestamp tracking

To try and wrap this up, attached patch is a slightly evolved version of the previous one, which makes the behaviour there (and in related patch before that) not dependent on the pts_interpolate setting, which seems not suited.

Rather, another setting, infer_ts is added (on by default), which allows baseparse to estimate PTS/DTS from each other, which is effectively being done here (and before as well).

Comments (such as on naming) welcome, and if no objections will be committing this patch to resolve this ...
Comment 22 Matej Knopp 2013-02-26 15:10:43 UTC
Is this the right patch? It seems like the old one.
Comment 23 Mark Nauwelaerts 2013-02-26 18:59:47 UTC
Created attachment 237467 [details] [review]
baseparse: more inter-timestamp tracking

Indeed, sigh, this time the intended one ...
Comment 24 Matej Knopp 2013-02-26 22:58:36 UTC
Seems to be working fine for me.
Comment 25 Arnaud Vrac 2013-03-18 14:40:23 UTC
The commited patch breaks backwards seek in mp3 files:

dts: 0:00:22.987754240, pts: 0:00:22.987754240, duration: 0:00:00.026122448
dts: 0:00:23.013876688, pts: 0:00:23.013876688, duration: 0:00:00.026122448                                                                                                                    
dts: 0:00:23.039999136, pts: 0:00:23.039999136, duration: 0:00:00.026122448
dts: 0:00:23.066121584, pts: 0:00:23.066121584, duration: 0:00:00.026122448

SEEK TO 0

dts: 0:00:00.000000000, pts: 0:00:23.118366480, duration: 0:00:00.026122448
dts: 0:00:00.026122448, pts: 0:00:23.144488928, duration: 0:00:00.026122448
dts: 0:00:00.052244896, pts: 0:00:23.170611376, duration: 0:00:00.026122448
dts: 0:00:00.078367344, pts: 0:00:23.196733824, duration: 0:00:00.026122448
Comment 26 Arnaud Vrac 2013-03-22 13:38:28 UTC
Mark's patch (baseparse: more inter-timestamp tracking) does not help for mp3 btw
Comment 27 Mark Nauwelaerts 2013-03-27 18:00:54 UTC
Indeed, that problem seems to have been elsewhere.  Following commit should take care of it:

commit 6ddbaaa95cf47ca353ae6d43feb2f75627d5849b
Author: Mark Nauwelaerts <mnauw@users.sourceforge.net>
Date:   Wed Mar 27 18:25:08 2013 +0100

    baseparse: reset next_pts upon SEGMENT event
    
    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=691481

Since no objections so far, also:

commit 76acdee9087c4b569cc500057d22ab9a44892bea
Author: Mark Nauwelaerts <mnauw@users.sourceforge.net>
Date:   Tue Feb 26 19:58:49 2013 +0100

    baseparse: more inter-timestamp tracking
    
    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=691481
Comment 28 Sebastian Dröge (slomo) 2013-04-23 08:14:15 UTC
This breaks A/V sync and smooth video playback in some files. A/V sync works again when not calling set_frame_rate() in the video parsers, smooth video playback is broken in any case.

commit 76acdee9087c4b569cc500057d22ab9a44892bea
Author: Mark Nauwelaerts <mnauw@users.sourceforge.net>
Date:   Tue Feb 26 19:58:49 2013 +0100

    baseparse: more inter-timestamp tracking

    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=691481
Comment 29 Sebastian Dröge (slomo) 2013-04-23 08:42:11 UTC
Note: it's the combination of that change and using the framerate to guess buffer durations that makes things fail
Comment 30 Sebastian Dröge (slomo) 2013-04-23 09:50:27 UTC
commit f27a3e12f6d35695ebbf2edc5aa4937c2e7c3843
Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
Date:   Tue Apr 23 11:47:54 2013 +0200

    baseparse: Only infer TS if PTS interpolation is enabled
    
    Otherwise this is breaking timestamps of formats that
    need reordering.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=597662


Also related to this:
commit b7d63d3fb1f71d8ebf822df50c516dda5967af7b
Author: Jan Schmidt <thaytan@noraisin.net>
Date:   Wed Sep 12 22:58:04 2012 -0700

    videoparsers: Disable PTS interpolation in the base parse class
    
    All these formats have re-ordered PTS which the base class gets
    wrong. It's better to leave them blank and let the decoder sort it
    out. Better yet would be to track and interpolate the timestamps
    in the subclasses (FIXME)