CABAC Encoder: Context Based Adaptive Binary Arithmetic Coding Encoder
CABAC Encoder: Context Based Adaptive Binary Arithmetic Coding Encoder
July 25 2020
1 Introduction
Context-based Adaptive Binary Arithmetic Coding (CABAC) as a normative
part of the new ITU-T — ISO/IEC standard H.264/AVC for video compres-
sion is presented. By combining an adaptive binary arithmetic coding technique
with context modeling, a high degree of adaptation and redundancy reduction is
achieved. The CABAC framework also includes a novel low-complexity method
for binary arithmetic coding and probability estimation that is well suited for
efficient hardware and software implementations. CABAC significantly outper-
forms the baseline entropy coding method of H.264/AVC for the typical area of
envisaged target applications.
1
2. Context Modelling : One of the most important properties of arithmetic
coding is the possibility to utilize a clean interface between modeling and
coding such that in the modeling stage, a model probability distribution
is assigned to the given symbols, which then, in the subsequent coding
stage, drives the actual coding engine to generate a sequence of bits as a
coded representation of the symbols according to the model distribution.
3. Binary Arithmetic Coding : Binary arithmetic coding is based on the
principle of recursive interval subdivision that involves the following ele-
mentary multiplication operation.
2
Figure 2: Integer Implementation Algo
3
3 CABAC Algorithm
Coding a data symbol involves the following stages.
• Binarization: CABAC uses Binary Arithmetic Coding which means that
only binary decisions (1 or 0) are encoded. A non-binary-valued symbol
(e.g. a transform coefficient or motion vector) is ”binarized” or converted
into a binary code prior to arithmetic coding. This process is similar
to the process of converting a data symbol into a variable length code
but the binary code is further encoded (by the arithmetic coder) prior to
transmission.
• Stages are repeated for each bit (or ”bin”) of the binarized symbol.
• Context model selection: A ”context model” is a probability model for one
or more bins of the binarized symbol. This model may be chosen from a
selection of available models depending on the statistics of recently coded
data symbols. The context model stores the probability of each bin being
”1” or ”0”.
• Arithmetic encoding: An arithmetic coder encodes each bin according to
the selected probability model. Note that there are just two sub-ranges
for each bin (corresponding to ”0” and ”1”).
4 Implementation
Two types of Implementation has been performed, One of them basic CABAC
and another is CABAC with prediction by partial matching(PPM). Difference
between them is in the creation and selection of Frequency tables. Before that
flow goes in same direction for both like : Decompressing and Image from
jpg/png, converting to binary image, save them as flatten numpy array and call
respective Encoding function.
4
Figure 3: Context Model for order 2
5
Figure 4: Context Model for order 2
5 Results
Compression Ratio = Uncompressed File size/Compressed file size Space Saved
= (1-1/Compression Ratio)*100
6
Figure 5: CABAC Results
7
Figure 7: Static Table approach
7 Conclusion
The entropy coding method of Context-based Adaptive Binary Arithmetic Cod-
ing (CABAC) is part of the Main profile of H.264/AVC [1] and may find its
way into video streaming, broadcast, or storage applications within this pro-
file. Experimental results have shown the superior performance of CABAC in
comparison to the baseline entropy coding method of VLC/CAVLC.
References
[1] Context Based Adaptive Binary Arithmetic Coding in the H.264/AVC
Video Compression Standard Detlev Marpe, Member, IEEE, Heiko
Schwarz, and Thomas Wiegand
[2] https://en.wikipedia.org/wiki/Context-adaptive binary arithmeticcoding
[3] https://en.wikipedia.org/wiki/Prediction by partial matching
[4] https://github.com/nayuki/Reference-arithmetic-coding
[5] https://www.nayuki.io/page/reference-arithmetic-coding