我用新的接口将摄像头的图像推送到videoToolBox编码器,并从编码器回调中获取编码的CMSampleBufferRef
我需要这些sps和pts的CMVideoFormatDescriptionCreateFromH264ParameterSets配置解码器
有人可以帮助/指导我吗?)THX
发布于 2014-07-26 06:26:02
反过来做也很容易,相关的函数是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 );发布于 2015-06-22 01:21:44
提取'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;
}https://stackoverflow.com/questions/24318092
复制相似问题