北京市建设资格与执业资格注册中心网站,产品开发计划书,个性化网页设计,自己做app的软件在直播系统中#xff0c;除了直播音视频之外#xff0c;有时候还想从主播端发布文本信息等#xff0c;这些信息可以不通过视频传输通道发送给用户播放端#xff0c;但如果传输的数据想和视频保持精准同步#xff0c;那最好的办法就是这些信息和视频数据打包在一起传输, 通… 在直播系统中除了直播音视频之外有时候还想从主播端发布文本信息等这些信息可以不通过视频传输通道发送给用户播放端但如果传输的数据想和视频保持精准同步那最好的办法就是这些信息和视频数据打包在一起传输, 通过h264 sei方式就可以把数据放入h264 Access Unit中传输。 H264 SEI 基本知识介绍: SEI 全称: Supplemental Enhancement Information SEI Nal Unit Type: 6 SEI 语法定义: Supplemental enhancement information RBSP syntax sei_rbsp( ) { CDescriptor do sei_message( ) 5 while( more_rbsp_data( ) ) rbsp_trailing_bits( ) 5 } Supplemental enhancement information message syntax
sei_message( ) { CDescriptor payloadType 0 while( next_bits( 8 ) 0xFF ) { ff_byte /* equal to 0xFF */ 5 f(8) payloadType 255 } last_payload_type_byte 5u(8) payloadType last_payload_type_byte payloadSize 0 while( next_bits( 8 ) 0xFF ) { ff_byte /* equal to 0xFF */ 5f(8) payloadSize 255 } last_payload_size_byte 5u(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消息而已。第三个是完全和视频保持同步这个是其他传输通道无法做到的.