rtmp視頻包結構
類型 | 長度 | 值 |
---|---|---|
FrameType | 4bit | 1表示關鍵幀,2表示非關鍵幀,3表示一次性幀,4爲服務器保留,5表示視頻信息或命令幀 |
CodecID | 4bit | 1表示JPG,2表示Sorenson H263,3表示屏幕錄像,4表示VP6 ON2,,5表示帶alphat通道的VP6 ON2,6表示版本2的屏幕錄像,7表示avc,即h264 |
VideoData | 視頻數據,根據CodecID的不同,此處字段內容不同,例如CodecID爲2時,此處爲H263包結構,當CodecID爲7時,此處爲AVC視頻包結構 |
實際使用當中,經常用的是發送h264或者h265的包
對於h265, CodecID爲7,對於h265,一般擴展的CodecID都是12
因此,對於h264視頻包來說,第一個字節一般是0x17或0x27,
對於h265, 第一個字節一般是0x1c或0x2c
對於VideoData
字段,當CodecID爲7時,結構是AVC視頻包
AVC視頻包結構
類型 | 長度 | 值 |
---|---|---|
AVCPacketType | 8bit | 0表示AVC Sequence頭,1表示nalu, 2一般不支持較低level的h264 |
Composition time | 3 byte | 如果AVCPacketType爲1表示Composition time offset, 其他值是全爲0 |
Data | n byte | 如果AVCPacketType爲0,此處是AVCDecoderConfigurationRecord,如果AVCPacketType,此處是視頻數據,如果AVCPacketType爲2, 此處爲空 |
明顯的,前2個字段比較明確,Composition time一般都填0
下面看下AVCDecoderConfigurationRecord
h264 AVCDecoderConfigurationRecord
參數名 | 長度 | 值 |
---|---|---|
configureVersion | 1 byte | 版本號,默認爲1 |
AVCProfileIndication | 1 byte | profile定義,sps信息裏面去除頭部信息和sps標誌後的第一個字節 |
profile_compatibility | 1 byte | profile支持級別,sps信息裏面去除頭部信息和sps標誌後的第二個字節 |
AVCLevelIndication | 1 byte | level級別 sps頭信息之後第3個字節 |
reserved | 6 bit | 保留,默認爲’111111’ |
lengthSizeMinusOne | 2 bit | nalu unit長度 - 1,一般爲3 |
reserved | 3 bit | 保留,默認爲’111’ |
numOfSequenceParameterSets | 5 bit | sps的個數,一般爲1,即後面只有1個sps,如果有多個則後面2個字段循環添加 |
sequenceParameterSetLength | 2 byte | sps長度,先填高8位,再填低8位 |
sequenceParameterSetNaluUnit | n byte | sps內容 |
numOfPictureParameterSets | 1 byte | pps個數,一般爲1,如果有多個,後面的2個字段循環添加 |
pictureParameterSetLength | 2 byte | pps長度 |
pictureParameterSetNaLuUnit | n byte | pps內容 |
這樣h264視頻包結構就比較明晰了
再看看h265的HEVCDecoderConfigurationRecord
參數名 | 長度 | 值 |
---|---|---|
configureVersion | 1 byte | 版本號,默認爲1 |
general_profile_space | 2 bit | 0, 其他值留作備用 |
general_tier_flag | 1 bit | 2個值,main tier和high tier,level 4和4以上支持High Tier |
general_profile_idc | 5 bit | 當general_profile_space等於0時,指示CVS符合的配置文件 |
附件A中規定 | ||
general_profile_compatibility_flags | 4 byte | 當general_profile_idc指定的profile不在 |
general_constraint_indicator_flags | 1 byte | |
general_level_idc | 1 byte | |
reserved1 | 4 bit | 默認’1111’ |
min_spatial_segmentation_idc_L | 4 bit | |
min_spatial_segmentation_idc_H | 1 byte | |
reserved1 | 6 bit | 默認’111111’ |
parallelismType | 2 bit | |
reserved1 | 6 bit | 默認’111111’ |
chromaFormat | 2 bit | |
reserved1 | 5 bit | 默認’11111’ |
bitDepthLumaMinus8 | 3 bit | |
reserved1 | 5 bit | 默認’11111’ |
bitDepthChromaMinus8 | 3 bit | |
avgFrameRate | 2 byte | |
constantFrameRate | 2 bit | |
numTemporalLayers | 3 bit | |
temporalIdNested | 1 bit | |
lengthSizeMinusOne | 2 bit | |
numOfArrays | 1 byte | vps,sps,pps個數,後續填充內容,與h264一樣 |
h265的推流還未測試,待測試過了再仔細分析
https://blog.csdn.net/SwordTwelve/article/details/89522984
https://blog.csdn.net/qq_33795447/article/details/89457581
https://blog.csdn.net/dqxiaoxiao/article/details/94820599
https://blog.csdn.net/Dillon2015/article/details/104311186
https://blog.csdn.net/yue_huang/article/details/75126155