Everything seems to be working except for fps

This commit is contained in:
Jack Richardson 2018-02-01 12:04:05 +10:30
parent 31a13b2dc2
commit 91bc6fbff9
2 changed files with 35 additions and 26 deletions

View File

@ -217,15 +217,20 @@ func (r *revidInst) ChangeState(config Config) error {
switch config.InputCodec { switch config.InputCodec {
case H264: case H264:
if config.Bitrate != "" && config.Quantization != "" && ( if config.Bitrate != "" && config.Quantization != "" {
(strconv.Atoi(config.Bitrate) > 0 && strconv.AtoI(config.Quantization) > 0) || bitrate, _ := strconv.Atoi(config.Bitrate)
(strconv.Atoi(config.Bitrate) == 0 && strconv.AtoI(config.Quantization) == 0) ){ 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!") return errors.New("Bad bitrate and quantization combination for H264 input!")
} }
}
case Mjpeg: 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!") return errors.New("Bad bitrate or quantization for mjpeg input!")
} }
}
case NothingDefined: case NothingDefined:
r.Log(Warning, "No input codec defined, defaulting to h264!") r.Log(Warning, "No input codec defined, defaulting to h264!")
config.InputCodec = H264 config.InputCodec = H264
@ -305,7 +310,7 @@ func (r *revidInst) ChangeState(config Config) error {
r.Log(Warning, "No quantization defined, defaulting to 35!") r.Log(Warning, "No quantization defined, defaulting to 35!")
config.Quantization = defaultQuantization config.Quantization = defaultQuantization
} else { } 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!") return errors.New("Bad quantization defined in config!")
} }
} }
@ -342,15 +347,10 @@ func (r *revidInst) Start() {
switch r.config.Input { switch r.config.Input {
case Raspivid: case Raspivid:
r.Log(Info, "Starting raspivid!") r.Log(Info, "Starting raspivid!")
var codec string
switch r.config.InputCodec { switch r.config.InputCodec {
case H264: case H264:
codec = "H264"
case Mjpeg:
codec = "MJPEG"
}
r.cmd = exec.Command("raspivid", r.cmd = exec.Command("raspivid",
"-cd", codec, "-cd", "H264",
"-o", "-", "-o", "-",
"-n", "-n",
"-t", r.config.Timeout, "-t", r.config.Timeout,
@ -362,6 +362,16 @@ func (r *revidInst) Start() {
"-ih", "-ih",
"-g", r.config.IntraRefreshPeriod, "-g", r.config.IntraRefreshPeriod,
) )
case Mjpeg:
r.cmd = exec.Command("raspivid",
"-cd", "MJPEG",
"-o", "-",
"-n",
"-t", r.config.Timeout,
"-fps", r.config.FrameRate,
)
}
stdout, _ := r.cmd.StdoutPipe() stdout, _ := r.cmd.StdoutPipe()
err := r.cmd.Start() err := r.cmd.Start()
r.inputReader = bufio.NewReader(stdout) r.inputReader = bufio.NewReader(stdout)

View File

@ -79,19 +79,18 @@ func TestRaspividMJPEGInput(t *testing.T){
Input: Raspivid, Input: Raspivid,
InputCodec: Mjpeg, InputCodec: Mjpeg,
Output: File, Output: File,
OutputFileName: "output/TestRaspividMjpegOutput.mjpeg", OutputFileName: "output/TestMjpeg.mjpeg",
Width: "1280", Width: "1280",
Bitrate: "1000000", Bitrate: "10000000",
Height: "720", Height: "720",
Quantization: "0",
FrameRate: "25", FrameRate: "25",
} }
revidInst, err := NewRevidInstance(config) revidInst, err := NewRevidInstance(config)
if err != nil { 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 return
} }
revidInst.Start() revidInst.Start()
time.Sleep(5*time.Second) time.Sleep(20*time.Second)
revidInst.Stop() revidInst.Stop()
} }