fixing flilp bug

This commit is contained in:
Saxon1 2018-05-05 13:45:07 +09:30
parent d178586d0a
commit 6f94ea3107
1 changed files with 38 additions and 33 deletions

View File

@ -42,6 +42,7 @@ import (
"strconv" "strconv"
"sync" "sync"
"time" "time"
"filepath"
"bitbucket.org/ausocean/av/generator" "bitbucket.org/ausocean/av/generator"
"bitbucket.org/ausocean/av/parser" "bitbucket.org/ausocean/av/parser"
@ -74,6 +75,7 @@ const (
maxSendFailedErrorCount = 500 maxSendFailedErrorCount = 500
clipSizeThreshold = 11 clipSizeThreshold = 11
rtmpConnectionMaxTries = 5 rtmpConnectionMaxTries = 5
raspividNoOfTries = 3
) )
// Log Types // Log Types
@ -528,49 +530,45 @@ func (r *revid) setupInputForRaspivid() error {
r.Log(Info, "Starting raspivid!") r.Log(Info, "Starting raspivid!")
switch r.config.InputCodec { switch r.config.InputCodec {
case H264: case H264:
var quantizationFlag string
var quantizationValue string
var verticalFlipFlag string var verticalFlipFlag string
var horizontalFlipFlag string var horizontalFlipFlag string
switch r.config.QuantizationMode { arguments := []string{ "-cd", "H264",
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",
"-o", "-", "-o", "-",
"-n", "-n",
"-t", r.config.Timeout, "-t", r.config.Timeout,
"-b", "0", "-b", "0",
quantizationFlag, quantizationValue,
"-w", r.config.Width, "-w", r.config.Width,
"-h", r.config.Height, "-h", r.config.Height,
"-fps", r.config.FrameRate, "-fps", r.config.FrameRate,
"-ih", "-ih",
"-g", r.config.IntraRefreshPeriod, "-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: case Mjpeg:
r.cmd = exec.Command("raspivid", r.cmd = exec.Command("raspivid",
@ -583,11 +581,18 @@ func (r *revid) setupInputForRaspivid() error {
} }
stdout, _ := r.cmd.StdoutPipe() stdout, _ := r.cmd.StdoutPipe()
err := r.cmd.Start() err := r.cmd.Start()
r.inputReader = bufio.NewReader(stdout)
if err != nil { 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 return err
} }
raspividSuccess:
r.inputReader = bufio.NewReader(stdout)
go r.readCamera() go r.readCamera()
return nil return nil
} }