直播系统中使用SEI传输用户自定义数据方案讨论
? ? ? 在直播系統中,除了直播音視頻之外,有時候還想從主播端發布文本信息等,這些信息可以不通過視頻傳輸通道發送給用戶播放端,但如果傳輸的數據想和視頻保持精準同步,那最好的辦法就是這些信息和視頻數據打包在一起傳輸, 通過h264 sei方式就可以把數據放入h264 Access Unit中傳輸。
? ? ?H264 SEI 基本知識介紹:
? ? ?SEI 全稱:?Supplemental Enhancement Information??
? ? ?SEI Nal Unit Type: 6
? ? ?SEI 語法定義:
? ? ?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:
| 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 語義:
? ? ? Supplemental enhancement information RBSP semantics
? ? ? 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消息而已。第三個是完全和視頻保持同步,這個是其他傳輸通道無法做到的.
?
總結
以上是生活随笔為你收集整理的直播系统中使用SEI传输用户自定义数据方案讨论的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【机器学习】UMAP:强大的可视化降维工
- 下一篇: RTSP播放器开发过程中需要考虑哪些关键