【问题标题】:getting sps and pps from CMSampleBufferRef从 CMSampleBufferRef 获取 sps 和 pps
【发布时间】:2015-06-22 01:21:44
【问题描述】:

我使用新 API 将图像从相机推送到 videoToolBox 编码器 并从编码器回调中获取编码的 CMSampleBufferRef

我需要这些用于 CMVideoFormatDescriptionCreateFromH264ParameterSets 的 sps 和 pts 配置解码器

有人可以帮助/指导我吗? )谢谢

【问题讨论】:

    标签: video-streaming video-processing video-encoding ios8


    【解决方案1】:

    反过来也很容易,相关函数是CMVideoFormatDescriptionGetH264ParameterSetAtIndex,可以使用类似

    CMFormatDescriptionRef format = CMSampleBufferGetFormatDescription(sampleBuffer);
    size_t spsSize, ppsSize;
    size_t parmCount;
    const uint8_t* sps, *pps;
    
    CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 0, &sps, &spsSize, &parmCount, nullptr );
    CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 1, &pps, &ppsSize, &parmCount, nullptr );
    

    【讨论】:

      【解决方案2】:

      提取 'SampleDescriptionExtensionAtoms' 字典的 'avcC' 元素,然后使用 'CFDataGetLength' 和 'CFDataGetBytePtr' 获取指向 avcC 结构的直接指针,然后可以通过以下方式解析该结构:

      #pragma pack(push, 1)
      struct AVCC {
          uint8_t  version;
          uint8_t  profile_idc;
          uint8_t  compatibility;
          uint8_t  level_idc;
          uint8_t  nalu_size  : 2;// indicates the length in bytes of the NALUnitLength field in an AVC video sample or AVC parameter set sample of the associated stream **minus one**
          uint8_t  reserved1  : 6;
          uint8_t  numSPS     : 5;// length size minus one
          uint8_t  reserved2  : 3;
          uint16_t SPSlen; 
          uint8_t  pSPS[15];      // Sequence parameter set
          uint8_t  numPPS;
          uint16_t PPSlen;
          uint32_t pPPS[1];       // Picture parameter set
      };
      #pragma pack(pop)
      
      int _tmain(int argc, _TCHAR* argv[])
      {
          AVCC* pAVCC = (AVCC*)g_pAVCC;
      
          pAVCC->SPSlen = ((pAVCC->SPSlen & 0x00FF) << 8) | ((pAVCC->SPSlen & 0xFF00) >> 8);
          pAVCC->PPSlen = ((pAVCC->PPSlen & 0x00FF) << 8) | ((pAVCC->PPSlen & 0xFF00) >> 8);
      
      
          uint8_t* pSPS = (uint8_t*)pAVCC->pSPS;
          uint8_t* pPPS = (uint8_t*)pAVCC->pPPS;
      
          ...
      
          return 0;
      }
      

      【讨论】:

        猜你喜欢
        • 2014-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-08
        • 1970-01-01
        • 2012-03-25
        • 1970-01-01
        • 2016-01-12
        相关资源
        最近更新 更多