在直播系統中,除了直播音視頻以外,有時候還想從主播端發佈文本信息等,這些信息能夠不經過視頻傳輸通道發送給用戶播放端,但若是傳輸的數據想和視頻保持精準同步,那最好的辦法就是這些信息和視頻數據打包在一塊兒傳輸, 經過h264 sei方式就能夠把數據放入h264 Access Unit中傳輸。html
H264 SEI 基本知識介紹:git
SEI 全稱: Supplemental Enhancement Information github
SEI Nal Unit Type: 6windows
SEI 語法定義:ide
Supplemental enhancement information RBSP syntax:測試
sei_rbsp( ) { | C | Descriptor |
do | ||
sei_message( ) | 5 | |
while( more_rbsp_data( ) ) | ||
rbsp_trailing_bits( ) | 5 | |
} |
Supplemental enhancement information message syntax:spa
sei_message( ) { | C | Descriptor |
payloadType = 0 | ||
while( next_bits( 8 ) = = 0xFF ) { | ||
ff_byte /* equal to 0xFF */ | 5 | f(8) |
payloadType += 255 | ||
} | ||
last_payload_type_byte | 5 | u(8) |
payloadType += last_payload_type_byte | ||
payloadSize = 0 | ||
while( next_bits( 8 ) = = 0xFF ) { | ||
ff_byte /* equal to 0xFF */ | 5 | f(8) |
payloadSize += 255 | ||
} | ||
last_payload_size_byte | 5 | u(8) |
payloadSize += last_payload_size_byte | ||
sei_payload( payloadType, payloadSize ) | 5 | |
} |
SEI 語義:code
Supplemental enhancement information RBSP semanticsorm
Supplemental Enhancement Information (SEI) contains information that is not necessary to decode the samples of coded pictures from VCL NAL units.視頻
Supplemental enhancement information message semantics
An SEI NAL unit contains one or more SEI messages. Each SEI message consists of the variables specifying the type
payloadType and size payloadSize of the SEI payload. SEI payloads are specified in Annex D. The derived SEI payload
size payloadSize is specified in bytes and shall be equal to the number of bytes in the SEI payload.ff_byte is a byte equal to 0xFF identifying a need for a longer representation of the syntax structure that it is used within.
last_payload_type_byte is the last byte of the payload type of an SEI message.
last_payload_size_byte is the last byte of the size of an SEI message
從上面的描述能夠看出一個Sei Nal Unit中能夠包含多個SEI消息,每一個SEI消息都有一個payloadType,目前h264規定payloadType爲5時,sei_playload可使用戶自定義數據, 那麼咱們就能夠利用它來傳輸數據。
到此爲止SEI基本知識介紹完畢,若是要本身實現代碼的話,還須要瞭解更多細節,建議仔細閱讀h264文檔,這裏再也不深刻討論,也歡迎一塊兒交流討論。接下來進入實踐環節。
先下載軟件: https://github.com/daniulive/SmarterStreaming 爲方便測試, 下載windows版本就能夠.
rtmp 傳輸文本信息:
1. 啓動推送端軟件: SmartPublisherDemo.exe
2. 作以下配置:
3. 能夠點擊自動發送文本按鈕
4. 打開播放端SmartPlayer.exe查看數據傳輸播放效果:
rtsp 傳輸文本信息:
1. 啓動推送端軟件: SmartPublisherDemo.exe
2. 作以下配置:
3. 能夠點擊自動發送文本按鈕
4. 打開播放端SmartPlayer.exe查看數據傳輸播放效果:
總結
從上面的實驗能夠看出SEI的優點來, 第一個優點是並不依賴於相關協議,rtsp和rtmp均可以,其餘協議只要播放端支持SEI解析的均可以使用。 第二個是兼容性很好,若是播放端不支持自定義SEI數據解析,把SEI數據丟給H264解碼器,解碼器只是忽略掉,並不影響正常播放. 上述操做也能夠用VLC來播放,播放正常,只是不顯示SEI消息而已。第三個是徹底和視頻保持同步,這個是其餘傳輸通道沒法作到的.