Chinaunix首页 | 论坛 | 博客
  • 博客访问: 33200
  • 博文数量: 11
  • 博客积分: 1420
  • 博客等级: 上尉
  • 技术积分: 65
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-04 11:38
文章分类
文章存档

2010年(11)

我的朋友
最近访客

分类: 嵌入式

2010-06-10 09:49:40

H.264 NAL格式及分析器程序源代码
          email:zsw_davy@hotmail.com

H.264 AVC SPEC 3 关于NAL解码的说明
ANNEX B Byte stream format
(This annex forms an integral part of this Recommendation | International Standard)
This annex specifies syntax and semantics of a byte stream format specified for use by applications that deliver 

some or
all of the NAL unit stream as an ordered stream of bytes or bits within which the locations of NAL unit boundaries 

need
to be identifiable from patterns in the data, such as ITU-T Recommendation H.222.0 | ISO/IEC 13818-1 systems or
ITU-T Recommendation H.320 systems. For bit-oriented delivery, the bit order for the byte stream format is 

specified to
start with the MSB of the first byte, proceed to the LSB of the first byte, followed by the MSB of the second 

byte, etc.
The byte stream format consists of a sequence of byte stream NAL unit syntax structures. Each byte stream NAL unit
syntax structure contains one start code prefix followed by one nal_unit( NumBytesInNALunit ) syntax structure. It 

may
(and under some circumstances, it shall) also contain an additional zero_byte syntax element. It may also contain 

one or
more additional trailing_zero_8bits syntax elements. When it is the first byte stream NAL unit in the bitstream, 

it may
also contain one or more additional leading_zero_8bits syntax elements
B.1.2 Byte stream NAL unit semantics
The order of byte stream NAL units in the byte stream shall follow the decoding order of the NAL units contained 

in the
byte stream NAL units (see subclause 7.4.1.2). The content of each byte stream NAL unit is associated with the 

same
access unit as the NAL unit contained in the byte stream NAL unit (see subclause 7.4.1.2.3).
leading_zero_8bits is a byte equal to 0x00.
NOTE – The leading_zero_8bits syntax element can only be present in the first byte stream NAL unit of the 

bitstream, because (as
shown in the syntax diagram of subclause B.1.1) any bytes equal to 0x00 that follow a NAL unit syntax structure 

and precede the
four-byte sequence 0x00000001 (which is to be interpreted as a zero_byte followed by a 

start_code_prefix_one_3bytes) will be
considered to be trailing_zero_8bits syntax elements that are part of the preceding byte stream NAL unit.
zero_byte is a single byte equal to 0x00.
When any of the following conditions are fulfilled, the zero_byte syntax element shall be present.
– the nal_unit_type within the nal_unit( ) is equal to 7 (sequence parameter set) or 8 (picture parameter set)
– the byte stream NAL unit syntax structure contains the first NAL unit of an access unit in decoding order, as
specified by subclause 7.4.1.2.3.
start_code_prefix_one_3bytes is a fixed-value sequence of 3 bytes equal to 0x000001. This syntax element is called 

a
start code prefix.
trailing_zero_8bits is a byte equal to 0x00.
 
B.2 Byte stream NAL unit decoding process
Input to this process consists of an ordered stream of bytes consisting of a sequence of byte stream NAL unit 

syntax
structures.
Output of this process consists of a sequence of NAL unit syntax structures.
At the beginning of the decoding process, the decoder initialises its current position in the byte stream to the 

beginning of
the byte stream. It then extracts and discards each leading_zero_8bits syntax element (if present), moving the 

current
position in the byte stream forward one byte at a time, until the current position in the byte stream is such that 

the next
four bytes in the bitstream form the four-byte sequence 0x00000001.
The decoder then performs the following step-wise process repeatedly to extract and decode each NAL unit syntax
structure in the byte stream until the end of the byte stream has been encountered (as determined by unspecified 

means)
and the last NAL unit in the byte stream has been decoded:
1. When the next four bytes in the bitstream form the four-byte sequence 0x00000001, the next byte in the byte
stream (which is a zero_byte syntax element) is extracted and discarded and the current position in the byte
stream is set equal to the position of the byte following this discarded byte.
2. The next three-byte sequence in the byte stream (which is a start_code_prefix_one_3bytes) is extracted and
discarded and the current position in the byte stream is set equal to the position of the byte following this 

threebyte
sequence.
3. NumBytesInNALunit is set equal to the number of bytes starting with the byte at the current position in the 

byte
stream up to and including the last byte that precedes the location of any of the following conditions:


a. A subsequent byte-aligned three-byte sequence equal to 0x000000, or
b. A subsequent byte-aligned three-byte sequence equal to 0x000001, or
c. The end of the byte stream, as determined by unspecified means.
4. NumBytesInNALunit bytes are removed from the bitstream and the current position in the byte stream is
advanced by NumBytesInNALunit bytes. This sequence of bytes is nal_unit( NumBytesInNALunit ) and is
decoded using the NAL unit decoding process.


5. When the current position in the byte stream is not at the end of the byte stream (as determined by unspecified
means) and the next bytes in the byte stream do not start with a three-byte sequence equal to 0x000001 and the
next bytes in the byte stream do not start with a four byte sequence equal to 0x00000001, the decoder extracts
and discards each trailing_zero_8bits syntax element, moving the current position in the byte stream forward
one byte at a time, until the current position in the byte stream is such that the next bytes in the byte stream 

form
the four-byte sequence 0x00000001 or the end of the byte stream has been encountered (as determined by
unspecified means).
B.3 Decoder byte-alignment recovery (informative)
This subclause does not form an integral part of this Recommendation | International Standard.
Many applications provide data to a decoder in a manner that is inherently byte aligned, and thus have no need for 

the
bit-oriented byte alignment detection procedure described in this subclause.
A decoder is said to have byte-alignment with a bitstream when the decoder is able to determine whether or not the
positions of data in the bitstream are byte-aligned. When a decoder does not have byte alignment with the encoder

’s byte
stream, the decoder may examine the incoming bitstream for the binary pattern '00000000 00000000 00000000
00000001' (31 consecutive bits equal to 0 followed by a bit equal to 1). The bit immediately following this 

pattern is the
first bit of an aligned byte following a start code prefix. Upon detecting this pattern, the decoder will be byte 

aligned
with the encoder and positioned at the start of a NAL unit in the byte stream.
Once byte aligned with the encoder, the decoder can examine the incoming byte stream for subsequent three-byte
sequences 0x000001 and 0x000003.
When the three-byte sequence 0x000001 is detected, this is a start code prefix.
250 VERSION 3 OF ITU-T Rec. H.264 (E)
When the three-byte sequence 0x000003 is detected, the third byte (0x03) is an emulation_prevention_three_byte to 

be
discarded as specified in subclause 7.4.1.
The byte alignment detection procedure described in this subclause is functionally equivalent to searching a byte
sequence for three consecutive zero-valued bytes (0x000000), starting at any alignment position. Detection of this
pattern indicates that the next non-zero byte contains the end of a start code prefix (as a conforming byte stream 

cannot
contain more than 23 consecutive zero-valued bits without containing 31 or more consecutive zero-valued bits, 

allowing
detection of 0x000000 relative to any starting alignment position), and the first non-zero bit in that next non-

zero byte is
the last bit of an aligned byte and is the last bit of a start code prefix.

阅读(2096) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~