             return
         }
         recording = true
+        startTime = nil
         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()
                    self.writer?.append(texture: self.texture, presentationTime: presentationTime)
                }
            }
            commandBuffer.commit()

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