MPEG2 Presentation Time Stamps (PTS) calculation

后端 未结 2 1203
失恋的感觉
失恋的感觉 2020-12-28 22:53

I have an MPEG2 TS file and now I am interested in extracting PTS information from each picture frame. I know that PTS is described in 33 bits including 3 marker bits. But I

相关标签:
2条回答
  • 2020-12-28 23:42

    24hours/day * 60min/hr * 60secs/min *90k/sec (clock) = 7962624000, which needs 33 bits to be represented; You can extract your time from the clock using this info;

    0 讨论(0)
  • 2020-12-28 23:51

    The MPEG2 transport stream clocks (PCR, PTS, DTS) all have units of 1/90000 second. The PTS and DTS have three marker bits which you need to skip over. The pattern is always (from most to least significant bit) 3 bits, marker, 15 bits, marker, 15 bits, marker. The markers must be equal to 1. In C, removing the markers would work like this:

    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 an extension field of 9bits, forming a 42bit integer in which the extension is the least significant bits. The units for the base+extension are 1/27000000 second. Many implementations leave the extension as all zeros.

    0 讨论(0)
提交回复
热议问题