以下限于H264.
-
SDP中计算宽高用到的参数
计算公式
// 计算宽和高 简易公式
Width = (pic_width_in_mbs_minus1 + 1) * 16;
Height = (pic_height_in_map_units_minus1 + 1) * 16;
Width -= (frame_crop_left_offset + frame_crop_right_offset) * 2;
Height -= (frame_crop_top_offset + frame_crop_bottom_offset) * 2;
更详细复杂的可参见: http://ju.outofmemory.cn/entry/208773
- 计算实例
Width = (119 + 1) * 16 - (0 + 0) * 2 = 1920
Height = (67 + 1) * 16 - (0 + 4) * 2 = 1088 - 8 = 1080
- 代码实例
Width = (pic_width_in_mbs_minus1 + 1) * 16;
Height = (pic_height_in_map_units_minus1 + 1) * 16;
int frame_mbs_only_flag;
int frame_cropping_flag, frame_crop_left_offset, frame_crop_right_offset;
int frame_crop_top_offset, frame_crop_bottom_offset;
...
frame_cropping_flag = u(1,buf,StartBit);
if (frame_cropping_flag)
{
frame_crop_left_offset = ...;
frame_crop_right_offset = ...;
frame_crop_top_offset = ...;
frame_crop_bottom_offset = ...;
Width -= (frame_crop_left_offset + frame_crop_right_offset) << 0x1;
Height -= (frame_crop_top_offset + frame_crop_bottom_offset) << 0x1;
}
References:
http://ju.outofmemory.cn/entry/208773
http://www.latelee.org/my-study/get-width-height-framerate-from-bitstream.html