получение sps и pps из CMSampleBufferRef

я отправляю изображение с камеры в кодировщик videoToolBox с новым API и получаю закодированный CMSampleBufferRef из обратного вызова кодировщика

мне нужны эти sps и pts для CMVideoFormatDescriptionCreateFromH264ParameterSets для настройки декодера

может ли кто-нибудь помочь/направить меня? ) СПАСИБО


person Igor Popov    schedule 20.06.2014    source источник


Ответы (2)


Это довольно легко сделать наоборот, соответствующая функция 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 );
person jgh    schedule 25.07.2014

Извлеките элемент «avcC» из словаря «SampleDescriptionExtensionAtoms», затем используйте «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;
}
person NadavRub    schedule 21.06.2015