首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从CMSampleBufferRef获取sps和pps

从CMSampleBufferRef获取sps和pps
EN

Stack Overflow用户
提问于 2014-06-20 08:03:53
回答 2查看 1.4K关注 0票数 2

我用新的接口将摄像头的图像推送到videoToolBox编码器,并从编码器回调中获取编码的CMSampleBufferRef

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

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

EN

回答 2

Stack Overflow用户

发布于 2014-07-26 06:26:02

反过来做也很容易,相关的函数是CMVideoFormatDescriptionGetH264ParameterSetAtIndex,它的用法如下

代码语言:javascript
复制
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 );
票数 5
EN

Stack Overflow用户

发布于 2015-06-22 01:21:44

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

代码语言:javascript
复制
#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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24318092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档