"H.264/AVC Video Codec technology detailed" 12, analysis of the macro-block structure of the code stream (above)

Source: Internet
Author: User
Tags documentation
" H.264/AVC Video Codec technology detailed" video tutorial has been in the "CSDN College" on-line, the video details of the background, standard protocol and implementation, and through a practical project in the form of the standard of the resolution and realization of H. A, welcome to watch. "The paper came to the end of the light, I know this matter to preach", only by themselves in accordance with the standard document in the form of code to operate, in order to the video compression coding standard ideas and methods have enough deep understanding and experience. link Address: H.264/AVC Video codec technology detailed GitHub code Address: Click here Analysis of Slice body--macro block structure (macroblock) in H . definition of 1.SLICE data structure

After a slice header has been implemented, the following work will be done on how to parse the body of a slice, the slice body part. The body part of a slice is mainly composed of a macro block structure macroblock, in addition there are some auxiliary information. The Slice_data () structure specified in the standard documentation is as follows:

As we can see from the documentation, there are not many independent grammatical elements in the slice_data structure, mainly only the following: cabac_alignment_one_bit: Indicates that if the CABAC algorithm is enabled for the bitstream, Then the bitstream must use several bits 1 to achieve byte alignment. Mb_skip_run and Mb_skip_flag: Both syntax elements are used to indicate whether a macro block structure can be skipped. "Skip" macro block refers to the slice in the prediction between frames, when the image area is flat, the code stream skips all the data of the macro block, not transmitted, only through the two grammatical elements are marked. At the decoding end, the skipped macro blocks are restored by the macro blocks that have been rebuilt around them. Mb_skip_run used for entropy coding when using CAVLC, a syntax element is used to denote the number of macro blocks that are skipped continuously, and mb_skip_flag is used for entropy coding when using CABAC to indicate whether each macro block is skipped. Mb_field_decoding_flag: The identity bit, used to identify whether a macro block is a frame mode or a field pattern in the frame-field adaptive stream. End_of_slice_flag: An identity bit in Cabac mode that indicates whether the end of the slice is reached.

Some of these grammatical elements undoubtedly take up only a small portion of the total data, and most of the data is contained in the macro block structure, the macroblock_layer () structure in the table above. 2. Macro block (MACROBLOCK) structure

As we can see from the above table, the macro block in a slice structure actually occupies the majority. In the standard, the structure of a macro block is defined as the following table:

(1). Mb_type:

In a macro block, the first syntax element is the type of the macro block:mb_type. We can see from the table that, according to whether the value of Mb_type equals I_PCM, the whole analytic method is divided into two categories: PCM type and non-PCM type, judging by the I_PCM mode when Mb_type is 25, otherwise non-I_PCM mode.

When this macro block is in I_PCM mode, the macro blocks are stored in a differential encoding to preserve the original pixel values of the macro block. There are a few grammatical elements: pcm_alignment_zero_bit: Fill bits, fill with bit zeros until byte-aligned, Pcm_sample_luma: 256 differential pixel values for luminance components; Pcm_sample_chroma: The difference pixel value of several chroma components, the actual number is specified by the color format of the stream. For example, for the most commonly used 4:2:0 format video, there are 128 chroma pixel values.

Except that Mb_type equals 25 o'clock can be determined to be I_PCM format, other mb_type values may vary depending on the frame type (or slice type). For example, I slice,mb_type the non-PCM mode can choose to 0~24 one of these values, for P Slice,mb_type can only take 0~4 these 5 values, for B slice,mb_type can take 0~22 one of these values. The current stream we are dealing with is all made up of I frames, so we only consider the case of I slice for the time being. The following figure is part of the Mb_type list of the I slice specified in the standard document, and the complete list is in table 7-11 of the Protocol document:

As we can see from the above table, Mb_type not only represents the segmentation of macro blocks, but also contains some additional information, such as intra-frame prediction mode, brightness and chroma component Coded_block_pattern. When the in-frame prediction uses 16x16 mode, the macro block has the same predictive information for the entire macro block, so you do not need to specify the forecast mode for each of the sub-macro blocks, which effectively reduces the consumed code flow. (2). Transform_size_8x8_flag

The syntax element is an identity bit that represents the size that is used to decode the transformation coefficients of the predicted residuals before the loop filter. When the identity bit is 1 o'clock, the predicted residuals are decoded according to the 8x8 pixel block, and when the flag bit does not exist or 0 o'clock, the predicted residuals are decoded according to a 4x4 block of pixels. (3). Coded_block_pattern

Coded_block_pattern syntax elements are often abbreviated as CBP, which is used to denote which of the 4 8x8 sub-block encodings in the current macro block encode which residual coefficients. It is important to note that this syntax element only exists when the macro block is in non-i_16x16 mode, because the information about CBP is already reflected in Mb_type in i_16x16 mode. (4). Mb_qp_delta

Mb_qp_delta represents the quantization parameter offset value for the macro block layer, with a value range of [-26, 25]. We have obtained the initial value of the quantization parameter of the entire sequence in PPS (computed by PIC_INIT_QP_MINUS26), and obtained the quantization parameter offset Slice_qp_delta of the slice layer in the slice header, Therefore, the quantization parameters of the first macro block of each slice can be calculated by the following formula:
Qp0=pic_init_qp+26+slice_qp_delta+mb_qp_delta Qp_0 = pic\_init\_qp + + Slice\_qp\_delta + Mb\_qp\_delta
Starting with the second macro block, the actual quantization parameters for each macro block are calculated as:
Qpn= (qpm+mb_qp_delta+52)%52 Qp_n = (qp_m + Mb\_qp\_delta + 52) \%52

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.