在 iOS 上捕获视频时查询最佳像素格式?

发布于 2024-12-01 08:08:23 字数 637 浏览 3 评论 0原文

AVFoundation 编程指南指出,捕获视频时的首选像素格式是:

  • 对于 iPhone 4: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRangekCVPixelFormatType_32BGRA
  • iPhone 3G 的

kCVPixelFormatType_422YpCbCr8kCVPixelFormatType_32BGRA (目前还没有针对 iPhone 5 的建议)或带摄像头的 iPad 设备。)

但是没有提供帮助我应该如何确定应用程序当前在什么设备上运行。如果首选像素格式在未来变得不同,从而导致我的应用程序未知设备发生变化,该怎么办?

确定任何设备的首选 YpCbCr 像素格式的正确且面向未来的方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝在阴天搁浅。 2024-12-08 08:08:23

我相信你可以将视频设置设置为零,AVFoundation 将使用最有效的格式。例如,

NSDictionary *videoSettings = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
videoOutput.videoSettings = videoSettings;

而不是执行此操作

videoOutput.videoSettings = nil;

您也可以尝试根本不设置它, 。我知道过去我会将其设置为零,除非我需要以特定格式捕获图像。

编辑

获取 AVFoundation 选择使用的格式。

CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(source);
CGColorSpaceRef cref = CVImageBufferGetColorSpace(imageBuffer);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文