Jonathan Plackett
Jonathan Plackett

Reputation: 2436

Setting a low frame rate of AVCaptureDevice in AVCaptureSession in Swift

I am trying to set a frame rate of 10 frames per second when capturing with an AVCaptureDevice in Swift.

I believe this is achieved by setting activeVideoMaxFrameDuration of the AVCaptureDevice but maybe I am doing this all wrong and there's a different way.

Here is my current code, which runs without error, but doesn't make any difference to the framerate in the preview or captured video, which still appears to be full motion.

    var devices = AVCaptureDevice.devicesWithMediaType(mediaType);
    var captureDevice: AVCaptureDevice = devices[0] as AVCaptureDevice;

    captureDevice.lockForConfiguration(&error)

    captureDevice.activeVideoMinFrameDuration = CMTimeMake(1,10)
    captureDevice.activeVideoMaxFrameDuration = CMTimeMake(1,10)

    captureDevice.unlockForConfiguration()

I have checked in AVCaptureDeviceFormat videoSupportedFrameRateRanges minFrameRate and 10 frames per second should be supported.

Changing the CMTime to something outside of the videoSupportedFrameRateRanges does throw an error so I know the code is being used, it just has no effect.

Thanks in advance for any help

Upvotes: 9

Views: 3054

Answers (1)

Liam
Liam

Reputation: 51

I think you should change the device configuration after the capture session starts running for it to take effect. I hope this works for you as it did for me. cheers =)

Upvotes: 5

Related Questions