diff --git a/filter/variable_fps.go b/filter/variable_fps.go index 39c68d0d..606b3656 100644 --- a/filter/variable_fps.go +++ b/filter/variable_fps.go @@ -41,9 +41,9 @@ type VariableFps struct { } // NewVariableFps returns a pointer to a new VariableFps filter. -func NewVariableFps(dst io.WriteCloser, fps float64) *VariableFps { - frames := uint(25 / fps) - mf := NewMOGFilter(dst, 25, 20, 500, 3, true) +func NewVariableFps(dst io.WriteCloser, minFPS float64, debug bool) *VariableFps { + frames := uint(25 / minFPS) + mf := NewMOGFilter(dst, 25, 20, 500, 3, debug) return &VariableFps{mf, dst, frames, 0} } @@ -52,9 +52,9 @@ func NewVariableFps(dst io.WriteCloser, fps float64) *VariableFps { // at a reduced frame rate, except when motion is detected, then all frames // with motion are sent. func (v *VariableFps) Write(f []byte) (int, error) { - v.count++ - if v.count > v.frames { - v.count = 0 + v.count = (v.count + 1) % v.frames + + if v.count == 0 { return v.dst.Write(f) } diff --git a/revid/revid.go b/revid/revid.go index 8c221738..74bbe65a 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -334,7 +334,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. case config.FilterMOG: r.filter = filter.NewMOGFilter(r.encoders, 25, 20, 500, 3, true) case config.FilterVariableFPS: - r.filter = filter.NewVariableFps(r.encoders, 1.0) + r.filter = filter.NewVariableFps(r.encoders, 1.0, true) default: panic("Undefined Filter") }