From 6f94ea31074b177b2cffe6e81e9e4011e43920e8 Mon Sep 17 00:00:00 2001 From: Saxon1 Date: Sat, 5 May 2018 13:45:07 +0930 Subject: [PATCH] fixing flilp bug --- revid/Revid.go | 71 +++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/revid/Revid.go b/revid/Revid.go index 4cb2d56b..6edc5303 100644 --- a/revid/Revid.go +++ b/revid/Revid.go @@ -42,6 +42,7 @@ import ( "strconv" "sync" "time" + "filepath" "bitbucket.org/ausocean/av/generator" "bitbucket.org/ausocean/av/parser" @@ -74,6 +75,7 @@ const ( maxSendFailedErrorCount = 500 clipSizeThreshold = 11 rtmpConnectionMaxTries = 5 + raspividNoOfTries = 3 ) // Log Types @@ -528,49 +530,45 @@ func (r *revid) setupInputForRaspivid() error { r.Log(Info, "Starting raspivid!") switch r.config.InputCodec { case H264: - var quantizationFlag string - var quantizationValue string var verticalFlipFlag string var horizontalFlipFlag string - switch r.config.QuantizationMode { - case QuantizationOn: - quantizationFlag = "-qp" - quantizationValue = r.config.Quantization - case QuantizationOff: - quantizationFlag = "" - quantizationValue = "" - } - - switch r.config.HorizontalFlip { - case Yes: - horizontalFlipFlag = "-hf" - case No: - horizontalFlipFlag = "" - } - - switch r.config.VerticalFlip { - case Yes: - verticalFlipFlag = "-vf" - case No: - verticalFlipFlag = "" - } - - r.cmd = exec.Command("raspivid", - "-cd", "H264", + arguments := []string{ "-cd", "H264", "-o", "-", "-n", "-t", r.config.Timeout, "-b", "0", - quantizationFlag, quantizationValue, "-w", r.config.Width, "-h", r.config.Height, "-fps", r.config.FrameRate, "-ih", "-g", r.config.IntraRefreshPeriod, - verticalFlipFlag, - horizontalFlipFlag, - ) + } + + if r.config.QuantizationMode == QuantizationOn{ + append(arguments,"-qp") + append(arguments,r.config.Quantization); + } + + if r.config.HorizontalFlip == Yes { + append(arguments, "-hf") + } + + if r.config.VerticalFlip == Yes { + append(arguments, "-vf") + } + + r.cmd = &Cmd{ + Path: "raspivid", + Args: append([]string{"raspivid"}, arguments), + } + if filepath.Base(name) == name { + if lp, err := LookPath(name); err != nil { + cmd.lookPathErr = err + } else { + cmd.Path = lp + } + } case Mjpeg: r.cmd = exec.Command("raspivid", @@ -583,11 +581,18 @@ func (r *revid) setupInputForRaspivid() error { } stdout, _ := r.cmd.StdoutPipe() err := r.cmd.Start() - r.inputReader = bufio.NewReader(stdout) if err != nil { - r.Log(Error, err.Error()) + for i := 0; i < raspividNoOfTries; i++ { + r.Log(Error, err.Error()) + err = r.cmd.Start() + if err == nil { + goto raspividSuccess + } + } return err } + raspividSuccess: + r.inputReader = bufio.NewReader(stdout) go r.readCamera() return nil }