 
       guard let pixelBuffer = pixelBufferTemp else { return }
 
-      var presentationTime: CMTime
-
-      if(useAudio){
-        let millisElapsed = NSDate().timeIntervalSince(audioCaptureStartedAt! as Date) * Double(options.timeScale)
-        presentationTime = CMTimeAdd(firstAudioTimestamp!, CMTimeMake(Int64(millisElapsed), Int32(options.timeScale)))
-      }else{
-        currentTime = CFAbsoluteTimeGetCurrent() - initialTime
-        let value: Int64 = Int64(currentTime * CFTimeInterval(options.timeScale))
-        presentationTime = CMTimeMake(value, options.timeScale)
-      }
-
       SceneKitVideoRecorder.bufferAppendSemaphore.wait()
 
       bufferQueue.async { [weak self] in
-        if self?.videoFramesWritten == false { self?.videoFramesWritten = true }
+        if self?.videoFramesWritten == false {
+          self?.videoFramesWritten = true
+          self?.firstVideoTimestamp = (self?.getCurrentCMTime())!
+        }
         if !(self?.videoInput.isReadyForMoreMediaData)! { return }
-        self?.pixelBufferAdaptor.append(pixelBuffer, withPresentationTime: presentationTime)
+        self?.pixelBufferAdaptor.append(pixelBuffer, withPresentationTime: (self?.getAppendTime())!)
         SceneKitVideoRecorder.bufferAppendSemaphore.signal()
       }
     }
 
   }
 
-  private var audioCaptureStartedAt: NSDate?
-  private var firstAudioTimestamp: CMTime?
-
   public func captureOutput(_ output: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
 
-    if(audioCaptureStartedAt == nil) {
-      audioCaptureStartedAt = NSDate()
+    if CMTIME_IS_INVALID(firstAudioTimestamp) {
       firstAudioTimestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer)
-    }
-    if(audioInput.isReadyForMoreMediaData && isRecording && videoFramesWritten){
+      if CMTIME_IS_INVALID(initialTime) {
+        initialTime = getCurrentCMTime()
+      }
+    }
+
+    if audioInput.isReadyForMoreMediaData && isRecording && videoFramesWritten {
       audioInput.append(sampleBuffer)
     }
 

    if useAudio {
      audioInput.markAsFinished()
    }
    self.stopDisplayLink()

    self.isRecording = false
    self.isPrepared = false
    self.videoFramesWritten = false

    writer.finishWriting(completionHandler: { [weak self] in
      completionHandler(outputUrl)


    if !videoInput.isReadyForMoreMediaData { return }


    autoreleasepool {

      let time = CACurrentMediaTime()
      let image = renderer.snapshot(atTime: time, with: self.options.videoSize, antialiasingMode: self.options.antialiasingMode)

      updateFrameHandler?(image)

