我正在尝试让一个简单的渲染相机输出到金属层管道运行,它在 Objective-C 中运行良好(有 MetalVideoCapture 示例应用程序)但是当我尝试时似乎有一些格式怪异把它翻译成swift。我的超简单捕获缓冲区看起来像这样(忽略缺乏清理...)
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
var error: CVReturn! = nil
let sourceImageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
let width = CVPixelBufferGetWidth(sourceImageBuffer!)
let height = CVPixelBufferGetHeight(sourceImageBuffer!)
var outTexture: CVMetalTextureRef? = nil
error = CVMetalTextureCacheCreateTextureFromImage(kCFAllocatorDefault, videoTextureCache!, sourceImageBuffer!, nil, MTLPixelFormat.BGRA8Unorm, width, height, 0, &outTexture!)
if error != nil {
print("Error! \(error)")
}
let videoTexture = CVMetalTextureGetTexture(outTexture!)
self.imageTexture = videoTexture!
}
videoTextureCache 在哪里var videoTextureCache: CVMetalTextureCache? = nil
但它给了我Cannot invoke 'CVMetalTextureCacheCreateTextureFromImage' with an argument list of type '(CFAllocator!, CVMetalTextureCache, CVImageBuffer, nil, MTLPixelFormat, Int, Int, Int, inout CVMetalTextureRef)'
问题是,如果我用 nil 替换 outTexture 它会停止抛出错误,但显然这对我没有帮助。根据函数的参考,我需要 UnsafeMutablePointer?> 作为最后一个值。我不知道如何得到。