CAVLC and Cabac Introduction

Source: Internet
Author: User
cabac/cavlcin H . what is entropy coding.

Entropy coding compression is a lossless compression, and its implementation principle is to use the new encoding to represent the input data, so as to achieve the compression effect. The commonly used entropy coding has run-length coding, Huffman coding and CAVLC coding. CAVLC

CAVLC (Context Adaptive variablelength Coding) is the entropy coding method used in H.264/MPEG-4AVC. In H. CAVLC, the Zig-zag sequence is used to encode the transformed residual block. CAVLC is a CABAC alternative, although its compression efficiency is not as good as CABAC, but CAVLC implementation is simple and supported in all h.264profile.

The encoding process for CAVLC is as follows:

Calculates the number of non-0 coefficients (totalcoeffs) and trailing coefficients (trailingones).

The trailing factor refers to a factor of +1/-1, with a maximum number of 3. If there are more than 3, then only the last three are considered trailing coefficients. The number of trailing coefficients is assigned to the variable trailingones.
Non-0 coefficients include all trailing coefficients, the number of which is assigned to the variable totalcoeffs).

Calculates the NC (Numbercurrent, current block value).

The NC value is determined by the non-0 coefficient nA and the upper block non-0 NB of the left block, the formula is: Nc=round ((NA+NB)/2), if NA exists NB does not exist, then Nc=na, if Na does not exist and NB exists, then nc=nb, if Na and NB do not exist, then nc=0.
The NC value is used to select the VLC encoding table, as shown in the following figure. This embodies the context-sensitive (contextadaptive) characteristics, such as when the NC value is small, the surrounding block is less than 0 coefficients, it will choose a shorter code, thus achieving data compression.

Tabular gets the Coff_token encoding.

According to the variables totalcoeffs, trailingones and NC values obtained from the previous coding and calculation process, the Coeff_token coding sequence can be obtained by checking the standard Appendix CAVLC code table.

Encodes the symbol for each trailing factor, encoded in reverse order of ZIG-ZAG.

Each symbol is represented by 1 bit bits, 0 means "+" and 1 means "-".
When the trailing factor exceeds three, only the last three are considered as trailing coefficients, and the coding order of the primers is encoded from backward forward.

Encode a level (levels) that is not 0 coefficients apart from the trailing factor.

The level of each non-0 factor includes sign and magnitude, and the scanning sequence is the inverse zig-zag sequence. The level's encoding consists of a prefix (level_prefix) and a suffix (level_suffix). The length of the prefix is between 0 and 6, and the length of the suffix can be determined by the following steps: Initialize the suffix to 0. (unless the total number of 0 coefficients exceeds 10 and the trailing factor is less than 3, it is initialized to 1). A non-0 factor other than the trailing factor for the highest encoding frequency (that is, the last scan order). If the magnitude of this coefficient exceeds a certain threshold (threshold), the length of the suffix is increased. The following table is a list of threshold values:

Encode the number of the last non-0 coefficients before 0 (totalzeos).

Totalzeros refers to the number of the last non-0 coefficient before 0, this non-0 coefficient refers to the last non-0 coefficient according to the forward scan
According to the Totalcoeffs value, a total of 25 variable-length tables are available for searching, with 15 tables for encoding luminance data, 3 tables for the coded chroma dc2x2 block (4:2:0 format), and a coded chroma dc2x4 block (4:2:2 Format) has 7 tables.

Encode the number of front 0 of each coefficient (Run_before).

The scan sequence is in reverse order of ZIG-ZAG.
If ∑[run_before]== Total_zeros, no further calculations are required Run_before
The last element in the sweep sequence does not need to be calculated Run_before
The VLC encoding for each run_before depends on the run_before itself and the number of non-encoded 0 zerosleft. For example, if zerosleft== 2, then Run_before can only be 0,1 or 2, so a two bit can be used to represent.

CAVLC to teach you the code .

Transferred from: http://blog.csdn.net/sunshine1314/article/details/1685948

This blog uses examples to explain the above process in detail, especially on the calculation of levels has made important additions. Here is the full text of the reprint:

First of all, this article is not written by me, the article from my classmate (Sunrise), are to do together H264, comparative understanding, the content of the article is their own collation, more credible, so finishing together, I also stole a lazy ha

Again: The standard used in the article is the formal standard of BS, if we find that the serial number is not correct, refer to the changed to be!

Encoding procedure:
Suppose you have a 4*4 block
{
   0,   3,   -1,    0,
   0,   -1,   1,   0,
    1,   0,   0,   0,
   0,    0,    0,   0
}
Data rearrangement: 0,3,0,1,-1,-1,0,1,0 ...

1) Initial value setting: The number of
non-0 coefficients (totalcoeffs)  = 5;
The number of trailing factors (trailingones) = 3;
The last number of non-0 coefficients before 0 (total_zeros)  = 3;
variable nc=1;
(Description: NC

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.