"H.264/AVC Video codec technology specific explanation" 13, Entropy coding Algorithm (3): CAVLC principle

Source: Internet
Author: User

"H.264/AVC Video codec technology specific explanation" video tutorial has been on the "CSDN College" on-line. The video details the background, standard protocol and implementation, and through a real project in the form of the standard of the resolution and implementation, welcome to watch! "The paper came to light, I know this matter to preach." Only have their own in accordance with the standard document in the form of code, the ability of the video compression coding standard ideas and methods have enough deep understanding and experience! Link Address: H.264/AVC Video codec technology specific explanation GitHub code address: Click here Contextual adaptive variable length encoding (context-based Adaptive Variable Length Coding, CAVLC) 1. Introduction

In the previous chapters of the blog/video, we have learned that entropy coding is a lossless coding method that uses statistical redundancy of information for data compression . And we have discussed the basic principle of entropy coding , the algorithm and practice of " exponential Columbus Code ", which is used in the parsing algorithm of grammatical elements in H.

    • "H.264/AVC Video codec technology specific explanation" seven, Entropy Coding algorithm (1): basic knowledge
    • "H.264/AVC Video codec technology specific explanation" Eight, Entropy coding algorithm (2): Entropy coding basic method, exponent Columbus code in H.

In the analysis of the structure (such as nal Unit, Slice header, etc.) we have implemented, most of them are implemented using fixed length coding or exponential Columbus coding. Data such as pre-test residuals that occupy a large volume of code streams must use algorithms with higher compression ratios, such as CAVLC and Cabac. The former is what we will discuss in this article. The latter will be detailed in the content.

2. Fundamentals of CAVLC

We know. The full name of CAVLC is called "context-adaptive variable-length encoding context-based Adaptive Variable Length Coding". The so-called "context-adaptive", shows that the CAVLC algorithm is not the same as the exponential Columbus code with a fixed code stream-code-word mapping coding, but a dynamic encoding algorithm, so the compression ratio is far more than the fixed variable length encoding UVLC algorithm.

The CAVLC is mainly used for pre-tested residual coding in the H.

In the second post of this series, we give the coded flow graph of H. I, in which we know that the input of entropy code is the coefficient matrix after the transformation-quantization of the pre-measured residuals between frames/frames.

In the case of a 4×4-sized coefficient matrix, after transformation-quantization, the matrix usually presents the following characteristics:

    1. The matrix after the transformation quantization usually has the sparse characteristic. That is, most of the data in the matrix is 0. CAVLC can efficiently compress continuous 0 coefficient strings through run-length coding;
    2. The highest frequency non-0 coefficient of the coefficient matrix after zig-zag scanning is usually a data string with a value of ±1. CAVLC is able to encode high frequency components efficiently by transmitting a continuous length of +1 or-1;
    3. The amplitude of a non-0 coefficient is usually larger near the DC (i.e. DC component) part. And in the high-frequency part smaller.
    4. The number of non-0 coefficients in matrices is related to neighboring blocks;

In view of the above characteristics 3 and 4, for the coefficients to be encoded in the coefficient matrix in different locations, as well as the adjacent blocks of information, in the code with a different code table encoding. Such a feature of the CAVLC. Embodies the "context-adaptive" approach in naming.

3. Coding process for CAVLC

In CAVLC, entropy coding is not coded for a certain code element like Huffman coding, but for a coefficient matrix. If we want to CAVLC encode an example of one of the following transformation coefficient blocks:

{    3,  2, -1,  0,    1,  0,  1,  0,    -1, 0,  0,  0,    0,  0,  0,  0,}

CAVLC encoding for a 4x4-sized transformation coefficient matrix. It needs to be scanned first. Converts a two-dimensional matrix into a one-dimensional array.

As mentioned in the previous section, the scans follow the Zig-zag sequence. That is, for example, in the following order:

Therefore, the transformation coefficients will be arranged again after the scan, resulting in:

[3, 2, 1, -1, 0, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]

The following important grammatical elements need to be noted in the coding process:

    • Number of non-0 coefficients (totalcoeffs): The value range is [0, 16], that is, the current coefficient matrix contains how many non-0 value elements;
    • The number of trailing coefficients (trailingones): The range of values is [0, 3], which indicates the number of values of the highest frequency as ±1 coefficients.

      The trailing factor is no more than 3, and if exceeded, only the last 3 are considered to be trailing coefficients, others are used as ordinary non-0 coefficients;

    • Symbol for trailing factor: 1 bit, 0 = +. 1 means-;
    • Current block value (numbercurrent): Used to select the Code table. Calculated from the number of non-0-series numbers of adjacent blocks above and to the left.

      Set the current block value to NC, the upper adjacent block is not 0 series number is NA. The left side adjacent block non-0 series number is NB, the formula is NC = Round ((NA + NB)/2), for the chromaticity of the DC coefficient, NC =-1;

    • The amplitude of the ordinary non-0coefficient (level): The encoding of the amplitude is divided into prefix and suffix two parts.

      The encoding process is encoded in reverse order. Starting from the highest frequency non-0 factor.

    • The number of 0 before the last non-0 coefficient (totalzeros);
    • Number of 0 before each non-0 coefficient (runbefore): According to the inverse sequence code, that is, from the highest-frequency non-0 coefficient start, for the last non-0 coefficient (that is, the low-frequency non-0 coefficient) before the number of 0. And no remaining 0 coefficients are required to encode. No further coding is required.

In each of these types of data, the level that encodes a non-0 factor is the most complex.

The main processes are:

    1. Determine the value of the Suffixlength:
      • Suffixlength initialization: Normally initialized to 0, when Totalcoeffs is greater than 10 and trailingones is less than 3 o'clock, it is initialized to 1;
      • If the number of non-0 coefficients that have been coded is greater than the threshold, then suffixlength plus 1. The threshold value is defined as 3 << (Suffixlength 1). After the first level is encoded. Suffixlength should be added 1;
    2. Converts the signed level value to an unsigned levelcode:
      • If level > 0,levelcode = (level << 1)-2;
      • If level < 0,levelcode =-(Level << 1)-1;
    3. The coding level_prefix:level_prefix is calculated as: Level_prefix = levelcode/(1 << suffixlength), and the corresponding relation of Level_prefix to Bitstream is represented by 9-6;
    4. Determine the length of the suffix: the length of the suffix levelsuffixsize is usually equal to suffixlength. Exceptions are:
      • Level_prefix = 14 o'clock. Suffixlength = 0, levelsuffixsize = 4;
      • Level_prefix = 15 o'clock, levelsuffixsize = 12;
    5. Calculate the value of the Level_suffix: Level_suffix = levelcode% (1 << suffixlength);
    6. According to the length of levelsuffixsize coding level_suffix;

In the above coefficient matrix, the number of non-0-series is totalcoeffs=6, the number of trailing coefficients is trailingones=3, and the last non-0 coefficient is 0 before the number totalzeros=2; if nc=0.

  1. In table 9-5 of the standard protocol document, the value of Coeff_token is 0x00000100;
  2. The symbol of the trailing factor, from high frequency to low frequency, trailing factor symbol is + 、-、-, so the code stream of the symbol is 011.
  3. Encode the amplitude of non-0 coefficients, three ordinary non-0 coefficients are 1, 2, 3 respectively;
    1. The encoded 1:suffixlength is initialized to 0;levelcode=0;level_prefix=0, and the corresponding code stream for the check table is 1. suffixlength=0, so incorrect suffix coding;
    2. The encoded 2:suffixlength 1 is equal to 1. Levelcode=2;level_prefix=1, check the table that the corresponding code stream for the suffixlength=1,level_suffix=0, so the suffix stream is 0.
    3. Encoding 3:suffixlength does not meet the self-increment condition, still 1. levelcode=4;level_prefix=2. The check table shows that the corresponding code stream is 001. Suffixlength=1. Level_suffix=0, so the suffix stream is 0;
    4. In summary, the value of the amplitude portion of the non-0 coefficients is 10100010.
  4. Encode the last non 0 coefficients before the number of 0 totalzeros:totalcoeffs=6,totalzeros=2. In table 9-7, the code stream is 111.
  5. Encode the number of the first 0 of each non-0 coefficient: from high frequency to low frequency, each non-0 coefficient of the total number of 0 (Zerosleft) is 2, 1, 0, 0, 0, 0, each non-0 coefficient before the number of consecutive 0 (run_before) 1, 1, 0, 0, 0, 0. According to the standard document table 9-10 available:
    • Run_before=1. zerosleft=2, the corresponding code flow for the;
    • Run_before=1. Zerosleft=1, the corresponding code stream is 0;
    • All 0 coefficients have been encoded and no further coding is required;

Sum up. After the entire 4x4 coefficient matrix has been CAVLC encoded, the output stream is: 0000010001110100010111010.

"H.264/AVC Video codec technology specific explanation" 13, Entropy coding Algorithm (3): CAVLC principle

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.