mirror of https://bitbucket.org/ausocean/av.git
Created motion filter that has a minimum frame rate.
This commit is contained in:
parent
016bbf0553
commit
9876b0cd35
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
DESCRIPTION
|
||||
A motion filter that has a variable frame rate. When motion is detected,
|
||||
the filter sends all frames and when it is not, the filter sends frames
|
||||
at a reduced rate, as set by a parameter.
|
||||
|
||||
AUTHORS
|
||||
Scott Barnard <scott@ausocean.org>
|
||||
|
||||
LICENSE
|
||||
variable_fps.go is Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
||||
|
||||
It is free software: you can redistribute it and/or modify them
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package filter
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// VariableFps is a filter that has a variable frame rate. When motion is
|
||||
// detected, the filter sends all frames and when it is not, the filter
|
||||
// sends frames at a reduced framerate.
|
||||
type VariableFps struct {
|
||||
motionFilter Filter
|
||||
dst io.WriteCloser
|
||||
frames uint
|
||||
count uint
|
||||
}
|
||||
|
||||
// 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)
|
||||
return &VariableFps{mf, dst, frames, 0}
|
||||
}
|
||||
|
||||
// Implements io.Writer.
|
||||
// Write applies the motion filter to the video stream. Frames are sent
|
||||
// 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
|
||||
return v.dst.Write(f)
|
||||
}
|
||||
|
||||
return v.motionFilter.Write(f)
|
||||
}
|
||||
|
||||
// Implements io.Closer.
|
||||
// Close calls the motion filter's Close method.
|
||||
func (v *VariableFps) Close() error {
|
||||
return v.motionFilter.Close()
|
||||
}
|
|
@ -112,6 +112,7 @@ const (
|
|||
const (
|
||||
FilterNoOp = iota
|
||||
FilterMOG
|
||||
FilterVariableFPS
|
||||
)
|
||||
|
||||
// Config provides parameters relevant to a revid instance. A new config must
|
||||
|
|
|
@ -333,6 +333,8 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
|
|||
r.filter = filter.NewNoOp(r.encoders)
|
||||
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)
|
||||
default:
|
||||
panic("Undefined Filter")
|
||||
}
|
||||
|
@ -630,7 +632,7 @@ func (r *Revid) Update(vars map[string]string) error {
|
|||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid VerticalFlip param", "value", value)
|
||||
}
|
||||
case "Filter":
|
||||
m := map[string]int{"NoOp": config.FilterNoOp, "MOG": config.FilterMOG}
|
||||
m := map[string]int{"NoOp": config.FilterNoOp, "MOG": config.FilterMOG, "VariableFPS": config.FilterVariableFPS}
|
||||
v, ok := m[value]
|
||||
if !ok {
|
||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid FilterMethod param", "value", value)
|
||||
|
|
Loading…
Reference in New Issue