@@ -295,13 +295,27 @@ - (void)createVideoDataOutput;
295
295
296
296
297
297
// set default FPS
298
- if ([self .videoDataOutput connectionWithMediaType: AVMediaTypeVideo].supportsVideoMinFrameDuration ) {
299
- [self .videoDataOutput connectionWithMediaType: AVMediaTypeVideo].videoMinFrameDuration = CMTimeMake (1 , self.defaultFPS );
298
+ AVCaptureDeviceInput *currentInput = [self .captureSession.inputs objectAtIndex: 0 ];
299
+ AVCaptureDevice *device = currentInput.device ;
300
+
301
+ NSError *error = nil ;
302
+ [device lockForConfiguration: &error];
303
+
304
+ float maxRate = ((AVFrameRateRange*) [device.activeFormat.videoSupportedFrameRateRanges objectAtIndex: 0 ]).maxFrameRate ;
305
+ if (maxRate > self.defaultFPS - 1 && error == nil ) {
306
+ [device setActiveVideoMinFrameDuration: CMTimeMake (1 , self .defaultFPS)];
307
+ [device setActiveVideoMaxFrameDuration: CMTimeMake (1 , self .defaultFPS)];
308
+ NSLog (@" [Camera] FPS set to %d " , self.defaultFPS);
309
+ } else {
310
+ NSLog (@" [Camera] unable to set defaultFPS at %d FPS, max is %f FPS" , self.defaultFPS, maxRate);
300
311
}
301
- if ([self .videoDataOutput connectionWithMediaType: AVMediaTypeVideo].supportsVideoMaxFrameDuration ) {
302
- [self .videoDataOutput connectionWithMediaType: AVMediaTypeVideo].videoMaxFrameDuration = CMTimeMake (1 , self.defaultFPS );
312
+
313
+ if (error != nil ) {
314
+ NSLog (@" [Camera] unable to set defaultFPS: %@ " , error);
303
315
}
304
316
317
+ [device unlockForConfiguration ];
318
+
305
319
// set video mirroring for front camera (more intuitive)
306
320
if ([self .videoDataOutput connectionWithMediaType: AVMediaTypeVideo].supportsVideoMirroring ) {
307
321
if (self.defaultAVCaptureDevicePosition == AVCaptureDevicePositionFront) {
@@ -329,7 +343,7 @@ - (void)createVideoDataOutput;
329
343
[self .videoDataOutput setSampleBufferDelegate: self queue: videoDataOutputQueue];
330
344
331
345
332
- NSLog (@" [Camera] created AVCaptureVideoDataOutput at %d FPS " , self.defaultFPS );
346
+ NSLog (@" [Camera] created AVCaptureVideoDataOutput" );
333
347
}
334
348
335
349
0 commit comments