iOS Camera Development:4K Resolution And High FrameRate Settings
所属分类:ios | 浏览:440 | 发布于 2025-07-16
there are two ways to set 4k resolution.
- w1: through the sessionPreset of AVCaptureSession
- w2: through the activeFormat of AVCaptureDevice
the most important different of them is you can set high frameRate through the activeFormat
1、sessionPreset
A preset value that indicates the quality level or bit rate of the output.
Specify a preset value to configure a capture session’s format and settings. The default preset is high, which produces high-quality video and audio output, but you can specify any preset value that returns true for a call to canSetSessionPreset(_:).
i don't want to talk sessionPreset because i'll need set high frameRate for my app.
here are some code from doubao ai:
// 设置为4K分辨率
if session.canSetSessionPreset(.photo) {
session.sessionPreset = .photo // 使用photo预设可支持最高分辨率
} else if session.canSetSessionPreset(.hd4K3840x2160) {
session.sessionPreset = .hd4K3840x2160 // 4K预设
} else {
print("无法设置4K分辨率,使用默认")
session.sessionPreset = .high
}
2、activeFormat
The currently active media data format of the capture device.
我花了一段时间才找到4k和60fps录制视频的答案。我的设置是iphone,Swift 4和iOS 12.3
- 确保捕获设备设置为AVCaptureDevice.default(for:.video)!不要使用AVCaptureDevice.DiscoverySession,因为它不会返回AVCaptureDevice.Format中的4k和60fps设置。
- 循环通过格式数组查找和设置所需的格式。4k和60fps所需的格式应该如下所示: AVCaptureDeviceFormat: 0x2820d8700‘vide’/‘420 v’。采购产品3840x2160,{ 3-60 fps}
最后一件事是使用AVOutputSettingsAssistant类在AVAssetWriter中配置输出设置字典。输出设置应该是AVOutputSettingsPresetHEVC3840x2160。如果视频设置为AVOutputSettingsPreset3840x2160,则视频输出将不稳定。
3、links