 
   private func startInputPipeline() -> Bool {
 
+    if writer.status != .unknown { return false }
+
     guard writer.startWriting() else { return false }
 
     writer.startSession(atSourceTime: kCMTimeZero)


  }

  public func startWriting() {

    if isRecording { return }
    isRecording = true

      print("AVAssetWriter Failed:", "Unknown error")
      stopDisplayLink()
      cleanUp()
      completionHandler(false)
      return
    }

    completionHandler(true)

  }

  public func finishWriting(completionHandler: (@escaping (_ url: URL) -> Void)) {

    if !isRecording { return }

    if writer.status != .writing { return }

    videoInput.markAsFinished()

