diff --git a/device/webcam/webcam.go b/device/webcam/webcam.go index 583a8158..bb41b7cf 100644 --- a/device/webcam/webcam.go +++ b/device/webcam/webcam.go @@ -197,6 +197,10 @@ func (w *Webcam) Start() error { // Stop will kill the ffmpeg process and close the output pipe. func (w *Webcam) Stop() error { + if !w.isRunning { + return nil + } + w.isRunning = false close(w.done) if w.cmd == nil || w.cmd.Process == nil { return errors.New("ffmpeg process was never started") @@ -205,12 +209,7 @@ func (w *Webcam) Stop() error { if err != nil { return fmt.Errorf("could not kill ffmpeg process: %w", err) } - err = w.out.Close() - if err == nil { - w.isRunning = false - return nil - } - return err + return w.out.Close() } // Read implements io.Reader. If the pipe is nil a read error is returned.