VTDecompressionSessionCreate fails with code -12911 on M1 iPad

In the context of an app that uses a VTDecompressionSession to decode incoming ts streams, the creation of the decompression session always fails for some h264 streams with code -12911 when running on a M1 iPad (iPad Pro, 12.9-inch, 5th generation, iOS 15.5).

When the same app is executed on my M1 Mac mini -as My Mac (Designed for iPad)- with the same stream, VTDecompressionSessionCreatesucceeds and the stream can be decoded.

Any idea of what could cause this error on the iPad?

The code:

decompressionSessionCreationStatus = VTDecompressionSessionCreate(allocator: kCFAllocatorDefault,
                                                                  formatDescription: videoFormatDescription!,
                                                                  decoderSpecification: nil,
                                                                  imageBufferAttributes: nil,
                                                                  outputCallback: nil,
                                                                  decompressionSessionOut: &videoDecompressionSession)

if videoDecompressionSession != nil { ... }
else {
    NSLog("videoDecompressionSession could not be created (status: %d): video format: %@", 
          decompressionSessionCreationStatus, (videoFormatDescription != nil) ? (CFCopyDescription(videoFormatDescription!) as String) : "{?}")
}

where videoFormatDescription was previously created by extracting h264 parameter sets and calling CMVideoFormatDescriptionCreateFromH264ParameterSets.

Output:

videoDecompressionSession could not be created (status: -12911): 
video format: <CMVideoFormatDescription 0x281894360 [0x1dacc01b8]> {
	mediaType:'vide' 
	mediaSubType:'avc1' 
	mediaSpecific: {
		codecType: 'avc1'		dimensions: 1920 x 1080 
	} 
	extensions: {{
    CVImageBufferChromaLocationBottomField = Left;
    CVImageBufferChromaLocationTopField = Left;
    CVImageBufferColorPrimaries = "ITU_R_709_2";
    CVImageBufferTransferFunction = "ITU_R_709_2";
    CVImageBufferYCbCrMatrix = "ITU_R_709_2";
    CVPixelAspectRatio =     {
        HorizontalSpacing = 1;
        VerticalSpacing = 1;
    };
    FullRangeVideo = 0;
    SampleDescriptionExtensionAtoms =     {
        avcC = {length = 119, bytes = 0x01640028 ffe10064 67640028 ad90a470 ... 68ff3cb0 fdf8f800 };
    };
}}
}

Any help on this would be greatly appreciated! :)

I have this exact issue as well, it seems to be an issue with M1 iPads exclusively. I tested it on M1 iPad Pro 12.9 (5th Generation) as well as iPad Air (5th Generation), works fine on M1 Macbook Pro (2020)

According to VTErrors.h, -12911 is kVTVideoDecoderMalfunctionErr. The name is not very helpful.

But in your code, you need to actually pass good values for decoderSpecification, imageBufferAttributes and outputCallback, not just nil.

My only guess is your SPS and PPS parameters are incorrect. They should not include the start code (0001), and don't forget to subtract the length of the start code (4). Like this:

OSStatus status = CMVideoFormatDescriptionCreateFromH264ParameterSets(
    NULL,
    2,
    (const uint8_t *[]) {spsBuffer + 4, ppsBuffer + 4},
    (const size_t[]) {spsSize - 4, ppsSize - 4},
    4,
    &videoFormat
);
VTDecompressionSessionCreate fails with code -12911 on M1 iPad
 
 
Q