我正在尝试解码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
}
}
}