Query for optimal pixel format when capturing video on iOS?
The AVFoundation Programming Guide states that the preferred pixel formats when capturing video are:
- for iPhone 4:
kCVPixelFormatType开发者_如何学Go_420YpCbCr8BiPlanarVideoRange
orkCVPixelFormatType_32BGRA
- for iPhone 3G:
kCVPixelFormatType_422YpCbCr8
orkCVPixelFormatType_32BGRA
(There are no recommendations [yet] for the iPhone 5 or for iPad devices with cameras.)
There is however no help provided as to how I should go about and determine what device the app is currently running on. And what if the preferred pixel format becomes different on a future and therefor to my app unknown device?
What is the correct, and future proof, way to determine the preferred YpCbCr pixel format for any device?
I believe you can just set the video settings to nil and AVFoundation will use the most efficient format. For instance instead of doing
NSDictionary *videoSettings = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
videoOutput.videoSettings = videoSettings;
Do this instead
videoOutput.videoSettings = nil;
You may also try not setting it at all. I know in the past I would just set this to nil unless I needed to capture images in a specific format.
edit
To get the format AVFoundation chose to use.
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(source);
CGColorSpaceRef cref = CVImageBufferGetColorSpace(imageBuffer);
精彩评论