FFmpeg 获取H264流中的sps pps

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) lengthSizeMinusOne;
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(8
pictureParameterSetLength) 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)。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值