How to generate timestamps from PCR in Hex

不想你离开。 提交于 2019-12-24 19:50:13

问题


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).

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....


回答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 90Khz 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



来源:https://stackoverflow.com/questions/58716586/how-to-generate-timestamps-from-pcr-in-hex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!