revid & cmd/revid-cli: added InputFPS config.Config field

The InputFPS field can control rate at which we lex frames from the input source. This has
not been a useful feature until now; we now want to simulate realtime input device using file
input. This requires firstly the Loop mode, and now also realistic input rate.
This commit is contained in:
Saxon 2020-01-24 20:05:43 +10:30
parent 99b931f948
commit 0f5aaf6cb5
3 changed files with 20 additions and 4 deletions

View File

@ -133,6 +133,7 @@ func handleFlags() config.Config {
saturationPtr = flag.Int("Saturation", 0, "Set Saturation. (100-100)") saturationPtr = flag.Int("Saturation", 0, "Set Saturation. (100-100)")
exposurePtr = flag.String("Exposure", "auto", "Set exposure mode. ("+strings.Join(raspivid.ExposureModes[:], ",")+")") exposurePtr = flag.String("Exposure", "auto", "Set exposure mode. ("+strings.Join(raspivid.ExposureModes[:], ",")+")")
autoWhiteBalancePtr = flag.String("Awb", "auto", "Set automatic white balance mode. ("+strings.Join(raspivid.AutoWhiteBalanceModes[:], ",")+")") autoWhiteBalancePtr = flag.String("Awb", "auto", "Set automatic white balance mode. ("+strings.Join(raspivid.AutoWhiteBalanceModes[:], ",")+")")
inputFPSPtr = flag.Int("InputFPS", 0, "Input source processing FPS")
// Audio specific flags. // Audio specific flags.
sampleRatePtr = flag.Int("SampleRate", 48000, "Sample rate of recorded audio") sampleRatePtr = flag.Int("SampleRate", 48000, "Sample rate of recorded audio")
@ -180,8 +181,6 @@ func handleFlags() config.Config {
} }
} }
cfg.Loop = *loopPtr
switch *inputPtr { switch *inputPtr {
case "Raspivid": case "Raspivid":
cfg.Input = config.InputRaspivid cfg.Input = config.InputRaspivid
@ -238,6 +237,8 @@ func handleFlags() config.Config {
netsender.ConfigFile = *configFilePtr netsender.ConfigFile = *configFilePtr
} }
cfg.InputFPS = *inputFPSPtr
cfg.Loop = *loopPtr
cfg.CameraIP = *cameraIPPtr cfg.CameraIP = *cameraIPPtr
cfg.Rotation = *rotationPtr cfg.Rotation = *rotationPtr
cfg.HorizontalFlip = *horizontalFlipPtr cfg.HorizontalFlip = *horizontalFlipPtr

View File

@ -86,6 +86,7 @@ const (
defaultAudioInputCodec = codecutil.ADPCM defaultAudioInputCodec = codecutil.ADPCM
defaultPSITime = 2 defaultPSITime = 2
defaultMotionInterval = 5 defaultMotionInterval = 5
defaultInputFPS = 0
// Ring buffer defaults. // Ring buffer defaults.
defaultRBMaxElements = 10000 defaultRBMaxElements = 10000
@ -300,6 +301,10 @@ type Config struct {
// If true will restart reading of input after an io.EOF. // If true will restart reading of input after an io.EOF.
Loop bool Loop bool
// Defines the rate at which an input source is processed. If reading
// from a realtime source, InputFPS is not necessary and should be 0 (default).
InputFPS int
} }
// TypeData contains information about all of the variables that // TypeData contains information about all of the variables that
@ -321,15 +326,17 @@ var TypeData = map[string]string{
"HTTPAddress": "string", "HTTPAddress": "string",
"Input": "enum:raspivid,rtsp,v4l,file", "Input": "enum:raspivid,rtsp,v4l,file",
"InputCodec": "enum:H264,MJPEG", "InputCodec": "enum:H264,MJPEG",
"InputFPS": "int",
"InputPath": "string", "InputPath": "string",
"KNNHistory": "uint", "KNNHistory": "uint",
"KNNKernel": "float", "KNNKernel": "float",
"KNNMinArea": "float", "KNNMinArea": "float",
"KNNThreshold": "float", "KNNThreshold": "float",
"logging": "enum:Debug,Info,Warning,Error,Fatal", "logging": "enum:Debug,Info,Warning,Error,Fatal",
"Loop": "bool",
"MinFPS": "float", "MinFPS": "float",
"MinFrames": "uint", "MinFrames": "uint",
"mode": "enum:Normal,Paused,Burst", "mode": "enum:Normal,Paused,Burst,Loop",
"MOGHistory": "uint", "MOGHistory": "uint",
"MOGMinArea": "float", "MOGMinArea": "float",
"MOGThreshold": "float", "MOGThreshold": "float",
@ -524,6 +531,11 @@ func (c *Config) Validate() error {
} }
} }
if c.InputFPS <= 0 {
c.Logger.Log(logger.Info, pkg+"InputFPS bad or unset, defaulting", "InputFPS", defaultInputFPS)
c.InputFPS = defaultInputFPS
}
return nil return nil
} }

View File

@ -428,8 +428,11 @@ func (r *Revid) Start() error {
return err return err
} }
// Calculate delay between frames based on InputFPS.
d := time.Duration(1000/r.cfg.InputFPS) * time.Millisecond
r.wg.Add(1) r.wg.Add(1)
go r.processFrom(r.input, (1000/25)*time.Millisecond) go r.processFrom(r.input, d)
r.running = true r.running = true
return nil return nil