内容取自Recommendation ITU-T H.264。
SPS 语法(seq_parameter_set_data)
7.3.2.1.1 Sequence parameter set data syntax
seq_parameter_set_data( ) { | C | Descriptor |
---|---|---|
profile_idc | 0 | u(8) |
constraint_set0_flag | 0 | u(1) |
constraint_set1_flag | 0 | u(1) |
constraint_set2_flag | 0 | u(1) |
constraint_set3_flag | 0 | u(1) |
constraint_set4_flag | 0 | u(1) |
constraint_set5_flag | 0 | u(1) |
reserved_zero_2bits /* equal to 0 */ | 0 | u(2) |
level_idc | 0 | u(8) |
seq_parameter_set_id | 0 | ue(v) |
if( profile_idc = = 100 | | profile_idc = = 110 | | profile_idc = = 122 | | profile_idc = = 244 | | profile_idc = = 44 | | profile_idc = = 83 | | profile_idc = = 86 | | profile_idc = = 118 | | profile_idc = = 128 | | profile_idc = = 138 | | profile_idc = = 139 | | profile_idc = = 134 | | profile_idc = = 135 ) { | ||
chroma_format_idc | 0 | ue(v) |
if( chroma_format_idc = = 3 ) | ||
separate_colour_plane_flag | 0 | u(1) |
bit_depth_luma_minus8 | 0 | ue(v) |
bit_depth_chroma_minus8 | 0 | ue(v) |
qpprime_y_zero_transform_bypass_flag | 0 | u(1) |
seq_scaling_matrix_present_flag | 0 | u(1) |
if( seq_scaling_matrix_present_flag ) | ||
for( i = 0; i < ( ( chroma_format_idc != 3 ) ? 8 : 12 ); i++ ) { | ||
seq_scaling_list_present_flag[ I ] | 0 | u(1) |
if( seq_scaling_list_present_flag[ i ] ) | ||
if( i < 6 ) | ||
scaling_list( ScalingList4x4[ i ], 16, UseDefaultScalingMatrix4x4Flag[ i ] ) | 0 | |
else | ||
scaling_list( ScalingList8x8[ i − 6 ], 64, UseDefaultScalingMatrix8x8Flag[ i − 6 ] ) | 0 | |
} | ||
} | ||
log2_max_frame_num_minus4 | 0 | ue(v) |
pic_order_cnt_type | 0 | ue(v) |
if( pic_order_cnt_type = = 0 ) | ||
log2_max_pic_order_cnt_lsb_minus4 | 0 | ue(v) |
else if( pic_order_cnt_type = = 1 ) { | ||
delta_pic_order_always_zero_flag | 0 | u(1) |
offset_for_non_ref_pic | 0 | se(v) |
offset_for_top_to_bottom_field | 0 | se(v) |
num_ref_frames_in_pic_order_cnt_cycle | 0 | ue(v) |
for( i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++ ) | ||
offset_for_ref_frame[ I ] | 0 | se(v) |
} | ||
max_num_ref_frames | 0 | ue(v) |
gaps_in_frame_num_value_allowed_flag | 0 | u(1) |
pic_width_in_mbs_minus1 | 0 | ue(v) |
pic_height_in_map_units_minus1 | 0 | ue(v) |
frame_mbs_only_flag | 0 | u(1) |
if( !frame_mbs_only_flag ) | ||
mb_adaptive_frame_field_flag | 0 | u(1) |
direct_8x8_inference_flag | 0 | u(1) |
frame_cropping_flag | 0 | u(1) |
if( frame_cropping_flag ) { | ||
frame_crop_left_offset | 0 | ue(v) |
frame_crop_right_offset | 0 | ue(v) |
frame_crop_top_offset | 0 | ue(v) |
frame_crop_bottom_offset | 0 | ue(v) |
} | ||
vui_parameters_present_flag | 0 | u(1) |
if( vui_parameters_present_flag ) | ||
vui_parameters( ) | 0 | |
} |
分辨率
chroma_format_idc | separate_colour_plane_flag | Chroma Format | SubWidthC | SubHeightC |
---|---|---|---|---|
0 | 0 | monochrome | - | - |
1 | 0 | 4:2:0 | 2 | 2 |
2 | 0 | 4:2:2 | 2 | 1 |
3 | 0 | 4:4:4 | 1 | 1 |
3 | 1 | 4:4:4 | - | - |
宽度
The variable for the picture width in units of macroblocks is derived as
PicWidthInMbs = pic_width_in_mbs_minus1 + 1 (7-13)
The variable for picture width for the luma component is derived as
PicWidthInSamplesL = PicWidthInMbs * 16 (7-14)
The variable for picture width for the chroma components is derived as
PicWidthInSamplesC = PicWidthInMbs * MbWidthC
PicWidthInMbs
:表示水平宏块数。
SubWidthC
,SubHeightC
:根据以上表格,每个色度格式有对应的值。
PicWidthInMbs = pic_width_in_mbs_minus1 + 1
- 当
chroma_format_idc
的值是0
时,表示这张图片没有色度格式,仅有亮度(luma),是一张灰度图。
PicWidthInSamplesL(分辨率宽度) =PicWidthInMbs * 16
- 当chroma_format_idc为
1~3
时,这张图有对应的色度格式。
MbWidthC =16 / SubWidthC
PicWidthInSamplesC(分辨率宽度) =PicWidthInMbs \* MbWidthC
高度
The variables PicHeightInMapUnits and PicSizeInMapUnits are derived as
PicHeightInMapUnits = pic_height_in_map_units_minus1 + 1 (7-16)
The variable FrameHeightInMbs is derived as
FrameHeightInMbs = ( 2 − frame_mbs_only_flag ) * PicHeightInMapUnits (7-18)
The variable for the picture height in units of macroblocks is derived as
PicHeightInMbs = FrameHeightInMbs / ( 1 + field_pic_flag ) (7-26)
The variable for picture height for the luma component is derived as
PicHeightInSamplesL = PicHeightInMbs * 16 (7-27)
The variable for picture height for the chroma component is derived as
PicHeightInSamplesC = PicHeightInMbs * MbHeightC (7-28)
The variable for the picture height in units of macroblocks is derived as
PicHeightInMbs = FrameHeightInMbs / ( 1 + field_pic_flag ) (7-26)
The variable for picture height for the luma component is derived as
PicHeightInSamplesL = PicHeightInMbs * 16 (7-27)
The variable for picture height for the chroma component is derived as
PicHeightInSamplesC = PicHeightInMbs * MbHeightC (7-28)
PicHeightInMapUnits
:表示垂直单位数量。
frame_mbs_only_flag
:0为帧编码(逐行扫描,p),1为场编码(隔行扫描,i)。
FrameHeightInMbs
:分辨率
field_pic_flag
:这个再研究,目前个人使用场景为0。
PicHeightInMapUnits = pic_height_in_map_units_minus1 + 1
FrameHeightInMbs = ( 2 − frame_mbs_only_flag ) * PicHeightInMapUnits
MbHeightC = 16 / SubHeightC
PicHeightInMbs = FrameHeightInMbs / ( 1 + field_pic_flag )
- 当
chroma_format_idc
的值是0
时,是一张灰度图。
PicHeightInSamplesL(分辨率高度) =PicHeightInMbs * 16
- 当chroma_format_idc为
1~3
时,这张图有对应的色度格式。
MbWidthC =16 / SubWidthC
PicHeightInSamplesC(分辨率高度) =PicHeightInMbs \* MbHeightC
对图片进行裁剪,获取正确分辨率
– If ChromaArrayType is equal to 0, CropUnitX and CropUnitY are derived as:
CropUnitX = 1 (7-19)
CropUnitY = 2 − frame_mbs_only_flag (7-20)
– Otherwise (ChromaArrayType is equal to 1, 2, or 3), CropUnitX and CropUnitY are derived as:
CropUnitX = SubWidthC (7-21)
CropUnitY = SubHeightC * ( 2 − frame_mbs_only_flag ) (7-22)
Let CroppedWidth and CroppedHeight be the width and height, respectively, of the cropped frame area output from the
decoder in units of luma samples, derived as follows:
CroppedWidth = PicWidthInSamplesL − CropUnitX * ( frame_crop_left_offset + frame_crop_right_offset )
(D-30)
CroppedHeight = PicHeightInSamplesL − CropUnitY * ( frame_crop_top_offset + frame_crop_bottom_offset )
(D-31)
frame_cropping_flag
:当这个值为1的时候才需要对图片进行裁剪。
- 当
chroma_format_idc
的值是0
时,是一张灰度图。
CropUnitX =1
CropUnitY =2 − frame_mbs_only_flag
- 当chroma_format_idc为
1~3
时,这张图有对应的色度格式。
CropUnitX =SubWidthC
CropUnitY =SubHeightC * ( 2 − frame_mbs_only_flag )
裁剪后正确尺寸:
CroppedWidth = PicWidthInSamplesL − CropUnitX * ( frame_crop_left_offset + frame_crop_right_offset )
CroppedHeight = PicHeightInSamplesL − CropUnitY * ( frame_crop_top_offset + frame_crop_bottom_offset )
vui 结构(vui_parameters)
Extended_SAR = 255
vui_parameters( ) { | C | Descriptor |
---|---|---|
aspect_ratio_info_present_flag | 0 | u(1) |
if( aspect_ratio_info_present_flag ) { | ||
aspect_ratio_idc | 0 | u(8) |
if( aspect_ratio_idc = = Extended_SAR ) { | ||
sar_width | 0 | u(16) |
sar_height | 0 | u(16) |
} | ||
} | ||
overscan_info_present_flag | 0 | u(1) |
if( overscan_info_present_flag ) | ||
overscan_appropriate_flag | 0 | u(1) |
video_signal_type_present_flag | 0 | u(1) |
if( video_signal_type_present_flag ) { | ||
video_format | 0 | u(3) |
video_full_range_flag | 0 | u(1) |
colour_description_present_flag | 0 | u(1) |
if( colour_description_present_flag ) { | ||
colour_primaries | 0 | u(8) |
transfer_characteristics | 0 | u(8) |
matrix_coefficients | 0 | u(8) |
} | ||
} | ||
chroma_loc_info_present_flag | 0 | u(1) |
if( chroma_loc_info_present_flag ) { | ||
chroma_sample_loc_type_top_field | 0 | ue(v) |
chroma_sample_loc_type_bottom_field | 0 | ue(v) |
} | ||
timing_info_present_flag | 0 | u(1) |
if( timing_info_present_flag ) { | ||
num_units_in_tick | 0 | u(32) |
time_scale | 0 | u(32) |
fixed_frame_rate_flag | 0 | u(1) |
} | ||
nal_hrd_parameters_present_flag | 0 | u(1) |
if( nal_hrd_parameters_present_flag ) | ||
hrd_parameters( ) | 0 | |
vcl_hrd_parameters_present_flag | 0 | u(1) |
if( vcl_hrd_parameters_present_flag ) | ||
hrd_parameters( ) | 0 | |
if( nal_hrd_parameters_present_flag | | vcl_hrd_parameters_present_flag ) | ||
low_delay_hrd_flag | 0 | u(1) |
pic_struct_present_flag | 0 | u(1) |
bitstream_restriction_flag | 0 | u(1) |
if( bitstream_restriction_flag ) { | ||
motion_vectors_over_pic_boundaries_flag | 0 | u(1) |
max_bytes_per_pic_denom | 0 | ue(v) |
max_bits_per_mb_denom | 0 | ue(v) |
log2_max_mv_length_horizontal | 0 | ue(v) |
log2_max_mv_length_vertical | 0 | ue(v) |
max_num_reorder_frames | 0 | ue(v) |
max_dec_frame_buffering | 0 | ue(v) |
} | ||
} |