Introduction to H.264: (2) SODB vs RBSP vs EBSP
SODB + RBSP Stop bit + 0 bit(s) => RBSP
RBSP part 1 + 0x03 + RBSP part 2 + 0x03 + … + RBSP part n => EBSP
In Byte Stream Format (Annex B),
String of Data Bits (SODB)
3.149 string of data bits (SODB): A sequence of some number of bits representing syntax elements present within a raw byte sequence payload prior to the raw byte sequence payload stop bit. Within an SODB, the left-most bit is considered to be the first and most significant bit, and the right-most bit is considered to be the last and least significant bit.
To form a NALU, we need the raw data and we call it String of Data Bits. It is a bitstream of coded raw H.264 data stream and defined by MPEG Part 10 (Free Download). So, it does not include the 3-byte / 4-byte start code, 0x000001 or 0x00000001 and not include the 1-byte NALU header  which contains some basic information of the NALU such as NAL unit type.
Raw Byte Sequence Payload (RBSP)
3.118 raw byte sequence payload (RBSP): 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 SODB containing syntax elements followed by an RBSP stop bit and followed by 0 or more subsequent bits equal to 0.
3.119 RBSP stop bit: A bit equal to 1 present within a RBSP after a SODB. The location of the end of the SODB 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.
After getting the SODB, a rbsp trailing bit equals to 1 is added to indicate the end of the SODB so the bit is called stop bit (rbsp_stop_one_bit). Also, RBSP is always byte aligned and some 0 bits are added after the stop bit to make it 8-bit aligned.
In short, two things are added to the end of SODB in order to form a RBSP:
- rbsp_stop_one_bit = 1
- rbsp_alignment_zero_bit(s) = 0(s) [[Must make the SODB byte-aligned]]
Encapsulate Byte Sequence Payload (EBSP)
I mentioned that we need to prefix the NAL Units with the start code 0x000001 / 0x00000001 in byte stream format in order to identify their boundaries . Yet, there may exist the pattern 0x00000X, where X is 0, 1, 2 or 3, in the RBSP and have emulation of start code. To ease the decoding process, a emulation_prevention_three_byte (0x03) is added after 0x0000 and it becomes 0x0000030X:
- 0x000000 => 0x00000300
- 0x000001 => 0x00000301
- 0x000002 => 0x00000302
- 0x000003 => 0x00000303
Since emulation_prevention_three_byte doesn’t affect the decoding result, the decoder should ignored it.
Form NAL Unit from SODB, RBSP & EBSP
126.96.36.199 Encapsulation of an SODB within an RBSP (informative)
The form of encapsulation of an SODB within an RBSP and the use of the emulation_prevention_three_byte for encapsulation of an RBSP within a NAL unit is specified for the following purposes:
– to prevent the emulation of start codes within NAL units while allowing any arbitrary SODB to be represented within a NAL unit,
– to enable identification of the end of the SODB within the NAL unit by searching the RBSP for the rbsp_stop_one_bit starting at the end of the RBSP,
– to enable a NAL unit to have a size larger than that of the SODB under some circumstances (using one or more cabac_zero_word).
The encoder can produce a NAL unit from an RBSP by the following procedure:
1. The RBSP data is searched for byte-aligned bits of the following binary patterns:
‘00000000 00000000 000000xx’ (where xx represents any 2 bit pattern: 00, 01, 10, or 11), and a byte equal to 0x03 is inserted to replace these bit patterns with the patterns:
‘00000000 00000000 00000011 000000xx’, and finally, when the last byte of the RBSP data is equal to 0x00 (which can only occur when the RBSP ends in a cabac_zero_word), a final byte equal to 0x03 is appended to the end of the data. The last zero byte of a byte-aligned three-byte sequence 0x000000 in the RBSP (which is replaced bythe four-byte sequence 0x00000300) is taken into account when searching the RBSP data for the next occurrence of byte-aligned bits with the binary patterns specified above.
2. The resulting sequence of bytes is then prefixed as follows:
– If nal_unit_type is not equal to 14 or 20, the sequence of bytes is prefixed with the first byte of the NAL unit containing the syntax elements forbidden_zero_bit, nal_ref_idc, and nal_unit_type, where nal_unit_type indicates the type of RBSP data structure the NAL unit contains.
– Otherwise (nal_unit_type is equal to 14 or 20), the sequence of bytes is prefixed with the first four bytes of the NAL unit, where the first byte contains the syntax elements forbidden_zero_bit, nal_ref_idc, and nal_unit_type and the following three bytes contain the syntax structure nal_unit_header_svc_extension( ).
The syntax element nal_unit_type in the first byte indicates the presence of the syntax structure nal_unit_header_svc_extension( ) in the following three bytes and the type of RBSP data structure the NAL unit contains.
The process specified above results in the construction of the entire NAL unit.
This process can allow any SODB to be represented in a NAL unit while ensuring that
– no byte-aligned start code prefix is emulated within the NAL unit,
– no sequence of 8 zero-valued bits followed by a start code prefix, regardless of byte-alignment, is emulated within the NAL unit.
 Refer to last article: “Introduction to H.264: (1) NAL Unit”
 Reference from 14496-10 on Page 2