1

I'm trying to record a video at 120fps, in 640x480.

I can set the fps with:

// currentCamera is an AVCaptureDevice, session is an AVCaptureSession
let input = try AVCaptureDeviceInput(device: currentCamera)
session.addInput(input)
let targetFrameRate = CMTimeMake(1, 120)
if let slowMoFormat = currentCamera.formats
  .flatMap({ return ($0 as? AVCaptureDeviceFormat) })
  .filter({ format in
    for x in format.videoSupportedFrameRateRanges {
      if let range = x as? AVFrameRateRange {
        if range.minFrameDuration <= targetFrameRate {
          return true
        }
      }
    }
    return false
  }).first {
  try currentCamera.lockForConfiguration()
  currentCamera.activeFormat = slowMoFormat
  currentCamera.activeVideoMinFrameDuration = targetFrameRate
  currentCamera.activeVideoMaxFrameDuration = targetFrameRate
  currentCamera.unlockForConfiguration()
}

or the video size with

// session is an AVCaptureSession
session.sessionPreset = AVCaptureSessionPreset640x480

But I can't do both, since changing the activeFormat, or session preset override the other change. Is there something obvious I'm missing?

Guig
  • 9,891
  • 7
  • 64
  • 126
  • did you try setting `minFramDuration` for `AVCaptureVideoDataOutput`?because that is what you end up seeing in preview. – Bluewings Dec 16 '16 at 03:48
  • It doesn't seem that there is a `minFrameDuration` on `AVCaptureVideoDataOutput`: https://developer.apple.com/reference/avfoundation/avcapturevideodataoutput. It has a `videoSettings` property but this seems to only concern codec type, and not video size: https://developer.apple.com/reference/avfoundation/avcapturevideodataoutput/1389945-videosettings – Guig Dec 16 '16 at 05:20
  • sorry..it was deprecated from iOS5.0..Use AVCaptureConnection's videoMinFrameDuration property instead. – Bluewings Dec 16 '16 at 06:50
  • I don't think I can set a min frame duration on the AVCaptureConnection to a value lower than what the activeFormat can support, and the format comes with a predefined video size. I ended up recording at a high frame rate, big video size, and then resizing... – Guig Dec 16 '16 at 08:22
  • Why do we always set the activeVideoMinFrameDuration and activeVideoMaxFrameDuration to the same value? – nr5 Jul 01 '17 at 10:49
  • So that it's precisely defined – Guig Jul 01 '17 at 15:03

0 Answers0