Reputation: 23
I am using VTCompressionSessionRef to compress CVImageBuffer in H.264 format . The compression session works fine, I am get the compression callbacks with the CMSampleBuffer. When I try to get the NALU parameter set using the following code, it does not work.
const uint8_t *paramenterSetPointerOut = NULL;
size_t parameterSetSizeOut,parameterSizeCountOut;
int nalUnitHeaderLengthOut;
CMFormatDescriptionRef fdesc = CMSampleBufferGetFormatDescription(sampleBuffer);
OSStatus status = CMVideoFormatDescriptionGetH264ParameterSetAtIndex(fdesc, 0, ¶menterSetPointerOut,¶meterSetSizeOut, ¶meterSizeCountOut, &nalUnitHeaderLengthOut);
CMVideoFormatDescriptionGetH264ParameterSetAtIndex API returns -12712 error. Could you please let me know if I am doing something wrong here?
Upvotes: 0
Views: 992
Reputation: 439
Maybe it's too late, but this implementation works great:
CMFormatDescriptionRef description = CMSampleBufferGetFormatDescription(sampleBuffer);
size_t numberOfParameterSets;
CMVideoFormatDescriptionGetH264ParameterSetAtIndex(description,
0, NULL, NULL,
&numberOfParameterSets,
NULL);
// Write each parameter set to the elementary stream
NSLog(@"NUMBER OF PARAMETERS %lu", numberOfParameterSets);
for (int i = 0; i < numberOfParameterSets; i++) {
const uint8_t *parameterSetPointer;
size_t parameterSetLength;
CMVideoFormatDescriptionGetH264ParameterSetAtIndex(description,
i,
¶meterSetPointer,
¶meterSetLength,
NULL, NULL);
// Write the parameter set to the elementary stream
[elementaryStream appendBytes:startCode length:startCodeLength];
[elementaryStream appendBytes:parameterSetPointer length:parameterSetLength];
}
Upvotes: 0
Reputation: 1
The function has a bug, file a Radar. You can just iterate from index 0 until the function returns an error. The pset data and size variables will be fine.
Upvotes: 0