Skip to content

Instantly share code, notes, and snippets.

@johnnyclem
Last active May 18, 2018 05:32
Show Gist options
  • Save johnnyclem/8608904 to your computer and use it in GitHub Desktop.
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
- (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