diff --git a/main.go b/main.go index 5928771..d6adbe1 100644 --- a/main.go +++ b/main.go @@ -56,6 +56,14 @@ func main() { fmt.Printf("Start reading device: %v\n", deviceID) + // This is a warm up ladies and gentlemen. + for i := 0; i < 20; i++ { + if ok := webcam.Read(&img); !ok { + fmt.Printf("Device closed: %v\n", deviceID) + return + } + } + // main loop for { if ok := webcam.Read(&img); !ok { @@ -88,7 +96,7 @@ func main() { currentRecording.Write(img) // Determine if we should stop recording - if lastMotionDetectedTime.Add(time.Second * recordLengthAfterMotion).After(time.Now()) { + if lastMotionDetectedTime.Add(time.Second * recordLengthAfterMotion).Before(time.Now()) { log.Printf("motion has not been detected for the last %d seconds stopping recording to file", recordLengthAfterMotion) err = currentRecording.Close() if err != nil {