CVMetalTextureCacheCreateTextureFromImage returns -6660 on macOS 10.13

前端 未结 3 1145
清酒与你
清酒与你 2021-01-12 16:31

I\'m recording the screen from my iPhone device to my Mac. As a preview layer I am collecting sample buffers directly from a AVCaptureVideoDataOutput, from whic

3条回答
  •  误落风尘
    2021-01-12 17:12

    Another way to get from a CVPixelBufferRef to MetalTexture, you could go via a CIImage and use a CIContext with a Metal device (hopefully minimises getting the CPU involved with copying the pixel buffer);

    Make sure your target metal texture is appropriately sized.

    CIContext* ciContext = [CIContext contextWithMTLDevice:mtlDevice
        options:[NSDictionary dictionaryWithObjectsAndKeys:@(NO),kCIContextUseSoftwareRenderer,nil]
    ];
    
    id metalCommandBuffer=[mtlCommandQueue commandBufferWithUnretainedReferences];
    
    CIImage* ciImage = [[CIImage alloc] initWithCVPixelBuffer:cvPixelBuffer];
    
    [ciContext render:ciImage 
        toMTLTexture:metal_texture 
        commandBuffer:mtlCommandBuffer
        bounds:[ciImage extent])
        colorSpace:[ciImage colorSpace]];
    
    

提交回复
热议问题