RTMP发送aac/h264数据, 需要添加flv的数据头. 官网说明
https://wwwimages2.adobe.com/content/dam/acom/en/devnet/flv/video_file_format_spec_v10_1.pdf
h264规范 https://www.itu.int/rec/T-REC-H.264 内容比较长, 这里只讲重点.
音频消息头(章节E.4.2 Audio Tags)
消息头格式
| 名称 | 比特数 | 说明 |
|---|---|---|
| sound format | 4 | 音频的格式, 10表示aac |
| sound rate | 2 | 音频采样率, 0表示5.5K, 1表示11K, 2表示22K, 3表示44K |
| sound size | 1 | 音频采样的大小, 0表示8bits, 1表示16bits |
| sound type | 1 | 音频声道类型 , 0表示单声道, 1表双通道 |
| aac packet type | 8 | 只有aac才有这个字节, 0表示数本数据包为AAC配置信息AudioSpecificConfig,ISO/IEC 14496-3文档中定义它的格式. 1表示AAC原始音频数据. |
AudioSpecificConfig的格式
| 字段 | 比特数 | 说明 |
|---|---|---|
| audioObjectType | 5 | aac的profile, 和adts中的定义是一样的 |
| samplingFrequencyIndex | 4 | aac的采样频率的索引, 和adts中的定义是一样的 |
| channelConfiguration | 4 | aac的通道数, 和adts中的p定义是一样的 |
| epConfig | 2 | 不知道干什么用的, 写固定值"00" |
| directMapping; | 1 | 不知道干什么用的, 写固定值"00" |
正常情况下, 以上两个表总共4个字节.
ADTS的格式
| 名称 | 比特数 | 说明 |
|---|---|---|
| syncword | 12 | must be 0xFFF |
| ID | 1 | 0 for mpeg-4, 1 for mpeg-2 |
| layer | 2 | must be 00 |
| protect | 1 | |
| profile | 2 | 0 for main profile, 1 for low complexity profile, 2 for scalable sampling rate profile, 3 reserved |
| frequency | 4 | 采样频率, 0表示96000, 1: 88200, 2: 64000,3: 48000,4: 44100,5: 32000, 6: 24000,7:22050,8: 16000, 9: 12000, 10: 11025, 11: 8000, 12: 7350, |
| private | 1 | |
| channel | 3 | 0:Defined in AOT Specifc Config, 1-6 for channel count, 7 for 8 channel |
| copy | 1 | |
| home | 1 | |
| copyright | 1 | |
| copyright-start | 1 | |
| frame-len | 13 | |
| adts-fullness | 11 | |
| blocks | 2 | 无 |
举例: 略
视频头(E.4.3 Video Tags)
| 字段 | 比特数 | 说明 |
|---|---|---|
| frame type | 4 | 数据帧的类型, 1表示关键帧, 2表示非关键帧, 5表示视频信息 |
| codec id | 4 | 编码类型, 7表示AVC |
| packet type | 8 | 0表示配置信息(sps pps), 1表示NALU |
| composite time | 24 | 如果packet type为0, 则填0; 其它, 填时间戳, 毫秒, 通常填0, 因为rtmp已经有时间戳了 |
对于AVC/H.264格式, 接下来是AVCVIDEOPACKET
当packet type为0时(sps, pps)
数据包格式为ISO 14496-15 5.2.4.1章节描述的AVCDecoderConfigurationRecord格式.
http://www.doc88.com/p-1823464610430.html
| 字段 | 比特数 | 说明 |
|---|---|---|
| version | 8 | 固定值1 |
| profile indication | 8 | 等同于sps的第2个字节 |
| profile compatibily | 8 | 等同于sps的第3个字节 |
| level indication | 8 | 等同于sps的第4个字节 |
| reserved | 6 | 固定值'111111' |
| length size | 2 | 表示NALULength字段的长度, 0表示用1个字节, 2表示用两个字节, 3表示用4个字节. 通常为3 |
| reserved | 3 | 固定值'111' |
| num of sps | 5 | sps的个数, 通常为1 |
| sps length | 16 | sps的字节数, 网络字节序 |
| sps | 8x(sps length) | sps的内容 |
| num of pps | 8 | pps的个数, 通常为1 |
| pps length | 16 | pps的字节数, 网络字节序 |
| pps | 8x(pps length) | pps的内容 |
当packet type为1时(NALU)
| 字段 | 比特数 | 说明 |
|---|---|---|
| nalu length | 32 | 它是由上表中length size决定的, 通常为4个字节. 现在的视频数据都很大. |
| nalu data | 8x(nalu length) | H264的原始数据 |
本文详细介绍了RTMP协议中AAC音频和H264视频数据的传输方式,包括数据头格式、ADTS格式及视频配置信息等内容,并提供了相关规范链接。

995

被折叠的 条评论
为什么被折叠?



