微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

iPhone 捕获会话:设置自定义帧速率

如何解决iPhone 捕获会话:设置自定义帧速率

我已经设置了一个 captureSession,现在正在尝试将帧率设置为 60。我使用的是 iPhone 12 Pro Max。

我正在尝试设置帧速率:

videoDevice?.activeVideoMinFrameDuration = CMTimeMake(value: 1,timescale: 60)

但是,打印我的 .activeFormat 告诉我我的 iPhone 只支持 30 fps。

我需要 60 fps 来匹配我的机器学习模型的帧速率。

配置:

  • 内置广角相机,
  • 视频,
  • 背部位置,
  • 横向正确的方向。

在这个枚举中没有任何允许超过 30 fps 的相机。因此,我创建了 videoDevice 对象:

let videoDevice = AVCaptureDevice.default(.builtInWideAngleCamera,for: .video,position: .back)

我做错了什么?

谢谢

解决方法

videoDevice.activeFormat 只是当前格式。 videoDevice.formats 包含所有可能的格式。

我的报告了许多能够达到 60fps 的格式,例如

<AVCaptureDeviceFormat: 0x28337d7c0 'vide'/'420f' 1280x 720,{ 1- 60 fps},HRSI:2112x1188,fov:70.291,binned,supports vis,max zoom:24.00 (upscales @1.50),AF System:1,ISO:33.0-3168.0,SS:0.000015-1.000000,supports wide color,supports multicam>
...

因此选择最适合您的格式,然后将其设为您的 activeFormat 并像这样设置所需的帧持续时间:

try! videoDevice.lockForConfiguration()

videoDevice.activeFormat = my60FPSFormat
videoDevice.activeVideoMinFrameDuration = CMTime(value: 1,timescale: 60)
videoDevice.activeVideoMaxFrameDuration = CMTime(value: 1,timescale: 60)

videoDevice.unlockForConfiguration()
,

谢谢,这回答了我的问题!:)

对于仍然想知道下面是我使用的代码的人:

    // Instantiate the video device: wide angle camera,back position
    let videoDevice = AVCaptureDevice.default(.builtInWideAngleCamera,for: .video,position: .back)
    
    
    // Set the frame rate to 60,as expected by the model
    try! videoDevice?.lockForConfiguration()
    
    videoDevice?.activeFormat = (videoDevice?.formats[30])!
    videoDevice?.activeVideoMinFrameDuration = CMTimeMake(value: 1,timescale: 60)
    videoDevice?.activeVideoMaxFrameDuration = CMTimeMake(value: 1,timescale: 60)
    
    videoDevice?.unlockForConfiguration()

    // Debug only
    // print(videoDevice?.activeFormat)

但是,请确保添加一些错误处理:D

再次感谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。