0

我正在使用 AVCam 的视频录制。在开始视频录制之前,自动对焦工作正常。但是在视频开始录制后它会继续聚焦,这是一种令人讨厌的行为。我在 AVCaptureConnection 中禁用了视频稳定功能,但仍然没有用

AVCaptureConnection *connection = [movieFileOutput connectionWithMediaType:AVMediaTypeVideo];

        if ([connection isVideoStabilizationSupported]) {

            if (SYSTEM_VERSION_LESS_THAN(@"8.0")) {
                // For iOS 7
                [connection setEnablesVideoStabilizationWhenAvailable:NO];

            } else {
                connection.preferredVideoStabilizationMode = AVCaptureVideoStabilizationModeOff;
            }
        } 

请指导我如何在视频录制期间禁用自动对焦?

4

1 回答 1

1

我从 viewDidLoad 调用了以下方法来实现所需的功能

- (void)disableAutoFocus {
    AVCaptureDevice *device = [[self videoDeviceInput] device];
    [device lockForConfiguration:nil];

    NSArray *devices = [AVCaptureDevice devices];
    NSError *error;
    for (AVCaptureDevice *device in devices) {
        if (([device hasMediaType:AVMediaTypeVideo]) &&
            ([device position] == AVCaptureDevicePositionBack) ) {
            [device lockForConfiguration:&error];
            if ([device isFocusModeSupported:AVCaptureFocusModeLocked]) {
                device.focusMode = AVCaptureFocusModeLocked;
                NSLog(@"Focus locked");
            }

            [device unlockForConfiguration];
        }
    }
}
于 2015-07-31T05:16:12.950 回答