简体   繁体   English

H264流解码器如何确定H264编码器正在馈送哪种流

[英]How does a H264 stream decoder decides which type of stream is being fed by H264 encoder

There are two types of stream types supported or at-least recommended by the ITU-T H264 documentation ie RTP packet and Annex B (Raw Byte Sequence). ITU-T H264文档支持或至少建议两种流类型,即RTP数据包和附件B(原始字节序列)。

My question here is that lets assume that the encoder is capable of sending streaming data in both the formats and can switch between anyone of them at any point of time while streaming(correct if this is not the case), how and when does the H264 decoder comes to know that it needs to parse the data either according to RTP format or Annex B ie Raw Byte Sequence data. 我在这里的问题是,假设编码器能够发送两种格式的流数据,并且在流传输时可以在任何时间点之间进行切换(如果不是这种情况,则是正确的),H264的方式和时间解码器知道它需要根据RTP格式或附件B解析数据,即原始字节序列数据。

Is there any standard protocol or mechanism to do that. 是否有任何标准协议或机制可以做到这一点。

What will happen in case there is packet loss and the encoder switches the way it was streaming data ie either from RTP to Annex B or vice versa, here the decoder probably still assumes the data being streamed in old format. 万一发生丢包,编码器切换数据流方式(即从RTP到附件B,反之亦然),将会发生什么情况,此处,解码器可能仍假定数据以旧格式进行流传输。

Kindly clarify the above. 请澄清以上内容。

Generally, most of the cases, H264 encoders produce packets in NAL (Netwrok Abstraction Layer) form. 通常,在大多数情况下,H264编码器会生成NAL(Netwrok抽象层)形式的数据包。 Each NALU (NAL Unit) consists of a NAL-Header and RBSP (Raw Byte Sequence Payload). 每个NALU(NAL单元)由一个NAL头和RBSP(原始字节序列有效载荷)组成。 As similar to H264 encoders, most of the decoders are capable of understanding the NALU (not really RTP). 与H264编码器类似,大多数解码器都能够理解NALU(不是真正的RTP)。 NAL header is 1-byte in size. NAL标头的大小为1个字节。

There are 2 RTP packetization methods for NAL Units. NAL单元有2种RTP打包方法。 In one method, NAL fragmentation is allowed and other method doesn't allow fragmenting the NALU. 在一种方法中,允许NAL片段化,而另一种方法不允许对NALU片段化。 In both methods, RTP header is followed by NALU. 在这两种方法中,RTP头后面都带有NALU。 Suppose both encoders and decoders are implemented in a way to understand RTP header as well, then they should parse the header first as the headers are always fixed in size. 假设编码器和解码器都以理解RTP头的方式实现,则由于头的大小始终固定,因此它们应该首先解析头。 Then, check against RTP and/or NAL headers to treat it accordingly for further parsing. 然后,检查RTP和/或NAL标头以对其进行相应的处理以进行进一步的分析。

For more details, see RFC 6184 - RTP Payload Format for H.264 Video 有关更多详细信息,请参阅RFC 6184-H.264视频的RTP有效负载格式

In summary, RTP and NAL are just headers and it's about the method to parse RTP or NAL header before decoding the actual video data. 总而言之,RTP和NAL只是标题,它是在解码实际视频数据之前解析RTP或NAL标题的方法。 It is better to signal the mode (RTP or NAL) in which the data got streamed to decoder. 最好用信号通知模式(RTP或NAL),在该模式下,数据流传输到解码器。 That makes decoder life easy to avoid mistake of treating any packet wrongly. 这使得解码器的寿命很容易避免错误地对待任何数据包的错误。

In case of packet loss, it is all about decoder resiliency approaches. 在丢包的情况下,全部与解码器弹性方法有关。 There is no standardized approach for packet (NALU) loss. 没有用于丢包(NALU)的标准化方法。 Some decoders do provide error concealment for packet loss scenarios. 一些解码器确实为丢包情况提供错误隐藏。

More Details Added: 添加了更多详细信息:

You need to have both header (RTP & NAL) parsing implementations on decoders side. 您需要在解码器端同时具有两个标头(RTP和NAL)解析实现。 As said above, it is better to have a signalling mechanism to indicate the mode in which the packet is sent to decoder. 如上所述,最好具有一种信令机制来指示将数据包发送到解码器的模式。 Since NAL header is subset in a given packet (exists in RTP and NAL), you better search for NAL start code first. 由于NAL标头是给定数据包中的子集(存在于RTP和NAL中),因此最好先搜索NAL起始码。 Once decoder finds the start code in a packet, check for number of bytes (x) consumed till that point. 解码器在数据包中找到起始代码后,请检查到该点为止消耗的字节数(x)。 If x is greater than RTP header size, start parsing in RTP mode from the beginning of the packet. 如果x大于RTP标头大小,则从数据包的开头开始以RTP模式进行解析。 If RTP parsing goes well (by validating some of the RTP fields against data in hand), decoder can conclude that packets are getting received in RTP mode. 如果RTP解析进行得很顺利(通过针对手中的数据验证一些RTP字段),则解码器可以得出结论,即以RTP模式接收到数据包。 Above approach is valid for Non-fragmented RTP packetization method. 以上方法对非分段RTP打包方法有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM