[FFmpeg-devel] Understanding the CABAC decoder implementation (at least a bit)

Philipp B philippb at gmail.com
Wed Jun 11 09:39:12 CEST 2014


Hi,

I am doing some research about the h.264 format, and I am
especially interested in the size of each macroblock in bits.

My idea is hacking some printf statement around the call to
ff_h264_decode_mb_cabac in h264_slice.c and decoding files
for analysis then.
By looking at h->cabac.bytestream_start, I get a rough estimation
of the used space, with 2 byte accuracy. However, I can't figure a
way to get the exact read position in terms of bits from the
CABACContext. In fact I have a pretty hard time understanding the
implementation.

This is my current printf code:

>  int start_pos = h->cabac.bytestream-h->cabac.bytestream_start;
>  int ret = ff_h264_decode_mb_cabac(h);
>  printf(" MB size : %d \n", h->cabac.bytestream -
h->cabac.bytestream_start-start_pos );

I understand the core idea of arithmetic coding allows even fractional
bit sizes for coded symbols, but I guess theres a way to estimate the
number of Symbols remaining in the CABACContext, presumably by
interpreting the 'low' and 'range' fields.

So, how do I extend the code above to show the space used in bits?

Also I would appreciate any link which helps to understand
the CABAC implementation.

Thanks,
Philipp


More information about the ffmpeg-devel mailing list