Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

h264 u(v) decode of frame_num, pic_order_cnt_lsb and slice_group_change_cycle

According to "Slice Header Syntax" (described in ITU-T Rec. h264), frame_num, pic_order_cnt_lsb and slice_group_change_cycle have u(v) descriptor, which is the unsigned integer using variable number of bits.

The doc states that

"the number of bits varies in a manner dependent on the value of other syntax elements."

Do you know how to figure out the number of bits used to store frame_num, pic_order_cnt_lsb and slice_group_change_cycle?

[The cited documentation points to read_bits(n) function, unfortunately I cannot figure it out by myself. Can you help?]

like image 338
dl_ Avatar asked May 30 '14 20:05

dl_


1 Answers

Other bitstream values define the number of bits to read.

frame_num

is used as an identifier for pictures and shall be represented by log2_max_frame_num_minus4 + 4 bits in the bitstream.

Here is what FFmpeg does, for example:

log2_max_frame_num_minus4 = get_ue_golomb(&h->gb);
// ...
sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4;
// ...
h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num);

pic_order_cnt_lsb

specifies the picture order count modulo MaxPicOrderCntLsb for the top field of a coded frame or for a coded field. The size of the pic_order_cnt_lsb syntax element is log2_max_pic_order_cnt_lsb_minus4 + 4 bits.

The value of the pic_order_cnt_lsb shall be in the range of 0 to MaxPicOrderCntLsb – 1, inclusive.

slice_group_change_cycle

The value of slice_group_change_cycle is represented in the bitstream by the following number of bits Ceil( Log2( PicSizeInMapUnits ÷ SliceGroupChangeRate + 1 ) )

Example of bit reading: SliceHeader.cpp, line 170

like image 118
Roman R. Avatar answered Oct 11 '22 13:10

Roman R.