Calculating MPEG2 Print Time (PTS)

I have an MPEG2 TS file, and now I'm interested in extracting the PTS information from each frame. I know that PTS is described in 33 bits, including 3 marker bits. But I do not know how this bit field can be converted into a more understandable form (seconds, milliseconds). Can someone help me please

+4
source share
2 answers

The MPEG2 transport stream clock (PCR, PTS, DTS) has units of 1/90000 of a second. PTS and DTS have three marker bits that you need to skip. A pattern is always (from most to least significant) 3 bits, marker, 15 bits, marker, 15 bits, marker. Markers must be equal to 1. In C, removing markers will work as follows:

uint64_t v; // this is a 64bit integer, lowest 36 bits contain a timestamp with markers uint64_t pts = 0; pts |= (v >> 3) & (0x0007 << 30); // top 3 bits, shifted left by 3, other bits zeroed out pts |= (v >> 2) & (0x7fff << 15); // middle 15 bits pts |= (v >> 1) & (0x7fff << 0); // bottom 15 bits // pts now has correct timestamp without markers in lowest 33 bits 

They also have a 9-bit extension field, forming a 42-bit integer in which the extension is the least significant bits. Units for expanding the base + 1/27000000 seconds. Many implementations leave the extension as all zeros.

+12
source

24 hours / day * 60 min / hour * 60 sec / min * 90 fps (hours) = 7962624000, for which 33 bits must be represented; You can extract your time from the clock using this information;

+4
source

All Articles