NALU

NALU

H.264码流在网络中传输时实际是以NALU的形式进行传输的.

NALU_第1张图片
NALU结构

每个NALU一个字节HeaderRBSP组成.

NAL Header
NALU_第2张图片
NAL Header
  • forbidden_zero_bit

forbidden_zero_bit shall be equal to 0.

  • nal_ref_idc
    用于表示当前NALU的重要性,值越大,越重要.
    解码器在解码处理不过来的时候,可以丢掉重要性为0的NALU.
NALU_第3张图片
nal_ref_idc

nal_ref_idc不等于0时, NAL unit的内容可能是SPS/PPS/参考图像的片等.
nal_ref_idc等于0时,NAL unit的内容可能是非参考图像的片等.

nal_ref_idc shall not be equal to 0 for sequence parameter set or picture parameter set NAL units.
When nal_ref_idc is equal to 0 for one slice or slice data partition NAL unit of a particular picture, it shall be equal to 0 for all slice and slice data partition NAL units of the picture.

SPS/PPS时,nal_ref_idc不可为0.
当某个图像的片的nal_ref_id等于0时,该图像的所有片均应等于0.

nal_ref_idc shall not be equal to 0 for IDR NAL units, i.e., NAL units with nal_unit_type equal to 5.
nal_ref_idc shall be equal to 0 for all NAL units having nal_unit_type equal to 6, 9, 10, 11, or 12.

NALU_第4张图片
The relationship of nal_unit_type and nal_ref_idc
  • nal_unit_type

nal_unit_type specifies the type of RBSP data structure contained in the NAL unit as specified in Table 7-1.

NALU_第5张图片
NAL unit type codes

nal_unit_type从是否包含VCL层编码数据分为VCL NAL unitsnon-VCL NAL units.
VCL NAL units中包含VCL层编码输出的数据, 而non-VCL NAL units不包括.

NALU_第6张图片
VCL NAL units & non-VCL NAL units

VCL NAL units常用的是nal_unit_type=5nal_unit_type=1.
nal_unit_type=5表明该NALU的类型是IDR的slice, 也表明该NALU所在图像也属于IDR帧.
nal_unit_type=1时一般表示该NALU所在的帧是P帧.

RBSP(Raw Byte Sequence Payload)

A syntax structure containing an integer number of bytes that is
encapsulated in a NAL unit
.
An RBSP is either empty or has the form of a string of data bits containing syntax
elements followed by an RBSP stop bit and followed by zero or more subsequent bits equal to 0.

  • (RBSP) stop bit

A bit equal to 1 present within a raw byte sequence payload
(RBSP) after a string of data bits. The location of the end of the string of data bits within an RBSP can be identified by searching from the end of the RBSP for the RBSP stop bit, which is the last non-zero bit in the
RBSP.

stop bit用于标示RBSP中数据部分的结束. 其后会填充0.

An RBSP is specified as an ordered sequence of bytes as follows.
The RBSP contains an SODB as follows.

  • If the SODB is empty (i.e., zero bits in length), the RBSP is also empty.
  • Otherwise, the RBSP contains the SODB as follows.
  1. The first byte of the RBSP contains the (most significant, left-most) eight bits of the SODB; the next byte of the RBSP shall contain the next eight bits of the SODB, etc., until fewer than eight bits of the SODB remain.
  2. rbsp_trailing_bits( ) are present after the SODB as follows:
    i) The first (most significant, left-most) bits of the final RBSP byte contains the remaining bits of the SODB, (if any)
    ii) The next bit consists of a single rbsp_stop_one_bit equal to 1, and
    iii) When the rbsp_stop_one_bit is not the last bit of a byte-aligned byte, one or more rbsp_alignment_zero_bit is present to result in byte alignment.
  3. One or more cabac_zero_word 16-bit syntax elements equal to 0x0000 may be present in some RBSPs after the rbsp_trailing_bits( ) at the end of the RBSP.

SODB(String Of Data Bits):
最原始的编码数据RBSP, 长度不一定是8的倍数,此时需要对齐. 
RBSP: 在SODB的后面填加了结尾比特(RBSP trailing bits 一个bit“1”)若干比特“0”,以便字节对齐.

NALU_第7张图片
RBSP

References:
14496-10.pdf
14496-15.pdf
http://blog.csdn.net/newthinker_wei/article/details/8748442
http://www.360doc.com/content/14/0520/17/17532616_379388909.shtml
http://www.samirchen.com/video-concept/

你可能感兴趣的:(NALU)