H.264的SPS和PPS串,包含了初始化H.264解码器所需要的信息参数,包括编码所用的profile,level,图像的宽和高,deblock滤波器等。
(1)avcC的数据结构:
aligned(8) class AVCDecoderConfigurationRecord {
unsigned int(8) configurationVersion = 1;
unsigned int(8) AVCProfileIndication;
unsigned int(8) profile_compatibility;
unsigned int(8) AVCLevelIndication;
bit(6) reserved = '111111’b;
unsigned int(2) lengthSi*usOne;
bit(3) reserved = '111’b;
unsigned int(5) numOfSequenceParameterSets;
for (i=0; i< numOfSequenceParameterSetsispan>
unsigned int(16) sequenceParameterSetLength ;
bit(8sequenceParameterSetLength) sequenceParameterSetNALUnit;
}
unsigned int(8) numOfPictureParameterSets;
for (i=0; i< numOfPictureParameterSetsispan>
unsigned int(16) pictureParameterSetLength;
bit(8pictureParameterSetLength) pictureParameterSetNALUnit;
}
}
avcC的数据结构对应sps和pps流。
(2) FFmpeg 如何获取sps和pps
ffmpeg获取sps和pps非常简单。avcC数据结构对应于AVFormatContext->streams[H264Index]->codec->extradata。
代码如下:
if ((ret = avformat_open_input(&ic, InputFileName, NULL, NULL)) < 0)
{
xprintf->Trace(0,"******** Decode avformat_open_input() Function result=%d",ret);
return ret;
}
if ((ret = avformat_find_stream_info(ic, NULL)) < 0)
{
xprintf->Trace(0,"******** Decode avformat_find_stream_info() Function result=%d ",ret);
avformat_close_input(&ic);
return ret;
}
for (int i=0;i<ic->streams[0]->codec->extradata_size;i++)
{
printf("%x ",ic->streams[0]->codec->extradata[i]);
}
对应上面的avcC结构体我们知道:
第7,8位, 为sps长度(0,18)即为24。
接下来的24位为sps数据,(67,64,0,20,ac,b2,0,a0,b,76,2,20,0,0,3,0,20,0,0,c,81,e3,6,49)。
numOfPictureParameterSets, 为1。
接下来2位为pps长度:(0,6) 即为6。
接下来6位为pps数据,(68,eb,c3,cb,22,c0)。