I want to reduce the video capture frame rate in the AVCapture system

I am trying to reduce the video capture frame rate for my application, as I find that it affects the performance of VoiceOver.

Currently, it captures frames from a video camera, and then processes frames using OpenGL routines as quickly as possible. I would like to set a specific frame rate during the capture process.

I expected that I could do this using videoMinFrameDuration or minFrameDuration, but that does not seem to make any difference to performance. Any ideas?

NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; for (AVCaptureDevice *device in devices) { if ([device position] == AVCaptureDevicePositionBack) { backFacingCamera = device; // SET SOME OTHER PROPERTIES } } // Create the capture session captureSession = [[AVCaptureSession alloc] init]; // Add the video input NSError *error = nil; videoInput = [[[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error] autorelease]; // Add the video frame output videoOutput = [[AVCaptureVideoDataOutput alloc] init]; [videoOutput setAlwaysDiscardsLateVideoFrames:YES]; [videoOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; [videoOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()]; // Start capturing if([backFacingCamera supportsAVCaptureSessionPreset:AVCaptureSessionPreset1920x1080]) { [captureSession setSessionPreset:AVCaptureSessionPreset1920x1080]; captureDeviceWidth = 1920; captureDeviceHeight = 1080; #if defined(VA_DEBUG) NSLog(@"Video AVCaptureSessionPreset1920x1080"); #endif } else do some fall back stuff // If you wish to cap the frame rate to a known value, such as 15 fps, set // minFrameDuration. AVCaptureConnection *conn = [videoOutput connectionWithMediaType:AVMediaTypeVideo]; if (conn.supportsVideoMinFrameDuration) conn.videoMinFrameDuration = CMTimeMake(1,2); else videoOutput.minFrameDuration = CMTimeMake(1,2); if ([captureSession canAddInput:videoInput]) [captureSession addInput:videoInput]; if ([captureSession canAddOutput:videoOutput]) [captureSession addOutput:videoOutput]; if (![captureSession isRunning]) [captureSession startRunning]; 

Any ideas? Am I missing something? Is this the best way to throttle?

 AVCaptureConnection *conn = [videoOutput connectionWithMediaType:AVMediaTypeVideo]; if (conn.supportsVideoMinFrameDuration) conn.videoMinFrameDuration = CMTimeMake(1,2); else videoOutput.minFrameDuration = CMTimeMake(1,2); 
+4
source share
2 answers

Mike Ulrich answers work before ios 7. These two methods, unfortunately, are deprecated in ios7. You must set activeVideo{Min|Max}FrameDuration to AVCaptureDevice. Sort of:

 int fps = 30; // Change this value AVCaptureDevice *device = ...; // Get the active capture device [device lockForConfiguration:nil]; [device setActiveVideoMinFrameDuration:CMTimeMake(1, fps)]; [device setActiveVideoMaxFrameDuration:CMTimeMake(1, fps)]; [device unlockForConfiguration]; 
+5
source

Turns out you need to set both videoMinFrameDuration and videoMaxFrameDuration to work.

eg:

 [conn setVideoMinFrameDuration:CMTimeMake(1,1)]; [conn setVideoMaxFrameDuration:CMTimeMake(1,1)]; 
+2
source

Source: https://habr.com/ru/post/1398991/


All Articles