FFmpeg 获取H264流中的sps pps

原文地址:http://blog.csdn.net/ren65432/article/details/43448781

FFmpeg 获取H264流中的sps pps

原创 2015年02月03日 13:45:15

H.264的SPS和PPS串,包含了初始化H.264解码器所需要的信息参数,包括编码所用的profile,level,图像的宽和高,deblock滤波器等。

(1)avcC的数据结构:

  1. aligned(8) class AVCDecoderConfigurationRecord {     
  2.  unsigned int(8) configurationVersion = 1;     
  3.  unsigned int(8) AVCProfileIndication;     
  4.  unsigned int(8) profile_compatibility;     
  5.  unsigned int(8) AVCLevelIndication;     
  6.  bit(6) reserved = '111111'b;     
  7.  unsigned int(2) lengthSizeMinusOne;     
  8.  bit(3) reserved = '111'b;     
  9.  unsigned int(5) numOfSequenceParameterSets;     
  10. for (i=0; i< numOfSequenceParameterSetsispan>    
  11.  unsigned int(16) sequenceParameterSetLength ;     
  12.  bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit;     
  13.  }     
  14.  unsigned int(8) numOfPictureParameterSets;     
  15. for (i=0; i< numOfPictureParameterSetsispan>    
  16.  unsigned int(16) pictureParameterSetLength;     
  17.  bit(8*pictureParameterSetLength) pictureParameterSetNALUnit;     
  18.  }     
  19. }     

avcC的数据结构对应sps和pps流。


(2) FFmpeg 如何获取sps和pps

ffmpeg获取sps和pps非常简单。avcC数据结构对应于AVFormatContext->streams[H264Index]->codec->extradata。

代码如下:

  1. if ((ret = avformat_open_input(&ic, InputFileName, NULL, NULL)) < 0)  
  2.     {  
  3.         xprintf->Trace(0,"******** Decode avformat_open_input() Function result=%d",ret);  
  4.         return ret;  
  5.     }  
  6.   
  7.     if ((ret = avformat_find_stream_info(ic, NULL)) < 0)   
  8.     {    
  9.         xprintf->Trace(0,"******** Decode avformat_find_stream_info() Function result=%d ",ret);  
  10.         avformat_close_input(&ic);    
  11.         return ret;    
  12.     }    
  13.   
  14.     for (int i=0;i<ic->streams[0]->codec->extradata_size;i++)  
  15.     {  
  16.         printf("%x ",ic->streams[0]->codec->extradata[i]);  
  17.     }  


对应上面的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)。

  1. numOfPictureParameterSets, 为1。  
接下来2位为pps长度:(0,6) 即为6。

接下来6位为pps数据,(68,eb,c3,cb,22,c0)。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值