我在Swift中有这个代码并得到一个错误:CVImageBuffer不能转换为Unmanaged
func getTextureFromSampleBuffer(sampleBuffer: CMSampleBuffer!) -> GLuint {
cleanupVideoTextures()
var unmanagedImageBuffer: Unmanaged<CVImageBuffer> = CMSampleBufferGetImageBuffer(sampleBuffer) // Here get the error
var imageBuffer = unmanagedImageBuffer.takeUnretainedValue()
var opaqueImageBuffer = unmanagedImageBuffer.toOpaque()
我该如何投这个?
谢谢!
答案 0 :(得分:2)
CMSampleBufferGetImageBuffer()
不会占用一个非托管对象(可能会改变它)
测试版之间)。你可以替换
var unmanagedImageBuffer: Unmanaged<CVImageBuffer> = CMSampleBufferGetImageBuffer(sampleBuffer) // Here get the error
var imageBuffer = unmanagedImageBuffer.takeUnretainedValue()
简单地通过
var imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)