H264 Frame → PES Packet → TS Packets 변환
1. H264 Frame(ES)에 PES Header를 붙이면 PES 패킷이 된다.
- PES Header에는 PTS, DTS 정보가 들어있다.
2. PES 패킷을 쪼개서 TS Header를 붙이면 TS 패킷이 된다.
- PES 패킷은 TS 패킷 크기(188 Bytes)에 맞춰 쪼개진다.
- 마지막 PES 패킷은 188 Bytes를 채우지 못하므로 Adaption Field를 0xFF로 채운다.
TS Packet (188 Bytes)
*MPEG-2 TS Packet Analyzer 캡쳐
1. TS Header
0x47 : sync_byte
0x40 :
0 : transport_error_indicator
1 : payload_unit_start_indicator
0 : transport_priority
0 : packet_identifier (PID)
0 : ..
0 : ..
0 : ..
0 : ..
0x41 :
0 : ..
1 : ..
0 : ..
0 : ..
0 : ..
0 : ..
0 : ..
1 : ..
0x3E :
0 : transport_scrambling_control
0 : ..
1 : adaptation_field_control (11=adaption field, payload 모두 존재)
1 : ..
1 : continuity_counter (1씩 증가)
1 : ..
1 : ..
0 : ..
2. Adaption Field
0x07 : adaptation_field_length
0x50 :
0 : discontinuity_indicator
1 : random_access_indicator
0 : elementary_system_priority_indicator
1 : PCR_flag (0=적응필드가 PCR 필드 포함하지 않음)
0 : OPCR flag
0 : splicing_point_flag
0 : transport_private_data_flag
0 : adaptation_field_extension_flag
0x09~ : PCR 관련 필드들
3. PES Packet
TS 패킷의 Payload에는 PES 패킷이 쪼개져서 담긴다.
3-1. PES Header
0x00 : packet_start_code_prefix
0x00 : ..
0x00 : ..
0x01 : ..
0xE0 : stream_id (E0=Video Stream 224)
0x2D : PES_packet_length
0x7D : ..
0x81 :
1 : optional PES header indicator
0 : ..
0 : PES_scrambling
0 : ...
0 : PES_priority
0 : data_alignment
0 : copyright
1 : original_or_copy
0x80 :
1 : PTS_flag
0 : DTS_flag
0 : ESCR_flag
0 : ES_rate_flag
0 : DSM_trick_mode_flag
0 : additional_copy_info_flag
0 : PES_CRC_flag
0 : PES_extention_flag
0x05 : PES_header_data_length
0x21~0xD9 : PTS, DTS (계산 방식은 Wikipedia 참고)
※ PTS 계산 방법
21 4D 41 15 D9
= 00100001 01000001 01000001 00010101 11011001
= 0010 000 1 010000010100000 1 000101011101100 1
0010 : PTS 정보만 포함함을 의미
000 : 부호 비트 (양수)
1 : 마커 비트
010000010100000 : PTS 상위 비트
1 : 마커 비트
000101011101100 : PTS 하위 비트
1 : 마커 비트
∴ PTS = 010000010100000000101011101100(2) = 273681132
3-2. PES Payload
H.264 Frame이 담긴다.
참고
1. http://www.ktword.co.kr/abbr_view.php?id=716&m_temp1=3504&nav=2