x264获取sps pps 等信息

通常是通过 x264_nal_t::i_type 判断当前的NAL的类型;


其定义的枚举类型:

enum nal_unit_type_e
{
    NAL_UNKNOWN     = 0,
    NAL_SLICE       = 1,
    NAL_SLICE_DPA   = 2,
    NAL_SLICE_DPB   = 3,
    NAL_SLICE_DPC   = 4,
    NAL_SLICE_IDR   = 5,    /* ref_idc != 0 */
    NAL_SEI         = 6,    /* ref_idc == 0 */
    NAL_SPS         = 7,
    NAL_PPS         = 8,
    NAL_AUD         = 9,
    NAL_FILLER      = 12,
    /* ref_idc == 0 for 6,9,10,11,12 */
};


通常,在关键帧前面的就是sps和pps等信息,但是如果要立刻获取相关信息或持续一开始就要先获取,可以通过 x264_encoder_headers 函数获取;

函数注释:

/* x264_encoder_headers:
 *      return the SPS and PPS that will be used for the whole stream.
 *      *pi_nal is the number of NAL units outputted in pp_nal.
 *      returns the number of bytes in the returned NALs.
 *      returns negative on error.
 *      the payloads of all output NALs are guaranteed to be sequential in memory. */
int     x264_encoder_headers( x264_t *, x264_nal_t **pp_nal, int *pi_nal );


应用示例:

 //* 获取整个流的PPS和SPS,不需要可以不调用.
 iResult = x264_encoder_headers(pX264Handle, &pNals, &iNal);
 assert(iResult >= 0);

//一个Nal保存一个相关信息,所以有多个信息,就会有多个Nal;

 for (int i = 0; i < iNal; ++i)
 {
  switch (pNals[i].i_type)  //也可以判断上述枚举中的其它相关信息;
  {
  case NAL_SPS:
   break;
  case  NAL_PPS:
   break;
  default:
   break;
  }
 }


这里可以注意,在x264中,一般sps和pps的分隔符是4个字节:00 00 00 01, 普通的分隔符是3个字节:00 00 01;








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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chinabinlang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值