0

When inspecting a transport stream using tsduck, I can see that some packets contains a PCR value in Hex. I am not sure how to convert these into timestamps.

For example, in the packet below the PCR value is 0x000002014CE

* Packet 179
  ---- TS Header ----
  PID: 481 (0x01E1), header size: 25, sync: 0x47
  Error: 0, unit start: 1, priority: 0
  Scrambling: 0, continuity counter: 4
  Adaptation field: yes (21 bytes), payload: yes (163 bytes)
  Discontinuity: 0, random access: 0, ES priority: 0
  PCR: 0x000002014CE
  ---- PES Header ----
  Stream id: 0xE0 (Video 0)
  PES packet length: 0 (unbounded)
  ---- Full TS Packet Content ----
  47 41 E1 34 14 12 00 00 0D B0 7E 4E 0C 02 0A 22 8E 00 00 D1 2D 03 64 00
  29 00 00 01 E0 00 00 84 C0 0A 31 00 07 44 B7 11 00 05 D4 37 00 00 00 01
  09 30 00 00 01 06 01 03 03 84 19 80 00 00 01 41 9A 84 93 D1 13 7F F0 28
  2C 26 B5 35 90 10 B7 32 8C FF 00 D3 47 BE 4C 9A 83 AE CD B8 9C 09 5A 60
  07 BE C4 F2 2C 5D D3 24 6C 7F A0 E1 C4 7B BC FA 37 CA C5 C0 B0 C4 2C 91
  96 09 07 22 C4 A8 55 FF C2 BF 0E 7E 10 74 6D 84 F2 08 9D D0 29 52 7F 2B
  F6 3E C8 23 1F BC 4E 80 C3 AE FD AC F4 96 08 E5 13 C8 A7 41 20 B4 F6 F8
  E1 14 4A 03 4C 8E 98 00 04 73 2D AE 83 31 0B C8 61 03 3A A1

What I tried is looking at the first few instances of packets that had the PCR values in them, then converting them to decimal and subsequently dividing by 90,000 which is the clock rate of the PCR clock (i.e the timebase).

Table with PCR in seconds

But looking at the last column, it doesn't look right. It would seem that the intervals are too high. I thought that the PCR must insert PCR stamps at least every 100ms or so, but this seems to be too infrequent....

Baba.S
  • 324
  • 2
  • 14
  • 1
    (Side note: I have answered similar questions for you in the past, and you never upvote or accept them. Please do so, thanks) https://stackoverflow.com/questions/53296731/what-is-fixed-frame-rate-flag-used-for-in-encoders, https://stackoverflow.com/questions/53401917/how-to-generate-timestamps-from-the-33-bit-pcr-count – szatmary Nov 05 '19 at 20:37

1 Answers1

1

You are not using the correct time base. If you look at the example you posted, tsduck shows the PCR as 0x000002014CE But that hex value does not show up in that packet at all. The reason is the PCR is more than just a time stamp, Its 2 timestamps. The PCR in the hex is actually 00 00 0D B0 7E 4E So how do we get from 0xDB07E4E to 0x2014CE? We extract the 90 kHz component by shifting 0xDB07E4E right by 15 bits, Then extract the 27MHz component by masking off the top 39 bits. Then multiply the 90kHz component by 300 to convert to 27MHz (300=27000000/90000) and add the two values together:

300*(0xDB07E4E>>15) + (0xDB07E4E&0x1ffff) = 0x2014CE

We now have the 27MHz timestamp. To convert that to seconds, divide by 27000000

0x2014CE/27000000=0.0779

Hence:

0x58e54 = 0.0135
0x78707 = 0.0183

TLDR: time base is 27000000, not 90000

Simson
  • 3,373
  • 2
  • 24
  • 38
szatmary
  • 29,969
  • 8
  • 44
  • 57
  • How many bits wide is the PCR in the packet? How does shifting by 15 bits equate to extracting 90khz? – Baba.S Nov 05 '19 at 23:03
  • 1
    The PCR is divided into 2 parts spread over 48bits. The fist 33bits is the 90khz component (48-33=15) the next 6 bits are literally nothing. The remaining 9 bits is the 27Mhz component. – szatmary Nov 06 '19 at 00:20
  • 1
    "How many bits wide is the PCR in the packet?" => I answered that in my post "The PCR in the hex is actually `00 00 0D B0 7E 4E`" – szatmary Nov 06 '19 at 00:27
  • Thanks for clarifying. The reason I asked was because there's conflicting information that I've come across. Some say 42 bits wide and others say 48 bits wide. I didn't know about the reserved 6 bits. – Baba.S Nov 06 '19 at 08:01