             self.btnStop.isEnabled = recording
         }
     }
+    var startTime:CMTime?
     
     var context:VSContext = VSContext(device: MTLCreateSystemDefaultDevice()!)
     var runtime:VSRuntime?

            return
        }
        recording = true
        self.writer = VSVideoWriter(delegate: self)
        let size = CGSize(width: texture.width, height: texture.height)
        let _ = self.writer?.startWriting(size: size)

                DispatchQueue.main.async {
                    self.texture = self.context.pop()?.texture // store it for renderer
                    self.context.flush()
                    if self.recording {
                        if self.startTime == nil {
                            self.startTime = presentationTime
                        }
                        let relativeTime = CMTimeSubtract(presentationTime, self.startTime!)
                        self.writer?.append(texture: self.texture, presentationTime: relativeTime)
                    }
                }
            }
            commandBuffer.commit()
