Query for optimal pixel format when capturing video on iOS?

允我心安 提交于 2019-12-25 03:55:39

问题


The AVFoundation Programming Guide states that the preferred pixel formats when capturing video are:

  • for iPhone 4: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange or kCVPixelFormatType_32BGRA
  • for iPhone 3G: kCVPixelFormatType_422YpCbCr8 or kCVPixelFormatType_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?


回答1:


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);


来源:https://stackoverflow.com/questions/7186472/query-for-optimal-pixel-format-when-capturing-video-on-ios

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