diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 0b474906..7e375992 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -148,10 +148,10 @@ func handleFlags() revid.Config { } switch *inputPtr { - case "Webcam": - cfg.Input = revid.Webcam case "Raspivid": cfg.Input = revid.Raspivid + case "v4l": + cfg.Input = revid.V4L case "File": cfg.Input = revid.File case "": diff --git a/revid/config.go b/revid/config.go index a47fb46e..304d3e64 100644 --- a/revid/config.go +++ b/revid/config.go @@ -75,6 +75,7 @@ type Config struct { const ( NothingDefined = iota Raspivid + V4L H264Codec File Http @@ -94,7 +95,6 @@ const ( Udp MpegtsRtp Rtp - Webcam ) // Default config settings @@ -132,9 +132,7 @@ func (c *Config) Validate(r *Revid) error { } switch c.Input { - case Raspivid: - case File: - case Webcam: + case Raspivid, V4L, File: case NothingDefined: c.Logger.Log(logger.Warning, pkg+"no input type defined, defaulting", "input", defaultInput) diff --git a/revid/revid.go b/revid/revid.go index b8793545..ea1c0adc 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -246,10 +246,10 @@ func (r *Revid) reset(config Config) error { } switch r.config.Input { - case Webcam: - r.setupInput = r.startWebcam case Raspivid: r.setupInput = r.startRaspivid + case V4L: + r.setupInput = r.startV4L case File: r.setupInput = r.setupInputForFile } @@ -367,10 +367,10 @@ loop: if err == nil { r.config.Logger.Log(logger.Debug, pkg+"sent clip to output "+strconv.Itoa(i)) } else if r.config.SendRetry == false { - r.config.Logger.Log(logger.Warning, pkg+"send to output "+strconv.Itoa(i)+"failed", "error", err.Error()) + r.config.Logger.Log(logger.Warning, pkg+"send to output "+strconv.Itoa(i)+" failed", "error", err.Error()) } else { r.config.Logger.Log(logger.Error, pkg+"send to output "+strconv.Itoa(i)+ - "failed, trying again", "error", err.Error()) + " failed, trying again", "error", err.Error()) err = dest.send() if err != nil && chunk.Len() > 11 { r.config.Logger.Log(logger.Error, pkg+"second send attempted failed, restarting connection", "error", err.Error()) @@ -479,9 +479,38 @@ func (r *Revid) startRaspivid() error { return err } -func (r *Revid) startWebcam() error { +func (r *Revid) startV4L() error { + const defaultVideo = "/dev/video0" + r.config.Logger.Log(logger.Info, pkg+"starting webcam") - r.cmd = exec.Command("ffmpeg", "-i", r.config.InputFileName, "-r", "25", "-f", "h264", "-") + if r.config.InputFileName == "" { + r.config.Logger.Log(logger.Info, pkg+"using default video device", "device", defaultVideo) + r.config.InputFileName = defaultVideo + } + + args := []string{ + "-i", r.config.InputFileName, + "-f", "h264", + "-r", fmt.Sprint(r.config.FrameRate), + } + switch { + case r.config.FlipHorizontal && r.config.FlipVertical: + args = append(args, "-vf", "hflip,vflip") + case r.config.FlipHorizontal: + args = append(args, "-vf", "hflip") + case r.config.FlipVertical: + args = append(args, "-vf", "vflip") + } + args = append(args, + "-b:v", fmt.Sprint(r.config.Bitrate), + "-maxrate", fmt.Sprint(r.config.Bitrate), + "-bufsize", fmt.Sprint(r.config.Bitrate/2), + "-s", fmt.Sprintf("%dx%d", r.config.Width, r.config.Height), + "-", + ) + + r.config.Logger.Log(logger.Info, pkg+"ffmpeg args", "args", strings.Join(args, " ")) + r.cmd = exec.Command("ffmpeg", args...) delay := time.Second / time.Duration(r.config.FrameRate) stdout, err := r.cmd.StdoutPipe()