From 91bc6fbff99531710a5da8e12a06e3006192b5bc Mon Sep 17 00:00:00 2001 From: Jack Richardson Date: Thu, 1 Feb 2018 12:04:05 +1030 Subject: [PATCH] Everything seems to be working except for fps --- revid/RevidInstance.go | 52 +++++++++++++++++++++++++----------------- revid/revid_test.go | 9 ++++---- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/revid/RevidInstance.go b/revid/RevidInstance.go index ebcea44a..6df881c3 100644 --- a/revid/RevidInstance.go +++ b/revid/RevidInstance.go @@ -217,14 +217,19 @@ func (r *revidInst) ChangeState(config Config) error { switch config.InputCodec { case H264: - if config.Bitrate != "" && config.Quantization != "" && ( - (strconv.Atoi(config.Bitrate) > 0 && strconv.AtoI(config.Quantization) > 0) || - (strconv.Atoi(config.Bitrate) == 0 && strconv.AtoI(config.Quantization) == 0) ){ + if config.Bitrate != "" && config.Quantization != "" { + bitrate, _ := strconv.Atoi(config.Bitrate) + quantization, _ := strconv.Atoi(config.Quantization) + if (bitrate > 0 && quantization > 0) || (bitrate == 0 && quantization == 0) { return errors.New("Bad bitrate and quantization combination for H264 input!") + } } case Mjpeg: - if config.Quantization != "" && config.Quantization > 0 || config.Bitrate == "" { + if config.Quantization != "" { + quantization, _ := strconv.Atoi(config.Quantization) + if quantization > 0 || config.Bitrate == "" { return errors.New("Bad bitrate or quantization for mjpeg input!") + } } case NothingDefined: r.Log(Warning, "No input codec defined, defaulting to h264!") @@ -305,7 +310,7 @@ func (r *revidInst) ChangeState(config Config) error { r.Log(Warning, "No quantization defined, defaulting to 35!") config.Quantization = defaultQuantization } else { - if integer, err := strconv.Atoi(config.Quantization); integer <= 0 || integer > 51 || err != nil { + if integer, err := strconv.Atoi(config.Quantization); integer < 0 || integer > 51 || err != nil { return errors.New("Bad quantization defined in config!") } } @@ -342,26 +347,31 @@ func (r *revidInst) Start() { switch r.config.Input { case Raspivid: r.Log(Info, "Starting raspivid!") - var codec string switch r.config.InputCodec { case H264: - codec = "H264" + r.cmd = exec.Command("raspivid", + "-cd", "H264", + "-o", "-", + "-n", + "-t", r.config.Timeout, + "-b", r.config.Bitrate, + "-qp", r.config.Quantization, + "-w", r.config.Width, + "-h", r.config.Height, + "-fps", r.config.FrameRate, + "-ih", + "-g", r.config.IntraRefreshPeriod, + ) case Mjpeg: - codec = "MJPEG" + r.cmd = exec.Command("raspivid", + "-cd", "MJPEG", + "-o", "-", + "-n", + "-t", r.config.Timeout, + "-fps", r.config.FrameRate, + ) } - r.cmd = exec.Command("raspivid", - "-cd", codec, - "-o", "-", - "-n", - "-t", r.config.Timeout, - "-b", r.config.Bitrate, - "-qp", r.config.Quantization, - "-w", r.config.Width, - "-h", r.config.Height, - "-fps", r.config.FrameRate, - "-ih", - "-g", r.config.IntraRefreshPeriod, - ) + stdout, _ := r.cmd.StdoutPipe() err := r.cmd.Start() r.inputReader = bufio.NewReader(stdout) diff --git a/revid/revid_test.go b/revid/revid_test.go index c0ab03c5..dc6b8731 100644 --- a/revid/revid_test.go +++ b/revid/revid_test.go @@ -79,19 +79,18 @@ func TestRaspividMJPEGInput(t *testing.T){ Input: Raspivid, InputCodec: Mjpeg, Output: File, - OutputFileName: "output/TestRaspividMjpegOutput.mjpeg", + OutputFileName: "output/TestMjpeg.mjpeg", Width: "1280", - Bitrate: "1000000", + Bitrate: "10000000", Height: "720", - Quantization: "0", FrameRate: "25", } revidInst, err := NewRevidInstance(config) if err != nil { - t.Errorf("Should not of have got an error!") + t.Errorf("Should not of have got an error!: %v\n", err.Error()) return } revidInst.Start() - time.Sleep(5*time.Second) + time.Sleep(20*time.Second) revidInst.Stop() }