From d17f7c87e97d2707b2dd297c9b599f7cc4850271 Mon Sep 17 00:00:00 2001 From: saxon Date: Wed, 19 Sep 2018 22:02:50 +0930 Subject: [PATCH] revid: fixed raspivid args and logging --- revid/revid.go | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index 16a1fea0..fb2a192e 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -36,6 +36,7 @@ import ( "os" "os/exec" "strconv" + "strings" "time" "bitbucket.org/ausocean/av/rtmp" @@ -421,39 +422,32 @@ func (r *Revid) startRaspivid() error { r.config.Logger.Log(smartlogger.Info, "Starting raspivid!") switch r.config.InputCodec { case H264: - // FIXME(saxon): consider using a map right from the start to store - // the raspivid args - raspiArgs := make(map[string]string) - raspiArgs["-cd"] = "H264" - raspiArgs["-o"] = "-" - raspiArgs["-n"] = "" - raspiArgs["-t"] = runContinuously - raspiArgs["-b"] = r.config.Bitrate - raspiArgs["-w"] = r.config.Width - raspiArgs["-h"] = r.config.Height - raspiArgs["-fps"] = r.config.FrameRate - raspiArgs["-ih"] = "" - raspiArgs["-g"] = r.config.IntraRefreshPeriod + args := []string{ + "-cd", "H264", + "-o", "-", + "-n", + "-t", runContinuously, + "-b", r.config.Bitrate, + "-w", r.config.Width, + "-h", r.config.Height, + "-fps", r.config.FrameRate, + "-ih", + "-g", r.config.IntraRefreshPeriod, + } if r.config.QuantizationMode == QuantizationOn { - raspiArgs["-qp"] = r.config.Quantization + args = append(args, "-qp", r.config.Quantization) } if r.config.HorizontalFlip == Yes { - raspiArgs["-hf"] = strconv.Itoa(int(r.config.HorizontalFlip)) + args = append(args, "-hf") } if r.config.VerticalFlip == Yes { - raspiArgs["-vf"] = strconv.Itoa(int(r.config.VerticalFlip)) + args = append(args, "-vf") } // Log all the args and create []string - args := make([]string, 0) - for i := range raspiArgs { - r.config.Logger.Log(smartlogger.Info, "Raspivid arg", i, raspiArgs[i]) - // First append the flag - args = append(args, i) - // and now append any values for the flag - args = append(args, raspiArgs[i]) - } - r.cmd = exec.Command("raspivid", args...) + argsStr := strings.Join(args, " ") + r.config.Logger.Log(smartlogger.Info, "Raspivid args", "raspividArgs", argsStr) + r.cmd = exec.Command("raspivid", argsStr) case Mjpeg: // FIXME(saxon): do above in this case too