gpt4 book ai didi

ios - 使用 iPad Pro 9.7"上的前置摄像头以 60 FPS 捕捉视频

转载 作者:行者123 更新时间:2023-11-29 06:00:03 24 4
gpt4 key购买 nike

我正在尝试将 AVCaptureSession 配置为使用 iPad Pro 9.7"上的前置摄像头以 640x480、60 FPS 抓取帧。

在配置过程中,我有以下几行:

  for videoFormat in (captureDevice?.formats)! {

let descriptions = videoFormat.formatDescription
let dimensions = CMVideoFormatDescriptionGetDimensions(descriptions)
let width = dimensions.width
let height = dimensions.height

if ((width != 640) || (height != 480)) {
continue
}
// let videoFormatDescriptionRef = videoFormat.formatDescription

for range in videoFormat.videoSupportedFrameRateRanges {
if range.maxFrameRate == 60 {
bestFormat = videoFormat
bestFrameRateRange = range
break
}
}

if ( bestFormat != nil) {
captureDevice!.activeFormat = bestFormat!;
captureDevice!.activeVideoMinFrameDuration = bestFrameRateRange!.minFrameDuration;
captureDevice!.activeVideoMaxFrameDuration = bestFrameRateRange!.minFrameDuration;
break
}
}

当我列出相机支持的视频格式时,我得到以下列表:

<AVCaptureDeviceFormat: 0x282fa1fc0 'vide'/'420v'  192x 144, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @6.67), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR> 

<AVCaptureDeviceFormat: 0x282fa1fb0 'vide'/'420f' 192x 144, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @6.67), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR, supports wide color>

<AVCaptureDeviceFormat: 0x282fa1fa0 'vide'/'420v' 352x 288, { 2- 60 fps}, fov:49.895, max zoom:60.00 (upscales @3.33), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR>

<AVCaptureDeviceFormat: 0x282fa1f90 'vide'/'420f' 352x 288, { 2- 60 fps}, fov:49.895, max zoom:60.00 (upscales @3.33), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR, supports wide color>

<AVCaptureDeviceFormat: 0x282fa1f80 'vide'/'420v' 480x 360, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @2.67), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR>

<AVCaptureDeviceFormat: 0x282fa1f70 'vide'/'420f' 480x 360, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @2.67), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR, supports wide color>

<AVCaptureDeviceFormat: 0x282fa1f60 'vide'/'420v' 640x 480, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @2.00), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR>

<AVCaptureDeviceFormat: 0x282fa1f50 'vide'/'420f' 640x 480, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @2.00), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR, supports wide color>

<AVCaptureDeviceFormat: 0x282fa2030 'vide'/'420v' 960x 540, { 2- 60 fps}, fov:58.480, max zoom:48.50 (upscales @1.43), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR>

<AVCaptureDeviceFormat: 0x282fa2040 'vide'/'420f' 960x 540, { 2- 60 fps}, fov:58.480, max zoom:48.50 (upscales @1.43), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR, supports wide color>

<AVCaptureDeviceFormat: 0x282fa2050 'vide'/'420v' 1024x 768, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @1.25), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR>

<AVCaptureDeviceFormat: 0x282fa2060 'vide'/'420f' 1024x 768, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @1.25), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR, supports wide color>

<AVCaptureDeviceFormat: 0x282fa2070 'vide'/'420v' 1280x 720, { 2- 60 fps}, fov:58.480, max zoom:48.50 (upscales @1.08), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR>

<AVCaptureDeviceFormat: 0x282fa2080 'vide'/'420f' 1280x 720, { 2- 60 fps}, fov:58.480, max zoom:48.50 (upscales @1.08), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR, supports wide color>

<AVCaptureDeviceFormat: 0x282fa2090 'vide'/'420v' 1280x 960, { 2- 60 fps}, HRSI:2576x1932, fov:54.400, max zoom:60.00 (upscales @1.00), ISO:34.0-2176.0, SS:0.000013-0.500000>

<AVCaptureDeviceFormat: 0x282fa20a0 'vide'/'420f' 1280x 960, { 2- 60 fps}, HRSI:2576x1932, fov:54.400, max zoom:60.00 (upscales @1.00), ISO:34.0-2176.0, SS:0.000013-0.500000, supports wide color>

因为我对 640x480 特别感兴趣,所以我想要其中之一:

<AVCaptureDeviceFormat: 0x282fa1f60 'vide'/'420v'  640x 480, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @2.00), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR> 

<AVCaptureDeviceFormat: 0x282fa1f50 'vide'/'420f' 640x 480, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @2.00), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR, supports wide color>

我选择第一个:

<AVCaptureDeviceFormat: 0x282fa1f60 'vide'/'420v'  640x 480, { 2- 60 fps}, fov:54.400, max zoom:60.00 (upscales @2.00), ISO:34.0-2176.0, SS:0.000013-0.500000, supports HDR> 

如果我理解正确的话,如果我选择这种格式,我可以将帧速率设置为 2 到 60 FPS 之间的任何帧速率。

我通过设置以下几行选择 60 FPS:

  captureDevice!.activeVideoMinFrameDuration = bestFrameRateRange!.minFrameDuration;
captureDevice!.activeVideoMaxFrameDuration = bestFrameRateRange!.minFrameDuration;

我什至尝试过这个

let fps60 = CMTimeMake(value: 1, timescale: 60)
captureDevice!.activeVideoMinFrameDuration = fps60;
captureDevice!.activeVideoMaxFrameDuration = fps60;

无论我做什么,视频总是以 30 FPS 捕获。

我正在设置捕获 session

self.captureSession.sessionPreset = AVCaptureSession.Preset.vga640x480
let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .front)

注意:我对 640x480 并不是特别感兴趣。这似乎是我能想到的最轻的分辨率,可以使捕捉速度更快。我会选择任何能让前置摄像头达到 60 FPS 的分辨率。

我怎样才能做到这一点?

谢谢

最佳答案

以下内容似乎不正确,因为 bestFrameRateRange!.minFrameDuration 应该是 2?

captureDevice!.activeVideoMinFrameDuration = bestFrameRateRange!.minFrameDuration;
captureDevice!.activeVideoMaxFrameDuration = bestFrameRateRange!.minFrameDuration;

此外,您是否在设置帧持续时间之前调用lockForConfiguration

do {
try captureDevice!.lockForConfiguration()
let fps60 = CMTimeMake(value: 1, timescale: 60)
captureDevice!.activeVideoMinFrameDuration = fps60;
captureDevice!.activeVideoMaxFrameDuration = fps60;
captureDevice!.unlockForConfiguration()
} catch {
// handle error
}

关于ios - 使用 iPad Pro 9.7"上的前置摄像头以 60 FPS 捕捉视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54777363/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com