H264 NALU分析(sps,pps,关键帧,非关键帧)

SPS部分
1. NALU起始符为00 00 00 01。
2. 紧跟着起始符的是是Start code,如 00 00 00 01 0x67(start coe)

0x67的二进制是0110 0111, 以0x67为例分析如下(u: 0110 0111):
1. forbidden_zero_bit 是禁止位,应该是第一位即u(1) = 0,1为语法有错误
2. nal_ref_idc是参考级别,代表被其它帧参考情况,u(2) = 11 = 3(Nal_ref_idc表示NAL的优先级,0-3, 取值越大,表示当前NAL越重要,如果当前NAL是属于参考帧的片,或是序列参数集,或是图像参数集这些重要单位时,取值必须>0)
3. nal_unit_type是该帧的类型,为剩下的5位,u(5) = 0 0111 = 7
目前类型有:
H264定义的类型 values for nal_unit_type
typedef enum {
NALU_TYPE_SLICE = 1,
NALU_TYPE_DPA = 2,
NALU_TYPE_DPB = 3,
NALU_TYPE_DPC = 4,
NALU_TYPE_IDR = 5,
NALU_TYPE_SEI = 6,
NALU_TYPE_SPS = 7,
NALU_TYPE_PPS = 8,
NALU_TYPE_AUD = 9,
NALU_TYPE_EOSEQ = 10,
NALU_TYPE_EOSTREAM = 11,
NALU_TYPE_FILL = 12,
(#)if (MVC_EXTENSION_ENABLE)
NALU_TYPE_PREFIX = 14,
NALU_TYPE_SUB_SPS = 15,
NALU_TYPE_SLC_EXT = 20,
NALU_TYPE_VDRD = 24 // View and Dependency Representation Delimiter NAL Unit
(#)endif
} NaluType;
可以看出7是NALU_TYPE_SPS 即sequence parameter sets

3.start code后面紧跟着的是profile_idc, 如00 00 00 01 0x67
0x64(profile_idc)

0x64转化为十进制则是100,
H264定义如下:
66 Baseline
77 Main
88 Extended
100 High (FRExt)
110 High 10 (FRExt)
122 High 4:2:2 (FRExt)
144 High 4:4:4 (FRExt)
所以0x64是100 表示high_profile, High (FRExt)

参考:
00 00 00 01 67 42 00 28 E9 00
A0 0B 77 FE 00 02 00 03 C4 80
00 00 03 00 80 00 00 1A 4D 88
10 94 00 00 00 01
00 00 00 01为NALu头,‍其余码流由十六进制转为二进制
67 0110 0111
42 0100 0010
00 0000 0000
28 0010 1000
E9 1110 1001
00 0000 0000
A0 1010 0000
0B 0000 1011
77 0111 01/11
……
94 1001 01//00
说明:
“/”后的码流要对照标准中AnnexE的句法表,是VUI(VideoUsabilityInformation?)的内容,
不懂,不写了,只写SPS部分先。
“//”后面两个0是补齐用的。
NAL层句法:码,值
forbidden_zero_bit(f(1)):0,0
nal_ref_idc(u(2)):11, 3
nal_unit_type(u(5)): 0 0111, 7, SPS
SPS序列参数集的句法:码,值
profile_idc(u(8)) = 0100 0010,66 , baseline profile基础档次
constraint_set0_flag(u(1)):0,0
constraint_set1_flag(u(1)):0,0
constraint_set2_flag(u(1)):0,0
constraint_set3_flag(u(1)):0,0
reserved_zero_4bits(u(4)):0000,0
level_idc(u(8)) :00101000,40 ,级别
seq_parameter_set_id(ue(v)): 1, 0
log2_max_frame_num_minus4(ue(v): 1, 0
MaxFrameNum = 2^(0+4) = 16
pic_order_cnt_type(ue(v)):1, 0
log2_max_pic_order_cnt_lsb_minus4(ue(v)):010 ,1
MaxPicOrderCntLsb = 2^(1+4) = 32
num_ref_frames(ue(v)):010, 1
gaps_in_frame_num_value_allowed_flag(u(1)):0,0
pic_width_in_mbs_minus1(ue(v)): 0000001010000, 2^6-1+16 = 79
PicWidthInMbs = pic_width_in_mbs_minus1 + 1 = 80
pic_height_in_map_units_minus1(ue(v)): 00000101101 ,2^5-1+13 = 44
PicHeightInMapUnits = pic_height_in_map_units_minus1 + 1 =45
frame_mbs_only_flag(u(1)):1,1
direct_8x8_inference_flag(u(1)): 1,1
frame_cropping_flag(u(1)):0,0
vui_parameters_present_flag(u(1)):1 ,1
这个参数为1,说明下面的句法存在
vui_parameters( )
aspect_ratio_info_present_flag(u(1)):1

其中:
pic_width_in_mbs_minus1 : 79
pic_height_in_map_units_minus1 : 44
(79+1)x16=1280
(44+1)x16=720

你可能感兴趣的:(FFmpeg,音视频编解码)