 
   private func startInputPipeline() -> Bool {
 
+    while CMTIME_IS_INVALID(firstAudioTimestamp) { }
+
     guard writer.startWriting() else { return false }
-    
-    if useAudio {
-      while audioCaptureStartedAt == nil && firstAudioTimestamp == nil {}
-      let millisElapsed = NSDate().timeIntervalSince(audioCaptureStartedAt! as Date) * Double(options.timeScale)
-      writer.startSession(atSourceTime: CMTimeAdd(firstAudioTimestamp!, CMTimeMake(Int64(millisElapsed), Int32(options.timeScale))))
-    }else{
-      writer.startSession(atSourceTime: kCMTimeZero)
-    }
+
+    if CMTIME_IS_INVALID(initialTime) {
+      initialTime = getCurrentCMTime()
+    }
+
+    videoStartTimestamp = getCurrentCMTime()
+
+    writer.startSession(atSourceTime: getAppendTime())
+
     videoInput.requestMediaDataWhenReady(on: frameQueue, using: {})
 
     return true


  }

  private func startDisplayLink() {

    currentTime = 0.0
    initialTime = CFAbsoluteTimeGetCurrent()
    displayLink = CADisplayLink(target: self, selector: #selector(updateDisplayLink))
    displayLink?.preferredFramesPerSecond = options.fps
    displayLink?.add(to: .main, forMode: .commonModes)


  private func prepare(with options: Options) {

    initialTime = kCMTimeInvalid

    self.options.videoSize = options.videoSize

    writer = try! AVAssetWriter(outputURL: self.options.outputUrl,
