Search code examples
iosswiftios-camera

swift AVCapturePhotoOutput capturePhoto hangs preview


Showing preview in 1080 x 1440; getting photo with max resolution (3024 x 4032) and quality on iPhone 8 Plus with code:

capturePhotoOutput?.capturePhoto(with: configurePhotoSettings(), delegate: self)

with photo settings:

private func configurePhotoSettings() -> AVCapturePhotoSettings {
    let photoSettings = AVCapturePhotoSettings()
    photoSettings.isHighResolutionPhotoEnabled = true
    photoSettings.isAutoStillImageStabilizationEnabled = (capturePhotoOutput?.isStillImageStabilizationSupported)!
    photoSettings.isAutoDualCameraFusionEnabled = (capturePhotoOutput?.isDualCameraFusionSupported)!
        
    return photoSettings
}

Doing this one by one (like sequential shooting mode) and preview freezes each time for a short time even if I do nothing in didFinishProcessingPhoto.


Looking for solution to make capturing smooth, maybe in background thread, but currently I'm stuck..


Solution

  • The reason of preview hangs is feature called optical stabilization.


    You just need to turn it off for smooth preview while capturing photo:

    photoSettings.isAutoStillImageStabilizationEnabled = false