【发布时间】: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