我正在使用
如果我将 VideoDataOutput 的颜色空间设置为 BGRA,它就可以正常工作(感谢这个答案 CGBitmapContextCreateImage 错误)。
没有上述videoSettings,我将会收到以下错误。
使用BGRA并不是一个好的选择,因为存在从YUV(默认AVCaptureSession颜色空间)转换为BGRA的开销,正如Brad和Codo在How to get the Y component from CMSampleBuffer resulted from the AVCaptureSession?中所述。
那么有没有一种方法将CMSampleBufferRef转换为UIImage并使用YUV颜色空间?
AVCaptureVideoDataOutput
并希望将 CMSampleBufferRef
转换为 UIImage
。许多答案都相同,例如 CMSampleBufferRef 创建的 UIImage 无法在 UIImageView 中显示? 和 具有多个预览的 AVCaptureSession。如果我将 VideoDataOutput 的颜色空间设置为 BGRA,它就可以正常工作(感谢这个答案 CGBitmapContextCreateImage 错误)。
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
[dataOutput setVideoSettings:videoSettings];
没有上述videoSettings,我将会收到以下错误。
CGBitmapContextCreate: invalid data bytes/row: should be at least 2560 for 8 integer bits/component, 3 components, kCGImageAlphaPremultipliedFirst.
<Error>: CGBitmapContextCreateImage: invalid context 0x0
使用BGRA并不是一个好的选择,因为存在从YUV(默认AVCaptureSession颜色空间)转换为BGRA的开销,正如Brad和Codo在How to get the Y component from CMSampleBuffer resulted from the AVCaptureSession?中所述。
那么有没有一种方法将CMSampleBufferRef转换为UIImage并使用YUV颜色空间?