mirror of https://bitbucket.org/ausocean/av.git
PR changes #1
This commit is contained in:
parent
5286ded51f
commit
62af00ff4f
|
@ -8,7 +8,7 @@ AUTHORS
|
||||||
Scott Barnard <scott@ausocean.org>
|
Scott Barnard <scott@ausocean.org>
|
||||||
|
|
||||||
LICENSE
|
LICENSE
|
||||||
variable_fps.go is Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
vfps.go is Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
||||||
|
|
||||||
It is free software: you can redistribute it and/or modify them
|
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
|
under the terms of the GNU General Public License as published by the
|
||||||
|
@ -30,39 +30,38 @@ import (
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VariableFps is a filter that has a variable frame rate. When motion is
|
// VariableFPSFilter 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
|
// detected, the filter sends all frames and when it is not, the filter
|
||||||
// sends frames at a reduced framerate.
|
// sends frames at a reduced framerate.
|
||||||
type VariableFps struct {
|
type VariableFPSFilter struct {
|
||||||
motionFilter Filter
|
filter Filter
|
||||||
dst io.WriteCloser
|
dst io.WriteCloser
|
||||||
frames uint
|
frames uint
|
||||||
count uint
|
count uint
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewVariableFps returns a pointer to a new VariableFps filter.
|
// NewVariableFPSFilter returns a pointer to a new VariableFPSFilter struct.
|
||||||
func NewVariableFps(dst io.WriteCloser, minFPS float64, debug bool) *VariableFps {
|
func NewVariableFPSFilter(dst io.WriteCloser, minFPS float64, filter Filter) *VariableFPSFilter {
|
||||||
frames := uint(25 / minFPS)
|
frames := uint(25 / minFPS)
|
||||||
mf := NewMOGFilter(dst, 25, 20, 500, 3, debug)
|
return &VariableFPSFilter{filter, dst, frames, 0}
|
||||||
return &VariableFps{mf, dst, frames, 0}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements io.Writer.
|
// Implements io.Writer.
|
||||||
// Write applies the motion filter to the video stream. Frames are sent
|
// 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
|
// at a reduced frame rate, except when motion is detected, then all frames
|
||||||
// with motion are sent.
|
// with motion are sent.
|
||||||
func (v *VariableFps) Write(f []byte) (int, error) {
|
func (v *VariableFPSFilter) Write(f []byte) (int, error) {
|
||||||
v.count = (v.count + 1) % v.frames
|
v.count = (v.count + 1) % v.frames
|
||||||
|
|
||||||
if v.count == 0 {
|
if v.count == 0 {
|
||||||
return v.dst.Write(f)
|
return v.dst.Write(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
return v.motionFilter.Write(f)
|
return v.filter.Write(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements io.Closer.
|
// Implements io.Closer.
|
||||||
// Close calls the motion filter's Close method.
|
// Close calls the motion filter's Close method.
|
||||||
func (v *VariableFps) Close() error {
|
func (v *VariableFPSFilter) Close() error {
|
||||||
return v.motionFilter.Close()
|
return v.filter.Close()
|
||||||
}
|
}
|
|
@ -334,7 +334,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
|
||||||
case config.FilterMOG:
|
case config.FilterMOG:
|
||||||
r.filter = filter.NewMOGFilter(r.encoders, 25, 20, 500, 3, true)
|
r.filter = filter.NewMOGFilter(r.encoders, 25, 20, 500, 3, true)
|
||||||
case config.FilterVariableFPS:
|
case config.FilterVariableFPS:
|
||||||
r.filter = filter.NewVariableFps(r.encoders, 1.0, true)
|
r.filter = filter.NewVariableFPSFilter(r.encoders, 1.0, filter.NewMOGFilter(r.encoders, 25, 20, 500, 3, true))
|
||||||
default:
|
default:
|
||||||
panic("Undefined Filter")
|
panic("Undefined Filter")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue