Created
March 29, 2022 04:04
-
-
Save abinhho/68cbfb9eae821d252f9104fce2bd6c08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func setMaxFps(device: AVCaptureDevice) { | |
var minFPS = 0.0 | |
var maxFPS = 0.0 | |
var maxWidth:Int32 = 0 | |
var selectedFormat:AVCaptureDevice.Format? = nil | |
for format in device.formats { | |
for range in format.videoSupportedFrameRateRanges { | |
let desc = format.formatDescription | |
let dimentions = CMVideoFormatDescriptionGetDimensions(desc) | |
if(minFPS <= range.minFrameRate && maxFPS <= range.maxFrameRate && maxWidth <= dimentions.width){ | |
minFPS = range.minFrameRate | |
maxFPS = range.maxFrameRate | |
maxWidth = dimentions.width | |
selectedFormat = format | |
} | |
} | |
} | |
do { | |
try device.lockForConfiguration() | |
device.activeFormat = selectedFormat! | |
device.activeVideoMinFrameDuration = CMTimeMake(value: 1, timescale: Int32(minFPS)) | |
// Set lowest frame rate to reduce memory | |
device.activeVideoMaxFrameDuration = CMTimeMake(value: 1, timescale: Int32(minFPS)) | |
device.unlockForConfiguration() | |
} catch { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment