iOS AVFoundation:获取 AVCaptureDevice.Format 的视频尺寸

时间:2021-02-01 16:53:53

标签: ios swift xcode avfoundation avcapturesession

我正在尝试向用户显示可以拍摄照片/视频的尺寸。

虽然可以通过 AVCaptureDevice.Format.highResolutionStillImageDimensions 轻松访问照片尺寸,但我不知道如何为视频实现相同的效果。

我已经尝试过 AVCaptureDevice.Format.formatDescription.dimensions 属性(或 .presentationDimensions(..) func),但那些只是给了我以下编译错误:

enter image description here Console output

由于这些自 iOS 13.0 起可用(我认为那是 Swift 5.1?),我绝对应该拥有这些 API(特别是因为我可以在我的代码中 CMD + 单击它们),并且我的项目应该可以编译。我在这里错过了什么吗?是否有更好的解决方案来获得捕获设备可以录制视频的分辨率?

3 个答案:

答案 0 :(得分:2)

你只需要下面一行。就是这样。

   let dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription)

答案 1 :(得分:0)

没有直接的 API 来获取视频分辨率。 您可以将 AVCaptureSession.sessionPreset 设置为 AVCaptureSession.Preset 之一,然后使用 canSetSessionPreset(_:) 检查当前设备是否支持预设。

答案 2 :(得分:0)

我只是做了以下测试并打印了所有可用的视频尺寸:

fit

我还检查了它是否为 iOS、模拟器和 macOS 编译,并且确实如此。

你还在支持 iOS 12 吗?你检查过你的 SDK 设置了吗?