MPEG TS PCR and PTS

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

MPEG TS PCR and PTS

Adams, Bruce (KMLWG)

Hi,

     I am trying to work out how to get absolute time-stamps from an incoming MPEG transport stream.

The basics seem to be that we get a presentation time-stamp via buffer->get_pts(). This is relative to the program clock reference PCR which is dictated by one of the elementary streams – typically the video. How do I get that base time out of gstreamer?

I note that if I use a tsparse element it can decode TOT and TDT sections for DVB inputs. However, I also notice that one of my inputs is a TSIP input which does not include these sections.

How can I tell if an  absolute time reference is available and when it is what is the epoch? Is it the standard unix epoch 1970-01-01T00:00:00Z?

 

Regards,

 

Bruce.



Kantar Disclaimer
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: MPEG TS PCR and PTS

Baby Octopus
Administrator
Have you gone through the code of mpegtsdemux in gst-plugins-bad? Is there
some part of code that you do not understand there? Typically first PCR is
used as base time and then subsequent PTS computation involves subtracting
this PCR from the PTS and then applying skew for compensating sender vs
receiver's clock variation



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

RE: MPEG TS PCR and PTS

Adams, Bruce (KMLWG)
In reply to this post by Adams, Bruce (KMLWG)

>>Date: Fri, 4 May 2018 07:13:14 +0000

>>From: "Adams, Bruce (KMLWG)" <[hidden email]>

>>To: "[hidden email]"<[hidden email]>

>>Subject: MPEG TS PCR and PTS

>> 

>>Hi,

>>    I am trying to work out how to get absolute time-stamps from an incoming MPEG transport stream.

>>The basics seem to be that we get a presentation time-stamp via buffer->get_pts(). This is relative to >>the program clock reference PCR which is dictated by one of the elementary streams - typically the >>video. How do I get that base time out of gstreamer?

>>I note that if I use a tsparse element it can decode TOT and TDT sections for DVB inputs. However, I >>also notice that one of my inputs is a TSIP input which does not include these sections.

>>How can I tell if an  absolute time reference is available and when it is what is the epoch? Is it the >>standard unix epoch 1970-01-01T00:00:00Z?

>> 

>>Regards,

>> 

>>Bruce.

> 

>Date: Fri, 4 May 2018 04:11:59 -0700 (MST)

>From: Baby Octopus <[hidden email]>

>To: [hidden email]

>Subject: Re: MPEG TS PCR and PTS

>Message-ID: <[hidden email]>

>Content-Type: text/plain; charset=us-ascii

> 

>Have you gone through the code of mpegtsdemux in gst-plugins-bad? Is there some part of code that >you do not understand there? Typically first PCR is used as base time and then subsequent PTS >computation involves subtracting this PCR from the PTS and then applying skew for compensating >sender vs receiver's clock variation

 

Tl;Dr; how do I relate the time-stamp from the TDT which comes via the bus to the pts I get from buffers in the pipeline?

 

Yes. Actually gstreamer is a case where you seem to be required to go through the code, and jump around a lot, to work out how to use some parts of the various libraries (I don’t know how users from other languages that are not C literate deal with that). Maybe I can help with the documentation in the future. Currently, I have multiple learning curves of MPEG-TS, DVB, gobject, gstreamer, gstreamermm to deal with so there are some gaps in my knowledge at present.

 

I can see that the struct _MpegTSParse2 contains three PCR variables as part of its structure. I don’t think I am supposed to access these directly but rather though either the buffers passed between elements and/or bus messages. Its not so obvious how that happens.

If I dump the values of buffer->get_pts()  I receive downstream they seem to increment at the expected rate (i.e. roughly 1s/s) but it is not clear from the name get_pts()  that the PCR is involved. Unfortunately both MPEG-TS and gstreamer overload the same term “presentation time stamp”. Does the PTS in gstreamer (in the buffers to be precise) combine both the PTS and PCR from MPEG TS?

 

From here (https://stackoverflow.com/questions/34646208/maximum-value-of-pcr/36810049#36810049 ) it seems that the PCR wraps every 26 hours or so. Thus is it not the absolute time-stamp I was looking for. It seems to be used just to sync audio and video tracks with each other.

 

It seems the absolute time-stamps I want in are the TDT section which is DVB specific but how do I relate the time-stamps I get there to the gstreamer pts (or the MPEG-TS PCR & PTS)? The TDT section comes via the gstreamer bus but the gstreamer pts is included in the buffers sent along the pipe-line.

 

To further confuse me I have some hardware that takes some DVB inputs and provides TSoIP outputs but seem to strip out the TDT sections (possibly because it combines parts of several different incoming transport streams). I don’t know if that is normal. For many applications relative time-stamps are enough. I ideally want to keep in sync with the encoding/transmission time rather than the reception time (or get an idea of the transmission delay) so if there is another way to get an absolute time-stamp that is part of plain MPEG TS or TSoIP (if that differs) it would be useful to know.

In the future I am going to have to support other standards in addition to DVB, such as ISDB-T (where the TDT won’t be available).

 


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

RE: MPEG TS PCR and PTS

Baby Octopus
Administrator
TDT does not have have timestamp information. TDT is date information only.
Timestamps are entirely derived from PTS and PCR(PCR only in live cases for
clock skew compensation)



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

RE: MPEG TS PCR and PTS

Adams, Bruce (KMLWG)
That's not correct according to the DVB standard (see http://www.etsi.org/deliver/etsi_en/300400_300499/300468/01.15.01_60/en_300468v011501p.pdf).
Both the TDT (mandatory) and TOT (optional) contain both and time and date stamps.

The issue on the gstreamer side is that the message comes on the bus (MPEG section -> TDT) and the PTS comes via the buffers. How do I associate these?

Perhaps I need an event via a pad rather than a message on the bus external the pipeline?

Perhaps what I want is a clock? As in:
https://gstreamer.freedesktop.org/documentation/application-development/advanced/clocks.html

I don't actually have any elements providing clock information in my pipeline at present. I would like a clock based on the absolute time from the TDT.
Similarly a clock based on absolute time-stamps from RTP could also be useful.

-----Original Message-----
From: gstreamer-devel [mailto:[hidden email]] On Behalf Of Baby Octopus
Sent: 05 May 2018 15:32
To: [hidden email]
Subject: RE: MPEG TS PCR and PTS

TDT does not have have timestamp information. TDT is date information only.
Timestamps are entirely derived from PTS and PCR(PCR only in live cases for
clock skew compensation)



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

RE: MPEG TS PCR and PTS

Baby Octopus
Administrator
I'm not really sure if the DVB standard recommends using TDT to derive
timestampson the decoder side. Almost all the decoders that I'm aware
of(including gstreamer) synchronize the PTS to the clock using PES PTS and
PCR. And they work pretty well :)

~BO



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

RE: MPEG TS PCR and PTS

Adams, Bruce (KMLWG)

The synchronisation between streams is fine but that's not what I'm after.
Please give a noob a break! :)

The gstreamer PTS is a relative timestamp which starts from 00:00:00 when I start playing.
How do I convert that to the time-stamp at the time of transmission?

If I add the system clock that gets me the reception time. It does not include the latency.
If I playback a TS I've previously saved I want to have the time-stamp it was transmitted which
could be days ago.

If I play a live stream via RTP I want to know the transmission delay.
I think a latency query is just the latency in the gstreamer pipeline.

The packets have time-stamps but gstreamer is (thankfully) processing those for me. I don't have direct access to them.

-----Original Message-----
From: gstreamer-devel [mailto:[hidden email]] On Behalf Of Baby Octopus
Sent: 07 May 2018 19:30
To: [hidden email]
Subject: RE: MPEG TS PCR and PTS

I'm not really sure if the DVB standard recommends using TDT to derive
timestampson the decoder side. Almost all the decoders that I'm aware
of(including gstreamer) synchronize the PTS to the clock using PES PTS and
PCR. And they work pretty well :)

~BO



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

RE: MPEG TS PCR and PTS

Baby Octopus
Administrator
Gstreamer playback, especially for TS is built on the premise of playing back
individual streams by synchronizing them. Just the way you double click a
file on VLC and it starts playing synchronizing each media

Things like content generated time is not respected. I presume you want to
do something like - Dictate the receiver side when to play, by sending that
information through Timestamp. I'm not aware of any standard which sends
absolute EPOCH or UTC based timestamp for synchronizing the playback(perhaps
MMT to a certain extent). Hence you would see each and every PTS starting
from 0

Gstreamer is extremely flexible and you could achieve what you want by
playing around with latency and Timestamp yourself. You can hack around
tsdemux deviating from existing standard(like using TDT for
synchronization), playaround with pipeline latency, Use buffer pad probes to
hack the timestamp yourself, or use appsrc and appsink etc. I'm sure there
are so many options for you to achieve what you want using gstreamer, though
it may not be a conventional way in which people use gstreamer.

Ensure you understand the concepts and gstreamer implementation perfectly if
you want to workaround or hack sensitive components such as Timestamps,
Latency, Clocks & Synchronization. Few of these concepts are well explained
at https://gstreamer.freedesktop.org/documentation/design/index.html 

~BO



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: MPEG TS PCR and PTS

Krzysztof Konopko-3
In reply to this post by Adams, Bruce (KMLWG)
Hi,
 
To my understanding, `buffer->get_pts()` makes little sense in case of MPEG-TS as each GStreamer buffer will typically hold a number of TS packets which in turn can be part of different PES packets and elementary streams and relate to different access units (frames). So I do not find it particularly useful to indicate with GStreamer PTS when to "present" such ambiguous chunk of stream before demuxing it.
 
Also to my understanding information like TOT/TDT is more useful when presenting programme events (EIT) for example in a guide and to synchronise intended start date and time of the events with the local time (for presentation or recording purposes). I can't see how it could be useful to relate it to the actual media time where it's not really useful to care about absolute values especially when timestamps can wrap.
 
Kris
 
On Fri, 2018-05-04 at 07:13 +0000, Adams, Bruce (KMLWG) wrote:

Hi,

     I am trying to work out how to get absolute time-stamps from an incoming MPEG transport stream.

The basics seem to be that we get a presentation time-stamp via buffer->get_pts(). This is relative to the program clock reference PCR which is dictated by one of the elementary streams – typically the video. How do I get that base time out of gstreamer?

I note that if I use a tsparse element it can decode TOT and TDT sections for DVB inputs. However, I also notice that one of my inputs is a TSIP input which does not include these sections.

How can I tell if an  absolute time reference is available and when it is what is the epoch? Is it the standard unix epoch 1970-01-01T00:00:00Z?

 

Regards,

 

Bruce.



Kantar Disclaimer
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
 

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

RE: MPEG TS PCR and PTS

Adams, Bruce (KMLWG)

Hi,

 

Yes indeed I only do buffer->get_pts() after demuxing.

Correctly assigning material to events is a good example. If I get an event saying “Foobar” is on at 9pm how can I determine from the (demuxed) TS when 9pm is in terms of the buffer mini objects I’m processing?

For testing I wish to playback a TS from a file as fast as possible rather than real-time. So all the time information must be in the TS somewhere. My guess is to use the TDT to get an absolute time-stamp and relate either the gstreamer PTS or the mpeg PCR & PTS to it somehow.

 

For a little more background I’m effectively monitoring live TS streams for events of interest detected by processing the audio (or video). I need to determine the absolute time of these events to associate them with events on other streams. The same code should work on a recorded TS as well.

 

At the moment it looks like I have to use the system clock for a live stream and provide a start time for a recorded TS. It seems like there ought to be an alternative way as the TS should know when it was recorded if, for example, it includes a TDT.

 

Regards,

 

Bruce.

 

 

From: gstreamer-devel [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: 09 May 2018 10:06
To: Discussion of the development of and with GStreamer
Subject: Re: MPEG TS PCR and PTS

 

Hi,

 

To my understanding, `buffer->get_pts()` makes little sense in case of MPEG-TS as each GStreamer buffer will typically hold a number of TS packets which in turn can be part of different PES packets and elementary streams and relate to different access units (frames). So I do not find it particularly useful to indicate with GStreamer PTS when to "present" such ambiguous chunk of stream before demuxing it.

 

Also to my understanding information like TOT/TDT is more useful when presenting programme events (EIT) for example in a guide and to synchronise intended start date and time of the events with the local time (for presentation or recording purposes). I can't see how it could be useful to relate it to the actual media time where it's not really useful to care about absolute values especially when timestamps can wrap.

 

Kris

 

On Fri, 2018-05-04 at 07:13 +0000, Adams, Bruce (KMLWG) wrote:

Hi,

     I am trying to work out how to get absolute time-stamps from an incoming MPEG transport stream.

The basics seem to be that we get a presentation time-stamp via buffer->get_pts(). This is relative to the program clock reference PCR which is dictated by one of the elementary streams – typically the video. How do I get that base time out of gstreamer?

I note that if I use a tsparse element it can decode TOT and TDT sections for DVB inputs. However, I also notice that one of my inputs is a TSIP input which does not include these sections.

How can I tell if an  absolute time reference is available and when it is what is the epoch? Is it the standard unix epoch 1970-01-01T00:00:00Z?

 

Regards,

 

Bruce.



Kantar Disclaimer

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

 


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel