【发布时间】:2019-03-29 15:47:48
【问题描述】:
我目前正在尝试使用 VideoToolbox 对来自 AVCaptureVideoDataOutput 的视频数据进行编码,但在从 VTCompressionOutputCallback 中引用 self 时遇到问题。
我的代码如下:
...
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))
...
效果很好,打印输出也符合预期,但只要我尝试在 VTCompressionOutputCallback 中添加对 self 的引用,就会出现编译器错误提示
A C function pointer cannot be formed from a closure that captures context
如何在回调中使用self?
提前感谢您的帮助。
【问题讨论】:
标签: ios swift avfoundation video-toolbox