VideoToolkit API H264 decoding fails with error -12911 in VTDecompressionSessionDecodeFrame

I am trying to decode a .H264 raw video stream but cannot find a way to generate the correct one

    - (void)decodeFrameWithNSData:(NSData*)data presentationTime:

(CMTime)presentationTime
{

    @autoreleasepool {

    CMSampleBufferRef sampleBuffer = NULL;
    CMBlockBufferRef blockBuffer = NULL;
    VTDecodeInfoFlags infoFlags;
    int sourceFrame;

    if( dSessionRef == NULL )
        [self createDecompressionSession];


    CMSampleTimingInfo timingInfo ;
    timingInfo.presentationTimeStamp = presentationTime;
    timingInfo.duration =  CMTimeMake(1,100000000);
    timingInfo.decodeTimeStamp = kCMTimeInvalid;

    //Creates block buffer from NSData
    OSStatus status  = CMBlockBufferCreateWithMemoryBlock(CFAllocatorGetDefault(), (void*)data.bytes,data.length*sizeof(char), CFAllocatorGetDefault(), NULL, 0, data.length*sizeof(char), 0, &blockBuffer);

    //Creates CMSampleBuffer to feed decompression session    
    status = CMSampleBufferCreateReady(CFAllocatorGetDefault(), blockBuffer,self.encoderVideoFormat,1,1,&timingInfo, 0, 0, &sampleBuffer);

    status = VTDecompressionSessionDecodeFrame(dSessionRef,sampleBuffer, kVTDecodeFrame_1xRealTimePlayback, &sourceFrame,&infoFlags);


    if(status != noErr) {
        NSLog(@"Decode with data error %d",status);
    }


    }
}

      

At the end of the call, I get error -12911 in VTDecompressionSessionDecodeFrame which translates to kVTVideoDecoderMalfunctionErr, which after reading this [post] pointed out to me that I should create a VideoFormatDescriptor using CMVideoFormatDescriptionCreateFromH264ParameterSets. But how can I create a new VideoFormatDescription if I don't have information about currentSps or currentPps? How can I get this information from my .H264 stream?

CMFormatDescriptionRef decoderFormatDescription;
const uint8_t* const parameterSetPointers[2] = 
    { (const uint8_t*)[currentSps bytes], (const uint8_t*)[currentPps bytes] };
const size_t parameterSetSizes[2] = 
    { [currentSps length], [currentPps length] };
status = CMVideoFormatDescriptionCreateFromH264ParameterSets(NULL,
       2,
       parameterSetPointers,
       parameterSetSizes,
       4,
       &decoderFormatDescription);

      

Thank you in advance,

Marcos

[post]: Error decoding VideoToolkit H264 API with error -8971 in VTDecompressionSessionCreate

+4


source to share


1 answer


You, you MUST call first CMVideoFormatDescriptionCreateFromH264ParameterSets

. SPS / PPS can be stored / transmitted separately from the video stream. Or it can come in line.

Note that VTDecompressionSessionDecodeFrame

your NALUs must be preceded by a size, not a starting code.



You can read more here: Possible Locations for Sequence / Picture Parameter Sets for H.264 Stream

+4


source







All Articles