Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a low frame rate of AVCaptureDevice in AVCaptureSession in Swift

Tags:

ios

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

like image 620
Jonathan Plackett Avatar asked Jan 07 '15 23:01

Jonathan Plackett


1 Answers

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 =)

like image 54
Liam Avatar answered Sep 29 '22 21:09

Liam