【问题标题】:iOS AVCaptureSession - How to get/set the number of frames per second recorded?iOS AVCaptureSession - 如何获取/设置每秒记录的帧数?
【发布时间】:2012-12-26 10:27:26
【问题描述】:

我是 AVCaptureSession 的新手,希望更好地了解如何使用它。 所以我设法将视频流捕获为单独的 CIImages 并将它们转换为 UIImages。 现在我希望能够获取每秒捕获的帧数,并且最好能够设置它。

知道怎么做吗?

【问题讨论】:

    标签: ios frame-rate avcapturesession


    【解决方案1】:

    AVCaptureConnection's videoMinFrameDuration 已弃用。

    您可以使用AVCaptureDevice 属性来检测支持的视频帧速率范围,并可以使用属性分配最小和最大帧速率。

    device.activeFormat.videoSupportedFrameRateRanges 返回设备支持的所有视频帧率范围。

    device.activeVideoMinFrameDurationdevice.activeVideoMaxFrameDuration 可用于指定帧持续时间。

    【讨论】:

      【解决方案2】:

      您可以使用AVCaptureConnectionvideoMinFrameDuration 访问器来设置值。

      AVCaptureConnection documentation

      output 视为AVCaptureVideoDataOutput 对象。

      AVCaptureConnection *conn = [output connectionWithMediaType:AVMediaTypeVideo];
      
      if (conn.isVideoMinFrameDurationSupported)
          conn.videoMinFrameDuration = CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND);
      if (conn.isVideoMaxFrameDurationSupported)
          conn.videoMaxFrameDuration = CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND);
      

      更多信息,请在SO question查看我的回答

      【讨论】:

      • 是否保证我的 fps 不会低于我的最小/最大值?如何获取当前的实际 fps,而不是最小值和最大值?
      • @TylerPfaff 您找到问题的答案了吗?
      • @Crashalot 太长了,我不记得了 :(
      • 现在不推荐使用这些属性。有什么替代方法吗?
      • @ShravyaBoggarapu 在下面查看我的答案。我已经更新了。
      【解决方案3】:

      要设置捕获会话帧速率,您必须使用 device.activeVideoMinFrameDurationdevice.activeVideoMaxFrameDuration 在设备上进行设置(如有必要)。

      Swift 4 中,您可以执行以下操作:

      extension AVCaptureDevice {
          func set(frameRate: Double) {
          guard let range = activeFormat.videoSupportedFrameRateRanges.first,
              range.minFrameRate...range.maxFrameRate ~= frameRate
              else {
                  print("Requested FPS is not supported by the device's activeFormat !")
                  return
          }
      
          do { try lockForConfiguration()
              activeVideoMinFrameDuration = CMTimeMake(value: 1, timescale: Int32(frameRate))
              activeVideoMaxFrameDuration = CMTimeMake(value: 1, timescale: Int32(frameRate))
              unlockForConfiguration()
          } catch {
              print("LockForConfiguration failed with error: \(error.localizedDescription)")
          }
        }
      }
      

      然后叫它

      device.set(frameRate: 60)
      

      【讨论】:

        【解决方案4】:

        这样做

        if let frameSupportRange = currentCamera.activeFormat.videoSupportedFrameRateRanges.first {
            captureSession.beginConfiguration()
            // currentCamera.activeVideoMinFrameDuration = CMTimeMake(1, Int32(frameSupportRange.maxFrameRate))
            currentCamera.activeVideoMinFrameDuration = CMTimeMake(1, YOUR_FPS_RATE)
            captureSession.commitConfiguration()
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-08-20
          • 1970-01-01
          • 1970-01-01
          • 2012-03-24
          • 2019-04-21
          • 2011-03-18
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多