diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index ea031a42..59b31be6 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -202,6 +202,8 @@ func handleFlags() config.Config { cfg.InputCodec = codecutil.PCM case "ADPCM": cfg.InputCodec = codecutil.ADPCM + case "MJPEG": + cfg.InputCodec = codecutil.MJPEG default: log.Log(logger.Error, pkg+"bad input codec argument") } diff --git a/device/webcam/webcam.go b/device/webcam/webcam.go index 256a3900..0ac08751 100644 --- a/device/webcam/webcam.go +++ b/device/webcam/webcam.go @@ -31,6 +31,7 @@ import ( "os/exec" "strings" + "bitbucket.org/ausocean/av/codec/codecutil" "bitbucket.org/ausocean/av/device" "bitbucket.org/ausocean/av/revid/config" "bitbucket.org/ausocean/utils/logger" @@ -113,18 +114,31 @@ func (w *Webcam) Set(c config.Config) error { // Start will build the required arguments for ffmpeg and then execute the // command, piping video output where we can read using the Read method. func (w *Webcam) Start() error { + br := w.cfg.Bitrate * 1000 + args := []string{ "-i", w.cfg.InputPath, - "-f", "h264", "-r", fmt.Sprint(w.cfg.FrameRate), + "-b:v", fmt.Sprint(br), + "-s", fmt.Sprintf("%dx%d", w.cfg.Width, w.cfg.Height), + } + + switch w.cfg.InputCodec { + default: + return fmt.Errorf("revid: invalid input codec: %v", w.cfg.InputCodec) + case codecutil.H264: + args = append(args, + "-f", "h264", + "-maxrate", fmt.Sprint(br), + "-bufsize", fmt.Sprint(br/2), + ) + case codecutil.MJPEG: + args = append(args, + "-f", "mjpeg", + ) } - br := w.cfg.Bitrate * 1000 args = append(args, - "-b:v", fmt.Sprint(br), - "-maxrate", fmt.Sprint(br), - "-bufsize", fmt.Sprint(br/2), - "-s", fmt.Sprintf("%dx%d", w.cfg.Width, w.cfg.Height), "-", ) diff --git a/revid/revid.go b/revid/revid.go index 786b75f5..d0bc73f3 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -191,7 +191,15 @@ func (r *Revid) reset(c config.Config) error { panic("unknown input codec for raspivid input") } case config.InputFile, config.InputV4L: - st = mts.EncodeH264 + switch r.cfg.InputCodec { + case codecutil.H264: + st = mts.EncodeH264 + case codecutil.MJPEG: + st = mts.EncodeMJPEG + encOptions = append(encOptions, mts.PacketBasedPSI(int(r.cfg.MinFrames))) + default: + panic("unknown input codec for v4l or input file input") + } case config.InputRTSP: switch r.cfg.InputCodec { case codecutil.H265: @@ -329,7 +337,12 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. case config.InputV4L: r.input = webcam.New(r.cfg.Logger) - r.lexTo = h264.Lex + switch r.cfg.InputCodec { + case codecutil.H264: + r.lexTo = h264.Lex + case codecutil.MJPEG: + r.lexTo = mjpeg.Lex + } case config.InputFile: r.input = file.New()