Last active
March 30, 2025 22:33
-
-
Save johnnyclem/8608904 to your computer and use it in GitHub Desktop.
this method sets the camera frame rate to the max available for the device
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
- (void)configureCameraForHighestFrameRate:(AVCaptureDevice *)device | |
{ | |
AVCaptureDeviceFormat *bestFormat = nil; | |
AVFrameRateRange *bestFrameRateRange = nil; | |
for ( AVCaptureDeviceFormat *format in [device formats] ) { | |
for ( AVFrameRateRange *range in format.videoSupportedFrameRateRanges ) { | |
if ( range.maxFrameRate > bestFrameRateRange.maxFrameRate ) { | |
bestFormat = format; | |
bestFrameRateRange = range; | |
} | |
} | |
} | |
if ( bestFormat ) { | |
if ( [device lockForConfiguration:NULL] == YES ) { | |
device.activeFormat = bestFormat; | |
device.activeVideoMinFrameDuration = bestFrameRateRange.minFrameDuration; | |
device.activeVideoMaxFrameDuration = bestFrameRateRange.minFrameDuration; | |
[device unlockForConfiguration]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment