CAVLC

1.什么是CAVLC?

Context Adaptive Variable Length Coding (CAVLC) is a method used to encode residual, scan ordered blocks of transform coefficients.

2.CAVLC是怎么工作?

  1. 对于量化后的4 * 4的block, CAVLC使用run-level来represent strings of zeros.
  2. Context Adaptive 的意思就是通过上下文自动调节的一种编码,所以这边CAVLC是通过附近4 * 4的block的情况来选择自己的"VLC table", 用这个VLC talbe 来编码 coeff_token.
  3. 对于高频的值,如果取值为1,-1之类的。使用"Trailing 1s" or "T1s" 来表示. 0代表1, 1代表-1. 最多只能表示3个trailing ones.
  4. CAVLC编码包括一下几个步骤
1.编码 coeff_token, coeff_token代表了有多少个trailing zeros, 以及有多少个no-zero coefficients
2.编码trailing ones, 代表了是+1 还是 -1
3.编码non-zero coefficients 的值,从高频到低频
4.编码最后一个none-zero coefficients 之前的所有的0的个数
5. 编码每个none-zero coefficients 之前有多少个0

3.CAVLC工作流程图

image

4. 编码coeff_token 以及 VLC Table 的选择

coeff_token必须使用VLC Table来查找对应的二进制.
coeff_token 编码了 Toal-Coeffs 代表非 0 coefficient的个数,取值从0到16.同时也编码了 Trailiing 1sT1s). 从 0 到 3. 代表有多少个coefficient数据是1 或者 -1,从高频到低频排序.
For Luma, Chroma DC (4:4:4) and Chroma AC.
(T1, numCoeff) will be coded based on nCContext. nCContext = (nCA + nCB + 1) >> 1. nCA is the number of nonzero coefficients available in the left 4x4 submacroblock and nCB is the number of nonzero coefficients available in the up 4x4 submacroblock.
如果nCb不可以用,nCC = nCb.
如果nCa不可以用,nCC = nCa.
如果两者都不可以用,nCC = 0;
根据nC,T1 ,numCoeff 编码 coeff_token,如下图
image
image
image

For ChromaDC.

If chroma_format_idc is equal to 1, nC is set equal to -1
Otherwise,if chroma_format_idc is equal to 2, nC is set equal to -2
Otherwise (chroma_format_idc is equal to 3), nC is set equal to 0
image

5. 编码 trailing 1s 的符号位

顺序为从高频到低频, 0 = +1, 1 = -1.

6. 编码 level of remaing non-zero coefficients.

level 由两个部分组成 prefix 和 suffix. 通俗的来说就是,prefix代表了高位的数据,suffix代表了低位的数据.
prefix总是以1结尾.
image
官方decoding代码
image
Encoding level算法
image
image
encoding level算法的例子.
假设如下4*4block
image
Reordered block:−2, 4, 3, −3, 0, 0, −1, ...
TotalCoeffs = 5
TotalZeros = 2
T1s = 1

  1. encoding a = -3的时候.
    step2: |a| = |a| - 1. a = -2;
    |a| < 8, number of zeros = 2 * (|-2| - 1) + (1) = 3;
    所以值就为 <0001><>
    更新suffxLength = 1;
  2. encoding a = 3的时候.
    step3: |a| = |a| - 1, a = 2;
    step5: 符号为正数, 所以suffix的最后一位为0.
    step7: number of remaing zeros = 2;
    所以值为<001><0>
  3. encoding a = 4的时候.
    step3: |a| = |a| - 1, a = 3;
    step5:符号为正数, 所以suffix的最后一位为0.
    step7: number of remaing zeros = 3;
    值为<0001><0>
    更新suffxLength = 2;
    4.encoding a = -2
    step5: suffix 最后一位,符号位为1.
    step6: |a| - 1 = 1B(二进制的1). suffix就为<11>
    step7: number of zeros = 0;
    值为<1><11>

7.编码 total number of zeros before the last coefficient

For Luma, Chroma DC (4:4:4) and Chroma AC, the (total_zeros, numCoeff) table
image


For Chroma DC (4:2:0), the code for total_zeros
image


for Chroma DC (4:2:2)
image

8.编码 run before

image

需要注意的点

  1. CAVLC uses run-level coding to to compactly represent strings of zeros.
  2. if CAVLC is used with 8 * 8 interger transform, each 8 * 8 block of quantized transform coeffients is processed as 4 * 4 blocks for the purpose of CAVLC encoding and decoding.

资料来源

  • The H.264 Advanced Video Compression Standards
  • T-REC-H.264-200503-S!!PDF-E
  • CAVLC (Context based Adaptive Variable Length Coding)
posted @ 2021-05-06 22:11  哇哩顾得  阅读(979)  评论(5编辑  收藏  举报