直播系统中使用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( ) {      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 */  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消息而已。第三个是完全和视频保持同步,这个是其他传输通道无法做到的.

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值