title: How to avoid AVCaptureVideoPreviewLayer from blinking when changing AVCaptureOutput
body: <p><a href="https://i.stack.imgur.com/50sV0.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/50sV0.gif" alt="enter image description here"></a></p>
  
  <p>I have a running session and a preview layer that is presented inside my view.</p>
  
  <p>I need to change the output several times in my application among AVCaptureStillImageOutput, AVCaptureMetadataOutput and AVCaptureVideoDataOutput, while my preview should appear smoothly without blinking.</p>
  
  <p>The problem: when I add an output to this session then the preview is blinking (please find my attached gif).</p>
  
  <p>The specific lines causes the problem:</p>
  
  <pre><code>self.stillImageOutput = AVCaptureStillImageOutput()
  self.stillImageOutput?.outputSettings = [AVVideoCodecKey: AVVideoCodecJPEG]
  if session.canAddOutput(self.stillImageOutput) {
      session.addOutput(self.stillImageOutput)
  }
  </code></pre>
  
  <p>My question: 
  How to avoid AVCaptureVideoPreviewLayer from blinking when adding output to a running session?</p>