TS流详细解析

1、PAT表的TS包

0x47:包头识别符 Sync_code
0x40 0x00:0100 0000 0000 0000
0b:transport_error_Indicator 为1的包丢弃
1b:payload_unit_start_indicator是否忽略头部后的第一个字节
0b:transport_priority 传输优先级
0 0000 0000 0000b:PID 最重要的:PAT的TS包 0x0000
0x10 --> 0001 0000b:
00b:transport_scrambling_control
01b:adaption_field_control
0000b:continuity_counter 序号为0
PAT表解析:8字节的头 + 4Byte * n个节目流(包含 program_number(16bit), reserved (3bit), program_map_PID(13bit))
PAT的数据:00 B0 0D 00 01 C1 00 00 00 01 F0 00 2A B1 04 B2
PAT头:00 B0 0D 00 01 C1 00 00
00:PAT的table_id只能是0x00
B0 0D: 1011 0000 0000 1101
1b:section_syntax_indicator 1bit 值为1 段语法标志位,固定为1
0b:zero 1bit 值为0
11b:reserved 2bits 值为11 (Binary)
0000 0000 1101b:section_length 12bits 值为即0x0D,十进制值为13,段长度为13字节,刚好是:00 01 C1 00 00 00 01 F0 00 2A B1 04 B2,13个字节
00 01:transport_stream_id 16bits TS的识别号
C1: 1100 0001
11b:reserved 2bits 值为3 TS的识别号
00 000b:version_number 5bits 值为0 一旦PAT有变化,版本号加1
1b:current_next_indicator 1bit 值为1 当前传送的PAT表可以使用,若为0则要等待下一个表
00:section_number 0x00 给出section号,在sub_table中,第一个section其section_number为"0x00",每增加一个section,section_number加一
00:last_section_number 0x00 sub_table中最后一个section的section_number
节目的PMT的PID:00 01 F0 00
00 01:0000 0000 0000 0001 代表节目号为0x0001(即十进制1)的节目
F0 00: 1111 0000 0000 0000
111b:reserved
1 0000 0000 0000b:PMT的PID为0x1000

本文福利, 免费领取C++音视频学习资料包、技术视频,内容包括(音视频开发,面试题,FFmpeg webRTC rtmp hls rtsp ffplay srs↓↓↓↓↓↓见下面↓↓文章底部点击免费领取↓↓

2、PMT表的TS包

TS头:47 50 00 10
0x47:包头识别符 Sync_code
0x50 0x00 0x10:0101 0000 0000 0000
0b:transport_error_Indicator 为1的包丢弃
1b:payload_unit_start_indicator是否忽略头部后的第一个字节
0b:transport_priority 传输优先级
1 0000 0000 0000b:PID为0x1000
PAT表解析:12字节的头 + 6 字节* n个音视频流(包含 stream_type(8bit), reserved (3bit), elementary_PID(13bit),reserved (4bit), ES_info_length(12bit))
PMT的数据:02 B0 1D 00 01 C1 00 00 E1 00 F0 00 02 E1 00 F0 00 03 E1 01 F0 06 0A 04 75 6E 64 00 94 9D 2D F0
PAT头:02 B0 1D 00 01 C1 00 00 E1 00 F0 00
02:PAT的table_id只能是0x02
B0 1D: 1011 0000 0001 1101
1b:section_syntax_indicator 1bit 值为1 段语法标志位,固定为1
0b:zero 1bit 值为0
11b:reserved 2bits 值为11 (Binary)
0000 0001 1101b:section_length 12bits 值为即0x1D,十进制值为29,段长度为29字节,刚好是:00 01 C1 00 00 E1 00 F0 00 02 E1 00 F0 00 03 E1 01 F0 06 0A 04 75 6E 64 00 94 9D 2D F0,29个字节
00 01:program_number 16bits TS的识别号
C1: 1100 0001
11b:reserved 2bits 值为3 TS的识别号
00 000b:version_number 5bits 值为0 一旦PAT有变化,版本号加1
1b:current_next_indicator 1bit 值为1 当前传送的PAT表可以使用,若为0则要等待下一个表
00:section_number 0x00 给出section号,在sub_table中,第一个section其section_number为"0x00",每增加一个section,section_number加一
00:last_section_number 0x00 sub_table中最后一个section的section_number
E1 00:1110 0001 0000 0000
111b:reserved
0 0001 0000 0000b:PCR_PID(节目参考时钟)所在TS分组的PID
F0 00:1111 0000 0000 0000
1111b:reserved
0000 0000 0000b:program_info_length值为0
视频的PID:02 E1 00 F0 00
02:stream_type 流类型,标志是Video还是Audio还是其他数据。这里是  0x02即是MPEG2视频类型
E1 00: 1110 0001 0000 0000
111b:reserved
0 0001 0000 0000b:elementary_PID  该节目的音频或视频PID,即是0x100
F0 00:1111 0000 0000 0000
1111b:reserved
0000 0000 0000b:ES_info_length 后面紧跟着0个字节的描述子
音频的PID:03 E1 01 F0 06
03:stream_type 流类型,标志是Video还是Audio还是其他数据。这里是  0x03即是ISO/IEC 11172音频
E1 01: 1110 0001 0000 0001
111b:reserved
0 0001 0000 0000b:elementary_PID  该节目的音频或视频PID,即是0x101
F0 06:1111 0000 0000 0110
1111b:reserved
0000 0000 0110b:ES_info_length 后面紧跟着6个字节的描述,也就是0A 04 75 6E 64 00

3、视频PES的TS包

TS包长度:12*16-4 = 204 - 16(CRS校验) = 188 Byte

0x47:包头识别符 Sync_code

0x41 0x00:0100 0001 0000 0000

0b:transport_error_Indicator 为1的包丢弃

1b:payload_unit_start_indicator 负载数据的起始标识

0b:transport_priority 传输优先级

0 0001 0000 0000b:PID 最重要的,包类型,视频频PES包 0x100

0x15 --> 0001 0101b:

00b:transport_scrambling_control

01b:adaption_field_control

0101b:continuity_counter 序号为5,上一个为4,下一个为6

4、音频PES的TS包

TS包长度:12*16-4 = 204 - 16(CRS校验) = 188 Byte

0x47:包头识别符 Sync_code

0x41 0x01:0100 0001 0000 0001

0b:transport_error_Indicator 为1的包丢弃

1b:payload_unit_start_indicator 负载数据的起始标识

0b:transport_priority 传输优先级

0 0001 0000 0001b:PID 最重要的,包类型,音频PES包 0x101

0x30 --> 0011 0000b:

00b:transport_scrambling_control

11b:adaption_field_control

0000b:continuity_counter 序号为0,上一个为15,下一个为1

本文福利, 免费领取C++音视频学习资料包、技术视频,内容包括(音视频开发,面试题,FFmpeg webRTC rtmp hls rtsp ffplay srs↓↓↓↓↓↓见下面↓↓文章底部点击免费领取↓↓

猜你喜欢

转载自blog.csdn.net/m0_60259116/article/details/126488039