ios – CVMetalTextureCacheCreateTextureFromImage始终返回null

ios – CVMetalTextureCacheCreateTextureFromImage始终返回null,第1张

概述我正试图通过MetalKit渲染I420(YCbCr规划器) 大多数例子都是使用来自Camera的CMSampleBuffer, 但我的目标是使用给定的I420字节. 我做这样的事情: let data = NSMutableData(contentsOfURL: NSBundle.mainBundle().URLForResource("yuv_640_360", withExtension: 我正试图通过MetalKit渲染I420(ycbcr规划器)

大多数例子都是使用来自Camera的CMSampleBuffer,

但我的目标是使用给定的I420字节.

我做这样的事情:

let data = NSMutableData(contentsOfURL: NSBundle.mainBundle().URLForResource("yuv_640_360",withExtension: "yuv")!)// Cache for YCVMetalTextureCacheCreate(kcfAllocatorDefault,nil,self.device!,&vIDeoTextureCache)var pixelBuffer: CVPixelBuffer?CVPixelBufferCreateWithBytes(kcfAllocatorDefault,Int(size.wIDth),Int(size.height),kCVPixelFormatType_420YpCbCr8BiPlanarVIDeoRange,data.mutableBytes,[    "kCVPixelBufferMetalCompatibilityKey": true,"kCVPixelBufferOpenGLCompatibilityKey": true,"kCVPixelBufferIOSurfacePropertIEsKey": []    ],&pixelBuffer)// Y texturevar yTextureRef : Unmanaged<CVMetalTexture>?let yWIDth = CVPixelBufferGetWIDthOfPlane(pixelBuffer,0)let yHeight = CVPixelBufferGetHeightOfPlane(pixelBuffer,0)let result = CVMetalTextureCacheCreateTextureFromImage(kcfAllocatorDefault,(vIDeoTextureCache?.takeUnretainedValue())!,pixelBuffer,MTLPixelFormat.R8Unorm,yWIDth,yHeight,&yTextureRef);

基本上代码与其他示例几乎相同,但我自己创建自己的CVPixelBuffer.

我创建CVPixelBuffer和CVMetalTexture时没有出错,

但它总是为yTexture返回null.

如何创建正确的CVPixelBuffer并使用它进行渲染?

解决方法 问题解决了.

iosurface很重要,如果你通过CVPixelBufferCreateWithBytes或CVPixelBufferCreateWithPlanarBytes创建CVPixelBuffer,我发现iosurface总是为null.

一旦你使用了iosurface为null的CVPixelBuffer,那么MetalTexture总是为空.

应该做这样的事情:

let result = CVPixelBufferCreate(kcfAllocatorDefault,wIDth,height,kCVPixelFormatType_420YpCbCr8Planar,[    String(kCVPixelBufferIOSurfacePropertIEsKey): [        "IOSurfaceOpenGLESFBOCompatibility": true,"IOSurfaceOpenGLESTextureCompatibility": true,"IOSurfaceCoreAnimationCompatibility": true,]    ],&self.pixelBuffer)CVPixelBufferLockBaseAddress(self.pixelBuffer!,0)for index in 0...2 {    memcpy(CVPixelBufferGetBaseAddressOfPlane(self.pixelBuffer!,index),planesAddress[index],planesWIDth[index] * planesHeight[index])}CVPixelBufferUnlockBaseAddress(self.pixelBuffer!,0)
总结

以上是内存溢出为你收集整理的ios – CVMetalTextureCacheCreateTextureFromImage始终返回null全部内容,希望文章能够帮你解决ios – CVMetalTextureCacheCreateTextureFromImage始终返回null所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1059460.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存