I have a running session and a preview layer that is presented inside my view.
I need to change the output several times in my application among AVCaptureStillImageOutput, AVCaptureMetadataOutput and AVCaptureVideoDataOutput, while my preview should appear smoothly without blinking.
The problem: when I add an output to this session then the preview is blinking (please find my attached gif).
The specific lines causes the problem:
self.stillImageOutput = AVCaptureStillImageOutput()
self.stillImageOutput?.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
if session.canAddOutput(self.stillImageOutput) {
session.addOutput(self.stillImageOutput)
}
My question: How to avoid AVCaptureVideoPreviewLayer from blinking when adding output to a running session?