【问题标题】:iPhone capture session: Set custom frame-rateiPhone 捕获会话:设置自定义帧速率
【发布时间】:2021-06-29 02:55:50
【问题描述】:

我已经设置了一个 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)

我做错了什么?

谢谢

【问题讨论】:

    标签: iphone avfoundation frame-rate avcapturesession vision


    【解决方案1】:

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

    Mine 报告了许多能够达到 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()
    

    【讨论】:

    • 另一个后续问题,因为您是该主题的专家:除了仅检查 3 秒内收集的帧实际上是否为 180 之外,我对此进行测试的最佳方法是什么? (我的模型尺寸)因为我实际上只输入了 2 fps,它看起来仍然像 30 一样流畅:/
    【解决方案2】:

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

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

        // 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

    再次感谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多