Search Results for 'MPEG-2'

2 POSTS

  1. 2009.01.30 How to calculate MPEG-2 PCR value
  2. 2009.01.30 How to extract DTS/PTS values out of MPEG-2 PES header

How to calculate MPEG-2 PCR value

Posted 2009.01.30 05:22
출처: http://blog.jongov.com/?p=3

How to calculate MPEG-2 PCR value

Lets say that we have to calculate PCR for time 10:01:47.66.
10 hours + 1 minute + 47.66 seconds equals 36107.66 seconds.

In MPEG-2 specification it is said:

PCR_base(i) =((system_clock_ frequency * t(i)) DIV 300) % pow(2, 33)
PCR_ext(i) =((system_clock_ frequency * t(i)) DIV 1) % 300,

where PCR_base is 33 bits and PCR_ext is 9 bits.

So

PCR_base(i) =((system_clock_ frequency * t(i)) DIV 300) % pow(2, 33)
PCR_base =((27000000 *36107.669773 ) DIV 300) % pow(2, 33)
PCR_base =( 974907083871 DIV 300) % pow(2, 33)
PCR_base = 3249690279 % pow(2, 33)
PCR_base = 3249690279

PCR_ext(i) =((system_clock_ frequency * t(i)) DIV 1) % 300
PCR_ext(i) =((27000000 * 36107.669773 ) DIV 1) % 300
PCR_ext(i) =(974907083871 DIV 1) % 300
PCR_ext(i) =171

신고
출처 : http://blog.jongov.com/?p=2

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


신고

티스토리 툴바