Post

Replies

Boosts

Views

Activity

Focus Hunting when using 60fps for video camera
When setting the AVCaptureDeviceFormat to 1080p@60fps for the back video camera there is an issue with the camera constantly re-focusing even though the subject area barely changes. Anyone have any workarounds for this issue?This is repeatable by modifying the following Apple sample code to use 1080p@60fps:AVCamManual: Extending AVCam to Use Manual Capture API: https://developer.apple.com/library/archive/samplecode/AVCamManual/Introduction/Intro.html#//apple_ref/doc/uid/TP40014578Add the following method to AVCamManualCameraViewController.m:// test -- manually select a device format -(void)selectDesiredFormat:(AVCaptureDevice *)device { NSArray *theFormats = [device formats]; for ( AVCaptureDeviceFormat *format in theFormats ) { CMFormatDescriptionRef formatRef = format.formatDescription; CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatRef); if (dimensions.height == 1080) { NSLog(@"got dimensions=1080"); for ( AVFrameRateRange *range in format.videoSupportedFrameRateRanges ) { if ( range.maxFrameRate >= 60 ) { NSLog(@"found frame rate >=60"); if ( YES == [device lockForConfiguration:NULL] ) { device.activeFormat = format; NSLog(@"format: %@",format); device.activeVideoMinFrameDuration = range.minFrameDuration; device.activeVideoMaxFrameDuration = range.minFrameDuration; [device unlockForConfiguration]; return; } } } } } }And then call this method from:- (IBAction)changeCaptureMode:(UISegmentedControl *)captureModeControl { ... else if ( captureModeControl.selectedSegmentIndex == AVCamManualCaptureModeMovie ) { ... // Insert call here [self selectDesiredFormat:self.videoDevice]; dispatch_async( dispatch_get_main_queue(), ^{ self.recordButton.enabled = YES; } ); }This should allow you to change the format to run 1080p@60fps.Now do the following steps:1) Build and run the updated project in Xcode (latest version, although this problem has been around for over a year)2) Change the camera mode to "Movie" by tapping the segment control in upper right3) Move the camera around slightly (becomes even more of an issue when closer to objects but happens when far away as well)4) From the debugger console notice all the "context == AdjustingFocusContext" printouts even though the camera is barely moving. (called by observing on "videoDevice.focusMode". May need to add this as I don't remember if this debug code was already in there)You can also observe this by viewing the preview and seeing the focus constantly adjusting even though the subject area barely changes... I call this problem "focus hunting" as the camera just can't seem to settle in on a focus.If you need a comparison to how it should work, comment out the added line: [self selectDesiredFormat:self.videoDevice], which will default the video camera to 1080p@30fps, and go through the steps above again. No focus hunting. Smooth focus even when you do change the subject area.In addition, if you use the builtin camera app and change the format to 1080p@60fps, this issue does not exist.I submitted a bug report (FB7390937) but have yet to get any response. I don't necessarily need it fixed but would like to know if anyone has any workarounds for this issue. I can't be the only one to run across this right??
4
1
1.8k
Oct ’19