【问题标题】:Decoding frames with VTDecompressionSessionDecodeFrame fails with 12909 error使用 VTDecompressionSessionDecodeFrame 解码帧失败并出现 12909 错误
【发布时间】:2020-06-03 11:25:45
【问题描述】:

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

这是我的代码:

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

【问题讨论】:

  • 不能直接回答你的问题。错误 12909 表示“错误数据错误”,即 kVTVideoDecoderBadDataErr。或许错误码的含义可以帮助你进一步调试。
  • 看看我的代码,有什么看起来不对的地方吗?有什么方法可以调试该数据有什么问题吗?这些 CMSampleBuffers 被传递给 AVSampleBufferDisplayLayer 并且它们显示正确,所以它一定是我的减压设置有问题:\ @manishg
  • 看看您如何创建 CMSampleBuffer 以及随附的格式说明将非常有用,它可能是其中一个未正确构造

标签: ios avfoundation video-toolbox


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 2016-03-06
    • 2021-11-27
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    相关资源
    最近更新 更多