3

我正在尝试解码CMSampleBuffer,以便分析他们的像素数据。12909我打电话时不断出错VTDecompressionSessionDecodeFrame。这对我来说都是全新的——有什么想法可能是问题所在吗?

这是我的代码:

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
        }
    }
}
4

1 回答 1

0

在我的应用程序中,我从 CMBlockBuffer 创建了 CMSampleBuffer。CMBlockBuffer 是从从 h.264 流中提取的字节数组创建的。创建 CMBlockBuffer 时,我在 NALU 标头中写入了一个错误的数组大小。在我的情况下,这导致了 -12909(坏数据)错误。

于 2021-01-04T15:57:20.203 回答