我目前正在尝试使用 VideoToolbox 对来自AVCaptureVideoDataOutput
,但我在引用时遇到问题self
从内部VTCompressionOutputCallback
.
我的代码如下:
...
var sessionRef: VTCompressionSession?
let outputCallback: VTCompressionOutputCallback = { _, _, status, _, sampleBuffer in
guard status == noErr, let sampleBuffer = sampleBuffer else {
return
}
debugPrint("[INFO]: outputCallback: sampleBuffer: \(sampleBuffer)")
}
let sessionErr = VTCompressionSessionCreate(allocator: nil,
width: width,
height: height,
codecType: kCMVideoCodecType_H264,
encoderSpecification: nil,
imageBufferAttributes: nil,
compressedDataAllocator: nil,
outputCallback: outputCallback,
refcon: nil,
compressionSessionOut: UnsafeMutablePointer(&sessionRef))
...
这工作正常,并且打印输出符合预期,但是一旦我尝试添加对self
内VTCompressionOutputCallback
,它得到一个编译器错误,指出
A C function pointer cannot be formed from a closure that captures context
我该如何使用self
从回调中?
先谢谢您的帮助。