iOS camera video recording quality issues related

  • problem

    The functions of taking photos, scanning codes, and video recording are written in the front, and the functions required in the front are enough to be realized, but the picture quality is not enough in the back

  • Ideas

    Possible cause analysis:

    1. AVCaptureSession setting the output format will affect the image quality and clarity

    2. The focus/exposure processing is not done during the photo, or the focus/exposure setting parameters cause blur

  • solve

    For reason 1, list the pixels (height *width) corresponding to sessionPreset as follows:

    AVCaptureSessionPresetHigh                  1920*1080
    AVCaptureSessionPresetMedium                480*360
    AVCaptureSessionPresetLow                   192*144
    AVCaptureSessionPresetPhoto                 4032*3024
    AVCaptureSessionPreset352x288               352*288
    AVCaptureSessionPreset640x480               640*480
    AVCaptureSessionPreset1280x720              1280*720
    AVCaptureSessionPreset1920x1080             1920*1080
    AVCaptureSessionPreset3840x2160             3840*2160
    AVCaptureSessionPresetiFrame960x540         960*540
    AVCaptureSessionPresetiFrame1280x720        1280*720
    AVCaptureSessionPresetInputPriority         1920*1080

    Set this parameter as needed

    For reason 2, focus/exposure settings:

    /* 必须先设置聚焦位置,再设定聚焦方式 */
    CGRect rectLayer = self.preView.frame;
    CGPoint ccenter = CGPointMake((rectLayer.origin.x + rectLayer.size.width) / 2, (rectLayer.origin.y + rectLayer.size.height) / 2);
    CGPoint cpoint = [self.preView captureDevicePointForPoint:ccenter];
    
    AVCaptureDevice *devices= [self.dInput device];
    [self.session beginConfiguration];
    [devices lockForConfiguration:nil];
    // 设置聚焦点的位置
    if ([devices isFocusPointOfInterestSupported]) {
        [devices setFocusPointOfInterest:cpoint];
    }
    // 设置聚焦模式
    if ([devices isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) {
        [devices setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
    }
    
    // 设置曝光点的位置
    if ([devices isExposurePointOfInterestSupported]) {
        [devices setExposurePointOfInterest:cpoint];
    }
    // 设置曝光模式
    if ([devices isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) {
        [devices setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
    }
    
    [device unlockForConfiguration];
    [self.session commitConfiguration];

    The focus mode and exposure mode settings are very interesting:

    typedef NS_ENUM(NSInteger, AVCaptureFocusMode) {
        // 将焦点锁定在镜头的当前位置
        AVCaptureFocusModeLocked              = 0,
        // 设备应自动对焦一次,然后将对焦模式更改为AVCaptureFocusModeLocked
        AVCaptureFocusModeAutoFocus           = 1,
        // 设备应在需要时自动对焦
        AVCaptureFocusModeContinuousAutoFocus = 2,
    }
    
    typedef NS_ENUM(NSInteger, AVCaptureExposureMode) {
        // 将曝光锁定在其当前值
        AVCaptureExposureModeLocked                            = 0,
        // 自动调整一次曝光,然后将曝光模式更改为AVCaptureExposureModeLocked
        AVCaptureExposureModeAutoExpose                        = 1,
        // 在需要时自动调整曝光
        AVCaptureExposureModeContinuousAutoExposure            = 2,
        // 仅根据用户提供的ISO,DurationDuration值来调整曝光
        AVCaptureExposureModeCustom API_AVAILABLE(macos(10.15), ios(8.0)) = 3,
    }

    When I set the focus mode = AVCaptureFocusModeAutoFocus, and the exposure mode = AVCaptureExposureModeAutoExpose, there will be a focusing process, but there is a gap with the system taking pictures.

    After debugging the parameters in ContinuousAuto mode, the image quality and clarity are almost the same as the system taking pictures.

  • end

Guess you like

Origin blog.51cto.com/15070994/2668333