How to extract DTS/PTS values out of MPEG-2 PES header
Lets say that we have the following sequence of bytes that represents the start of one PES packet:
0×00 0×00 0×01 0xE0 0×00 0×00 0×84 0xC0 0×0A 0×31 0×00 0×05 0xBF 0×21 …
The description of these bytes is as follows:
0×00 0×00 0×01 [0000 0000 0000 0000 0000 0001] packet_start_code_prefix (24 bits) = 1
0xE0 [1110 0000] stream_id (8 bits) = 224
0×00 0×00 [0000 0000 0000 0000] PES_packet_len (16 bits) = 0
0×84 [1000 0100] reserved(2 bits) = 2,
PES_scrabling_control(2 bits) = 0,
PES_priority(1 bit) = 0,
data_aligment_indicator(1 bit) = 1,
copyright(1 bit), = 0
original_or_copy(1 bit) = 0
0xC0 [1100 0000] PTS_DTS_flags(2 bits) = 3,
ESCR_flag(1 bit) = 0,
ES_rate_flag(1 bit) = 0,
DMS_trick_mode_flag(1 bit) = 0, additional_copy_info_flag(1 bit) = 0,
PES_CRC_flag(1 bit) = 0,
PES_extension_flag(1 bit) = 0
0×0A [0000 1010] PES_header_data_length(8 bits) = 10
0×31 [0011 0001] reserved(4 bits) = 3,
PTS_32_30(3 bits) = 0,
marker_bit(1 bit) = 1
0×00 0×05 [0000 0000 0000 0101] PTS_29_15(15 bits) = 2,
marker_bit(1 bit) = 1
0xBF 0×21 [1011 1111 0010 0001] PTS_14_0(15 bits) = 24464,
marker_bit(1 bit) = 1
The PTS value is contained in 0×31 0×00 0×05 0xBF 0×21 byte sequence, along with the reserved and marker bits. DTS and PTS values are held in 90 kHz units and the resulting value must be divided by 90000 in order to get the result in seconds.
The formula for PTS calculation is:
PTS in seconds = ( (PTS_32_30 << 30 ) + (PTS_29_15 << 15) + PTS_14_0 ) / 90000.0;
Here “<<” denotes the bitwise “shift to left” operation.
PTS in seconds = ( ( 0 << 30 ) + ( 2 << 15 ) + 24464 ) / 90000.0;
PTS in seconds = ( 0 + 65536 + 24464 ) / 90000.0;
PTS in seconds = ( 90000 ) / 90000.0;
PTS in seconds = 1.0
PTS = 00:00:01.0
'Research > Broadcast' 카테고리의 다른 글
Flash Player (0) | 2009.05.13 |
---|---|
How to calculate MPEG-2 PCR value (0) | 2009.01.30 |
채널 적응형 위성방송을 위한 DVB-S2 기술동향 (0) | 2008.03.28 |
Anatomy of a Video Signal (0) | 2008.02.21 |
YPbPr, RGB, Composite and S-VIdeo Colorbars (0) | 2008.02.19 |