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 705066 - mpegvideoparse: fix timestamps
mpegvideoparse: fix timestamps
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other All
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-07-29 08:35 UTC by Matej Knopp
Modified: 2018-11-03 13:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Filter that fixes mpeg timestamps (4.99 KB, application/zip)
2013-07-29 08:35 UTC, Matej Knopp
Details
Filter that fixes mpeg timestamps (4.80 KB, application/zip)
2013-07-29 16:23 UTC, Matej Knopp
Details
Updated filter (4.80 KB, application/zip)
2013-07-29 16:37 UTC, Matej Knopp
Details
Updated filter (5.19 KB, application/zip)
2013-07-30 09:51 UTC, Matej Knopp
Details

Description Matej Knopp 2013-07-29 08:35:52 UTC
Created attachment 250353 [details]
Filter that fixes mpeg timestamps

Mpegvideoparse currently doesn't do anything about fixing broken / missing timestamps. This affects playback for many files in my case. I'm currently using custom filter after mpegvideoparse to do this, but perhaps the functionality should be added to the parser?

If someone could look at the code and confirm I can provide a patch. Although unlike my filter mpegvideoparser probably can't get away with throwing away D frames so this will need to be addressed. Does anyone have a stream with D frames?
Comment 1 Olivier Crête 2013-07-29 11:14:43 UTC
Funny thing, I just updated the patch to do just that at bug #632222.. Well, if you use the second patch and use "retimestamp=TRUE", but it's still not perfect. I think that in the general case, one should use the timestamps from the upper layer instead of from inside the MPEG2-ES stream, if the upper layers provide useful timestamps.

*** This bug has been marked as a duplicate of bug 632222 ***
Comment 2 Matej Knopp 2013-07-29 11:20:50 UTC
This patch really works differently than yours. I calculate the timestamps by figuring out the presentation order of the frames and then interpolating the time. It should work for all cases.
Comment 3 Matej Knopp 2013-07-29 11:24:56 UTC
Also your patch doesn't seem to deal with with frame reordering at all. I don't take the timestamp from GOP header, it should come from the demuxer. But the timestamps from demuxer are often jumpy or missing (usually for reordered frames), that's what needs to be fixed.
Comment 4 Matej Knopp 2013-07-29 11:26:21 UTC

*** This bug has been marked as a duplicate of bug 632222 ***
Comment 5 Olivier Crête 2013-07-29 11:31:22 UTC
I'm trying to address the case where the MPEG2-ES stream is transmitted as-is (not muxed), that's why I read the timestamps from the GOP. I would generally assume that the timestamps from the demuxer, etc are better. For example, rtpjitterbuffer and tsdemux apply clock skew correction (for the live playback case).

And by using the temporal reference number (TSN), you don't have to worry about decoding-vs-presentation order, the TSN are presentation times. Only adding up the durations, which was my initial approach, means that you have to keep up with P-frames, etc. Also means it won't work if you have any losses
Comment 6 Matej Knopp 2013-07-29 11:33:16 UTC
Actually, I spoke to soon. I see you take the tsn from picheader, I used to do the same thing before but had bad experience with it for some files.
Comment 7 Matej Knopp 2013-07-29 12:02:20 UTC
Also simply calculating PTS using TSN * duration_from_framerate will not work for telecine.
Comment 8 Matej Knopp 2013-07-29 14:01:51 UTC
Anyway, regardless of how the timestamps are determined, the question is whether the parser is allowed to change timestamps at all? Can it fill missing timestamps? What if there are already timestamps from upstream but are not perfect? (i.e. I've seen wrong timestamps on reordered frames)
Comment 9 Matej Knopp 2013-07-29 15:37:42 UTC
I think I might be overly pessimistic about the container timestamps. I changed the code to just fill in empty timestamps (don't change container timestamps) and have no problem with my test videos so far.
Comment 10 Matej Knopp 2013-07-29 16:23:16 UTC
Created attachment 250381 [details]
Filter that fixes mpeg timestamps

Updated version. Does not overwrite demuxer timestamps (only fills in missing ones). Does not introduce latency if timestamps are present on input buffers.
Comment 11 Matej Knopp 2013-07-29 16:37:57 UTC
Created attachment 250385 [details]
Updated filter

Updated version. Does not overwrite demuxer timestamps (only fills in missing ones). Does not introduce latency if timestamps are present on input buffers.
Comment 12 Edward Hervey 2013-07-30 04:57:58 UTC
I think it's quite unlikely this would go in as a separate element considering we already have mpegvideoparse :( Can you make it a patch against current mpegvideoparse from git ?
Comment 13 Matej Knopp 2013-07-30 09:51:18 UTC
Created attachment 250439 [details]
Updated filter

Fixed some problems from last iteration.
Comment 14 Matej Knopp 2013-07-30 09:52:53 UTC
(In reply to comment #12)
> I think it's quite unlikely this would go in as a separate element considering
> we already have mpegvideoparse :( Can you make it a patch against current
> mpegvideoparse from git ?

The issue is, that at this point I'm not entirely sure what the videoparse needs to be doing. Having as separate filter makes it much easier to test. Once the filter does what parser should be doing (which I'm still not sure what that is - will explain in next comment) I can make it a patch for mpegvideoparse.
Comment 15 Matej Knopp 2013-07-30 10:06:19 UTC
So currently the way the filter works it only adds missing timestamps, doesn't touch timestamps that come from upstream. This works well for most files (where the timestamps from upstream are sparse, but correct). 

Some files are not so nice however. For example
https://s3.amazonaws.com/MatejK/Samples/V.VOB

It has only timestamps on i-frames (which is usual). The timestamp of second iFrame is 
0:28:19.420000000
But the actual presentation time (when calculated from all frames that are displayed before it) is 
0:28:19.940000000

In current state, the filter ignores the calculated value and just uses the one from upstream. This will of course cause errors during playback, as the timestamps jump back.

Now without the filter (where the timestamps are sparse), libav just ignores the timestamps and goes on, so the playback  works. With the filter however, when all timesamps are set, libav honors the timestamps so the playback is actually worse.

I need to check the demuxer to see if the timestamps it gives are correct, but for now I assume they are. I don't see any solution for this. wtay says that the parser should respect upstream timestamps, but when we do, the file is unplayable (even though it plays in other players, as they obviously ignore those, at least when the TS are going backwards)
Comment 16 Matej Knopp 2013-07-30 11:25:48 UTC
Nevermind, the file is good. mpegvideoparse doesn't support field pictures :(
Comment 17 Matej Knopp 2013-07-30 13:22:22 UTC
Disregard the comment about V.VOB, it was a false alarm. mpegtimestampparse was outputing twice as many buffers than it should have ( https://bugzilla.gnome.org/show_bug.cgi?id=705144 )
Comment 18 Matej Knopp 2013-07-30 13:29:39 UTC
I meant mpegvideoparse of course.
Comment 19 Sebastian Dröge (slomo) 2013-08-13 12:13:31 UTC
Ok, so what should happen here now? What's left to be done, how does that relate to the other mpegvideoparse timestamp bug?
Comment 20 Matej Knopp 2013-08-13 12:35:03 UTC
Well, someone should take the code from the filter attached here and put it to mpegvideoparse. That someone probably being me. I have one issue with this though, I need access to queued pages in baseparser, but there is no easy way to do that currently.

As for the other issue, there is partial overlap (interpolating of missing timestamps), not sure about the rest (using timestamps from seq. header, etc).
Comment 21 Sebastian Dröge (slomo) 2013-08-13 13:55:16 UTC
Ok, feel free to add whatever API is needed to baseparse :)
Comment 22 Olivier Crête 2018-05-04 12:31:07 UTC
@Matej Do you plan to put the code inside mpegvideparse ?
Comment 23 Matej Knopp 2018-05-04 12:35:04 UTC
I really don't think I'm going to be able to do that in foreseeable future.
Comment 24 GStreamer system administrator 2018-11-03 13:17:21 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/105.