MPEG2 Presentation Time Stamps (PTS) calculation

纵然是瞬间 提交于 2019-11-29 00:09:05

问题


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 don't know how this bitfield can be converted to more understandable form (seconds, milliseconds). Can anybody help me please


回答1:


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.




回答2:


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;



来源:https://stackoverflow.com/questions/13606023/mpeg2-presentation-time-stamps-pts-calculation

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