CVPixelBuffer to CIImage always returning nil

我们两清 提交于 2019-12-04 05:15:23

Solved this problem - I was trying on simulator, while it seems that is is only supported on devices.

Laz

It seems that you do not have iosurface properties key defined. Not 100% it will solve your issue, but try this:

CFDictionaryRef attrs = (CFDictionaryRef)@{
    (id)kCVPixelBufferWidthKey: @(WIDTH_OF_YOUR_VIDEO_GOES_HERE),
    (id)kCVPixelBufferHeightKey: @(HEIGHT_OF_YOUR_VIDEO_GOES_HERE),
    (id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;), // kCVPixelFormatType_32BGRA
    (id)kCVPixelBufferIOSurfacePropertiesKey: @{},
}

And pass this dictionary along with other keys during creation of your pixelbuffer

That's not the way you set the content of a layer; this is:

(__bridge id)uiImage.CGImage;

There's no way you got what you had working on a device or a simulator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!