3

I'm trying to decode CMSampleBuffer so I can analyze their pixel data. I keep getting error 12909 when I call VTDecompressionSessionDecodeFrame. This is all very new to me - any ideas where might be the problem?

Here's my code:

func decode(sampleBuffer: CMSampleBuffer) {
    let imageBufferAttributes: CFDictionary? = [kCVPixelBufferOpenGLESCompatibilityKey: true,
                                                kCVPixelBufferPixelFormatTypeKey:kCVPixelFormatType_32BGRA] as CFDictionary
    let formatDes = sampleBuffer.formatDescription!
    VTDecompressionSessionCreate(allocator: kCFAllocatorDefault,
                                 formatDescription: formatDes,
                                 decoderSpecification: nil,
                                 imageBufferAttributes: imageBufferAttributes,
                                 outputCallback: nil,
                                 decompressionSessionOut: &session)


    let flags: VTDecodeFrameFlags = []
    var flagOut: VTDecodeInfoFlags = []
    let canAccept = VTDecompressionSessionCanAcceptFormatDescription(session!,
                                                                     formatDescription: formatDes)
    print("Can accept: \(canAccept)") // true
    VTDecompressionSessionDecodeFrame(session!,
                                      sampleBuffer: sampleBuffer,
                                      flags: flags,
                                      infoFlagsOut: &flagOut)
    { status, infoFlags,imageBuffer, _ , _ in
        guard let imageBuffer = imageBuffer else {
            print("Error decoding. No image buffer. \(status)") // 12909
            return
        }
    }
}
msmialko
  • 1,439
  • 2
  • 20
  • 35
  • Not straightforward to answer your question. The error 12909 means "Bad data error" i.e. kVTVideoDecoderBadDataErr. Perhaps the error code meaning can help you debug this further. – manishg Jun 10 '20 at 01:34
  • Looking at my code, is there anything that looks wrong? Is there any way to debug what's wrong with that data? Those CMSampleBuffers are passed to `AVSampleBufferDisplayLayer` and they are displayed correctly so it must be something wrong with my decompression settings :\ @manishg – msmialko Jun 10 '20 at 08:49
  • It would be very useful to see how you created the CMSampleBuffer, along with the format description provided with it, it could be one or the other has not been constructed properly – Declan Stewart McPartlin Jun 13 '20 at 19:10

1 Answers1

0

I my application I created the CMSampleBuffer from a CMBlockBuffer. The CMBlockBuffer was created from a byte array extracted from a h.264 stream. When creating the CMBlockBuffer I wrote a false array size into the NALU header. That was causing the -12909 (Bad Data) error in my case.

RobX
  • 51
  • 4