CALVC Tutorial
CALVC Tutorial
log
2
x
2
k
+1
(2.1)
The length of sufx binary string is equal to l + k, and the value of the sufx
string is:
EGk
sufx
= x +2
k
2
k+l
(2.2)
UEGk is combined binarization scheme of TU and EGk. It is utilized for
binarization of SEs of absolute value of residual coefcient level and MVD. TU
generates prex of the bin string, and EGk is adopted to generate the sufx with k
set to 0 and 3 for coefcient level and MVD, respectively. TU is simple and it per-
mits fast adaptation of probability of coding symbol. However, it is only benecial
for small SE values. For large SE values, sufx bin string generated by EGk pro-
vides a good t to the probability distribution, and bypass bin coding is also utilized
to reduce computation complexity.
2.3.2 Context Modeling
The context modeling step shown in Fig. 2.4 implements two sub-functions:
context model selection and context model access. The statistics of the coded SEs
are utilized to update the probability models (context model) [Wiegand03] of reg-
ular bins. For regular bin coding, one context model is chosen, and fetched from a
pre-dened set of context models to provide the probability of regular bin to be MPS
or LPS, and the context model is updated after bin coding based on bin value. The
context index (CtxIdx) is calculated to select context model, which is the sumof con-
text offset (CtxOffset) and context index increment (CtxIdxInc). CtxOffset locates the
context model set of processed SE, while CtxIdxInc selects one context model from
the set based on the values of coded bins or coded SEs of neighboring coded blocks.
The idea of multiplication-free arithmetic coding of H.264/AVC is based on the
assumption that estimated probability of each context model can be represented by a
sufciently limited set of representative values. In CABAC, the number of the repre-
sentative values is set to 64 to enable accurate estimation, which is larger than the 30
of Q-coder. Each context model contains a 1-bit tag of MPS value, and a 6-bit prob-
ability state index (pStateIdx) that addresses one of 64 representative probability
36 2 Review of CAVLC, Arithmetic Coding, and CABAC
values of LPS from p
0
to p
63
in the range of [0.01875, 0.5]. The probability values
of LPS are derived from (2.3). The ratio of two neighboring probability values is a
constant value , which is approximately equal to 0.949.
p
= p
1
for : = 1, . . . , 63, =
0.01875
0.5
1/63
, and p
0
= 0.5
(2.3)
Probability update of context model is based on the rule in (2.4), in which p
old
and p
new
are the probabilities for the bin to be LPS before and after bin coding. If
the coding bin is MPS, the probability of LPS decreases by simply multiplying the
ratio , while for the LPS bin, the update probability of MPS is calculated rst, and
then the probability of LPS is obtained.
p
new
=
max( p
old
, p
62
), if bin = MPS
1 (1 p
old
), if bin = LPS
(2.4)
By mapping the update probability value of LPS of (2.4) to the closest value in
the aforementioned set of representative values, multiplication of probability esti-
mation of CABAC is replaced by simple table lookup for the pStateIdx of next
probability state according to pStateIdx of the current bin, and based on whether it is
MPS or LPS. This probability value estimation of context state is actually the func-
tion state transition of FSM with 64 predened states. This type of probability FSM
is rst utilized in Q-coder, and adopted in QM coder and MQ coder. Compared to
Q-coder, QM coder, and MQ coder, the representative LPS probability values need
not to be stored in CABAC. Instead, the approximation of the products of coding
interval Range and the LPS probability of (1.37) are stored. In order to be more
adaptive to the coding context, the values of MPS and LPS can be exchanged when
the probabilities of MPS and LPS are equal and the coding bin is LPS.
For particular regular bins of CABAC, multiple context models are allocated for
single bin to more precisely represent probabilities of bin in different coding con-
texts. Four types of context model selection techniques are supported in CABAC,
based on (a) neighboring coded SE values of the current SE, (b) values of prior
coded bins of SE bin string, (c) position of the to-be-encoded residual coefcient
in the scanning path of residual block coefcients, and (d) level values of encoded
coefcients of residual block.
2.3.3 Binary Arithmetic Coding (BAC)
BAC performs arithmetic coding of each bin based on bin value, type, and the corre-
sponding context model of the bin. BAC is a recursive procedure of coding interval
subdivision and selection, as shown in Fig. 2.5.
2.3 CABAC of H.264/AVC 37
MPS
MPS
LPS
MPS
Range
Low
Range
Low
CABAC Bin Encoding Flow
Fig. 2.5 Coding interval subdivision and selection procedure of CABAC
Coding interval subdivision mechanism of CABAC is different from that of
QM and MQ coders. In QM and MQ coders, calculation of Range
LPS
of (1.38) is
simplied by using the approximated value 1 for Range, and multiplication is elim-
inated. In comparison, Range is also utilized for Range
LPS
calculation of CABAC.
Figure 2.6 shows the reference pseudo C-program of interval subdivision and selec-
tion of regular bin, in which the 2 higher-order bits of Range (bit 7 and bit 6) and
the index of probability state (pStateIdx) of LPS are used to look up for the pre-
calculated product of Range and p
LPS
of (1.37) in a 2-D LUT. Although the product
of LUT is of limited precision, the precision of Range
LPS
calculation, interval subdi-
vision is improved, and computational complexity is reduced in CABAC, compared
to those of QM and MQ coders.
RangeIdx = (Range >> 6) & 3; //Range[7:6]
Range
LPS
= rangeTableLPS[pStateIdx][RangeIdx];
Range
MPS
= Range Range
LPS
;
if(bin == MPS) //bin is MPS
Range = Range
MPS
;
else { //bin is LPS
Range = Range
LPS
;
Low = Low + Range
MPS
;
}
Fig. 2.6 Coding interval subdivision and selection of regular bin of CABAC
Because Range and Low of coding interval are represented by nite number of
bits (9 bits for Range and 10 bits for Low), it is necessary to renormalize (scale
up) the interval to prevent precision degradation, and the upper bits of Low are
output as coded bits during renormalization. Coding interval renormalization and
bit output of CABAC is based on Wittens algorithm [Witten87], as illustrated in the
reference pseudo C-program of Fig. 2.7. The coding interval of (Low, Low + Range)
is renormalized when Range is smaller than the threshold value 256 (0x100), which
is
1
/
4
of the maximum range of coding interval.
As illustrated in Fig. 2.7, renormalization of Range and Low is an iterative pro-
cedure, and the maximum number of iterations is 6, as the smallest possible value
of Range is 6. For the processing of carry propagation and output of coding bits,
the coded bits of CABAC are not output until it is conrmed that further carry
38 2 Review of CAVLC, Arithmetic Coding, and CABAC
while (Range < 0x100) {
if (Low >= 0x100) {
if (Low >= 0x200) {
//Output bit 0 and following outstanding bits of 1
PutBit(1);
Low = Low 0x200;
}
else { // Low is between 0x100 and 0x200
Low = Low 0x100;
NumOutstandingBits ++; //Accumulate outstanding bits
}
}
else {
//Output bit 0 and following outstanding bits of 1
PutBit(0);
}
//scale up Range and Low values by left shift
Range = Range << 1;
Low = Low << 1;
}
Fig. 2.7 Pseudo C-program of renormalization and bit output of CABAC
propagation will not inuence bit values. Figure 2.7 illustrates that only when inter-
val length (Range) is smaller than the threshold 0x100, one bit can be output if the
interval is located within the top half [0x200, 0x400) or bottom half [0, 0x200) of
the maximum coding range, or an outstanding (OS) bit is accumulated when the
interval is within [0x100, 0x300). When a bit of value X is output in BAC, the accu-
mulated OS bits are output with the value 1X. Compared to the bit stufng or byte
stufng schemes of Q-coder, QM coder, and MQ coder, carry propagation is com-
pletely solved during renormalization of BAC, and no additional processing of bit
stream is needed at CABAC decoder. Moreover, as no bits or bytes are stuffed in
the bit stream, the compression efciency of CABAC is further improved. However,
the renormalization illustrated in Fig. 2.8 is a highly sequential operation, and as the
number of iterations is variable depending on the selected subinterval Range, it is
1
3/4
1/2
1/4
0
Output
Bit 1
Output
Bit 0
Accumulate
Outstanding
Bit
Bit output when
Range < 1/4 of max interval range
(0x0)
(0x200)
(0x300)
(0x400)
Ratio(Value)
(0x100)
Fig. 2.8 Decision of bit
output and accumulation of
outstanding (OS)bit
2.3 CABAC of H.264/AVC 39
challenging for SW or HW acceleration of renormalization and bit output of BAC.
In some situations, long delay may be experienced, when a large number of OS bits
are accumulated.
2.3.4 Comparisons of CABAC with Other Entropy Coders
The coding efciency of CABAC is higher than those of the Q-coder, QM coder, and
MQ coder, because of (a) the more precise multiplication of Range
LPS
, (b) larger
number of probability states for each probability model, and more precise proba-
bility estimation of coding bins; and (c) more context models (probability models)
deployed for various coding contexts of different types of SEs.
Because of the high computational complexity of CABAC, another entropy
coding tool CAVLC [Bjntegaard02] is deployed in the Baseline prole and
Extended prole of H.264/AVC targeting low bit-rate real-time video coding. It
offers compression-complexity tradeoff with lower complexity, and lower coding
efciency, compared to CABAC [Marpe03a]. It is employed to encode the quantized
transform coefcients of 44 residual blocks, while zero-order Exp-Golomb codes
[Teuhola78] (EG0) are used for all other types of non-residual SEs. Adaptivity is
introduced to CAVLC by allowing switching among multiple VLC tables based on
the already processed SEs, and the coding efciency of CAVLC is better than those
of the previous VLCcoders which used single VLCtable. Instead of coding data pair
of run-level as a single SE, run and level of the residual block are encoded separately
in CAVLC, so that the inter-symbol redundancy can be more efciently exploited.
However, compression efciency of CABAC is signicantly higher, with typically
bit rate reduction of 914% in the video quality range of 3038 dB [Marpe03a],
compared to CAVLC and EG0. This is because (a) in CABAC, encoding symbols
can be more precisely represented in non-integer number of bits, especially for the
symbol with probability higher than 0.5, and (b) CABAC encoder is more adaptive
to the non-stationary symbol statistics with efcient context modeling (probability
estimation) for the coding bins of all types of SEs.
Since the adoption of CABAC entropy coding in H.264/AVC [Marpe97, Marpe,
Heising01, Marpe03a, Mrak03], CABAC is also applied in many applications of
image and video processing including motion mode and residual data of 3Ddynamic
mesh [Muller05], prediction residual in lossless 4D medical image compression
[Sanchez08], SEs of 88 transform coefcients of AVS coding standard [Zhang07],
motion vector coding of scalable video coder [Wu07], parameters of depth and cor-
rection vectors in multi-view video coding [Sehoon07]. CABAC is also utilized
to encode afne motion vector [Kordasiewicz07], and MVD of 3-D DWT-based
subband video encoder [Golwelkar07].
http://www.springer.com/978-3-642-14702-9