Hacer una image CG de un CMSampleBuffer en Swift?

A continuación se muestra un resumen de todas las partes relevantes de mis bashs de solución.

Intento n. ° 1

CVPixelBufferLockBaseAddress(buffer, 0) let ctx = CIContext() let ciImage = CIImage(CVPixelBuffer: buffer) let cgImage = ctx.createCGImage(ciImage, fromRect: CGRectMake(0, 0, CGFloat(size.width), CGFloat(size.height))) CVPixelBufferUnlockBaseAddress(buffer, 0) 

Intento # 2

 UIGraphicsBeginImageContext(CGSizeMake(CGFloat(size.width), CGFloat(size.height))) let context = UIGraphicsGetCurrentContext() let contextData = CGBitmapContextGetData(context) CVPixelBufferLockBaseAddress(buffer, 0) let bufferData = CVPixelBufferGetBaseAddress(buffer) let bufferSize = CVPixelBufferGetDataSize(buffer) memcpy(contextData, bufferData, bufferSize) CVPixelBufferUnlockBaseAddress(buffer, 0) let cgImage = UIGraphicsGetImageFromCurrentImageContext().CGImage UIGraphicsEndImageContext() 

Intento # 3

 let bufferAddress = CVPixelBufferGetBaseAddress(buffer) let bytesPerRow = CVPixelBufferGetBytesPerRow(buffer) let colorSpace = CGColorSpaceCreateDeviceRGB() let provider = CGDataProviderCreateWithData(nil, bufferAddress, bytesPerRow * size.height, nil) let cgImage = CGImageCreate(size.width, size.height, 8, 32, bytesPerRow, colorSpace, bitmapInfo, provider, nil, true, kCGRenderingIntentDefault) 

¡Cualquier ayuda sería muy apreciada!