To convert a buffer to an image, you first need to convert the buffer to CIImage , which you can then convert to NSImage .
let ciImage = CIImage(cvImageBuffer: pixelBuffer) let context = CIContext(options: nil)
From here you can go to GCImage and NSImage :
let width = CVPixelBufferGetWidth(pixelBuffer) let height = CVPixelBufferGetHeight(pixelBuffer) let cgImage = context.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: width, height: height)) let nsImage = NSImage(cgImage: cgImage, size: CGSize(width: width, height: height))
source share