使用AVCam在视频录制期间禁用自动对焦

时间:2015-07-29 08:00:11

标签: ios iphone video avfoundation avcam

我正在使用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;
            }
        } 

请指导我如何在视频录制过程中禁用自动对焦?

1 个答案:

答案 0 :(得分: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];
        }
    }
}