diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index fc4d863f..d0b32e9f 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -133,6 +133,7 @@ func handleFlags() config.Config { saturationPtr = flag.Int("Saturation", 0, "Set Saturation. (100-100)") 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[:], ",")+")") + inputFPSPtr = flag.Int("InputFPS", 0, "Input source processing FPS") // Audio specific flags. sampleRatePtr = flag.Int("SampleRate", 48000, "Sample rate of recorded audio") @@ -180,8 +181,6 @@ func handleFlags() config.Config { } } - cfg.Loop = *loopPtr - switch *inputPtr { case "Raspivid": cfg.Input = config.InputRaspivid @@ -238,6 +237,8 @@ func handleFlags() config.Config { netsender.ConfigFile = *configFilePtr } + cfg.InputFPS = *inputFPSPtr + cfg.Loop = *loopPtr cfg.CameraIP = *cameraIPPtr cfg.Rotation = *rotationPtr cfg.HorizontalFlip = *horizontalFlipPtr diff --git a/revid/config/config.go b/revid/config/config.go index 47a8eaf9..8ee31ee5 100644 --- a/revid/config/config.go +++ b/revid/config/config.go @@ -86,6 +86,7 @@ const ( defaultAudioInputCodec = codecutil.ADPCM defaultPSITime = 2 defaultMotionInterval = 5 + defaultInputFPS = 0 // Ring buffer defaults. defaultRBMaxElements = 10000 @@ -300,6 +301,10 @@ type Config struct { // If true will restart reading of input after an io.EOF. 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 @@ -321,15 +326,17 @@ var TypeData = map[string]string{ "HTTPAddress": "string", "Input": "enum:raspivid,rtsp,v4l,file", "InputCodec": "enum:H264,MJPEG", + "InputFPS": "int", "InputPath": "string", "KNNHistory": "uint", "KNNKernel": "float", "KNNMinArea": "float", "KNNThreshold": "float", "logging": "enum:Debug,Info,Warning,Error,Fatal", + "Loop": "bool", "MinFPS": "float", "MinFrames": "uint", - "mode": "enum:Normal,Paused,Burst", + "mode": "enum:Normal,Paused,Burst,Loop", "MOGHistory": "uint", "MOGMinArea": "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 } diff --git a/revid/revid.go b/revid/revid.go index 9c414480..b442e34a 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -428,8 +428,11 @@ func (r *Revid) Start() error { return err } + // Calculate delay between frames based on InputFPS. + d := time.Duration(1000/r.cfg.InputFPS) * time.Millisecond + r.wg.Add(1) - go r.processFrom(r.input, (1000/25)*time.Millisecond) + go r.processFrom(r.input, d) r.running = true return nil