diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 1eaf4cfe..af87b38e 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -129,6 +129,10 @@ func handleFlags() revid.Config { quantizationPtr = flag.Uint("Quantization", 0, "Desired quantization value: 0-40") intraRefreshPeriodPtr = flag.Uint("IntraRefreshPeriod", 0, "The IntraRefreshPeriod i.e. how many keyframes we send") rotationPtr = flag.Uint("Rotatation", 0, "Rotate video output. (0-359 degrees)") + brightnessPtr = flag.Uint("Brightness", 50, "Set brightness. (0-100) ") + saturationPtr = flag.Int("Saturation", 0, "Set Saturation. (100-100)") + exposurePtr = flag.String("Exposure", "auto", "Set exposure mode. ("+strings.Join(revid.ExposureModes[:], ",")+")") + autoWhiteBalancePtr = flag.String("Awb", "auto", "Set automatic white balance mode. ("+strings.Join(revid.AutoWhiteBalanceModes[:], ",")+")") ) var outputs flagStrings @@ -256,6 +260,10 @@ func handleFlags() revid.Config { cfg.IntraRefreshPeriod = *intraRefreshPeriodPtr cfg.RtpAddress = *rtpAddrPtr cfg.SendRetry = *sendRetryPtr + cfg.Brightness = *brightnessPtr + cfg.Saturation = *saturationPtr + cfg.Exposure = *exposurePtr + cfg.AutoWhiteBalance = *autoWhiteBalancePtr return cfg } diff --git a/revid/config.go b/revid/config.go index d7e906a2..209e692c 100644 --- a/revid/config.go +++ b/revid/config.go @@ -70,6 +70,40 @@ type Config struct { SendRetry bool BurstPeriod uint Rotation uint + Brightness uint + Saturation int + Exposure string + AutoWhiteBalance string +} + +// Possible modes for raspivid --exposure parameter. +var ExposureModes = [...]string{ + "auto", + "night", + "nightpreview", + "backlight", + "spotlight", + "sports", + "snow", + "beach", + "verylong", + "fixedfps", + "antishake", + "fireworks", +} + +// Possible modes for raspivid --awb parameter. +var AutoWhiteBalanceModes = [...]string{ + "off", + "auto", + "sun", + "cloud", + "shade", + "tungsten", + "fluorescent", + "incandescent", + "flash", + "horizon", } // Enums for config struct @@ -257,5 +291,32 @@ func (c *Config) Validate(r *Revid) error { if c.RtpAddress == "" { c.RtpAddress = defaultRtpAddr } + + if c.Brightness < 0 || c.Brightness > 100 { + return errors.New("bad brightness setting in config") + } + + if c.Saturation < -100 || c.Saturation > 100 { + return errors.New("bad saturation setting in config") + } + + if !stringInSlice(c.Exposure, ExposureModes[:]) { + return errors.New("bad exposure setting in config") + } + + if !stringInSlice(c.AutoWhiteBalance, AutoWhiteBalanceModes[:]) { + return errors.New("bad awb setting in config") + } + return nil } + +// stringInSlice returns true if want is in slice. +func stringInSlice(want string, slice []string) bool { + for _, s := range slice { + if s == want { + return true + } + } + return false +} diff --git a/revid/revid.go b/revid/revid.go index 41ea03c5..198bc547 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -358,6 +358,22 @@ func (r *Revid) Update(vars map[string]string) error { //look through the vars and update revid where needed for key, value := range vars { switch key { + case "Saturation": + s, err := strconv.ParseInt(value, 10, 0) + if err != nil { + r.config.Logger.Log(logger.Warning, pkg+"invalid saturation param", "value", value) + } + r.config.Saturation = int(s) + case "Brightness": + b, err := strconv.ParseUint(value, 10, 0) + if err != nil { + r.config.Logger.Log(logger.Warning, pkg+"invalid brightness param", "value", value) + } + r.config.Brightness = uint(b) + case "Exposure": + r.config.Exposure = value + case "AutoWhiteBalance": + r.config.AutoWhiteBalance = value case "Output": outputs := strings.Split(value, ",") r.config.Outputs = make([]uint8, len(outputs)) @@ -594,6 +610,14 @@ func (r *Revid) startRaspivid() error { "--bitrate", fmt.Sprint(r.config.Bitrate), "--framerate", fmt.Sprint(r.config.FrameRate), "--rotation", fmt.Sprint(r.config.Rotation), + "--brightness", fmt.Sprint(r.config.Brightness), + "--saturation", fmt.Sprint(r.config.Saturation), + "--exposure", fmt.Sprint(r.config.Exposure), + "--awb", fmt.Sprint(r.config.AutoWhiteBalance), + } + + if r.config.FlipHorizontal { + args = append(args, "--hflip") } if r.config.FlipVertical {