2018-04-19 10:03:12 +03:00
|
|
|
/*
|
|
|
|
NAME
|
2018-06-27 01:20:05 +03:00
|
|
|
revid-cli - command line interface for Revid.
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
See Readme.md
|
|
|
|
|
|
|
|
AUTHORS
|
2018-06-20 08:08:34 +03:00
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
|
|
|
Jack Richardson <jack@ausocean.org>
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
LICENSE
|
2018-06-27 01:20:05 +03:00
|
|
|
revid-cli is Copyright (C) 2017-2018 the Australian Ocean Lab (AusOcean)
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
2018-06-20 08:08:34 +03:00
|
|
|
for more details.
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2018-06-20 08:08:34 +03:00
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
2018-04-19 10:03:12 +03:00
|
|
|
*/
|
2018-07-05 14:24:10 +03:00
|
|
|
|
2018-04-15 13:42:06 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2018-06-09 03:46:04 +03:00
|
|
|
"os"
|
2018-07-05 14:24:10 +03:00
|
|
|
"runtime/pprof"
|
2018-04-19 09:42:07 +03:00
|
|
|
"strconv"
|
2018-12-10 02:09:20 +03:00
|
|
|
"strings"
|
2018-04-19 11:19:36 +03:00
|
|
|
"time"
|
2018-04-19 08:58:16 +03:00
|
|
|
|
2018-04-19 11:19:36 +03:00
|
|
|
"bitbucket.org/ausocean/av/revid"
|
2018-05-03 06:51:28 +03:00
|
|
|
"bitbucket.org/ausocean/iot/pi/netsender"
|
2019-01-02 08:09:47 +03:00
|
|
|
"bitbucket.org/ausocean/iot/pi/smartlogger"
|
|
|
|
"bitbucket.org/ausocean/utils/logger"
|
2018-04-15 13:42:06 +03:00
|
|
|
)
|
|
|
|
|
2018-06-08 15:44:23 +03:00
|
|
|
const (
|
|
|
|
// progName is the program name for logging purposes.
|
|
|
|
progName = "revid-cli"
|
|
|
|
|
|
|
|
// Logging is set to INFO level.
|
2019-01-02 08:09:47 +03:00
|
|
|
defaultLogVerbosity = logger.Debug
|
2018-06-08 15:44:23 +03:00
|
|
|
)
|
|
|
|
|
2018-04-19 09:42:07 +03:00
|
|
|
// Other misc consts
|
|
|
|
const (
|
2018-06-08 15:22:11 +03:00
|
|
|
netSendRetryTime = 5 * time.Second
|
|
|
|
defaultRunDuration = 24 * time.Hour
|
|
|
|
revidStopTime = 5 * time.Second
|
2018-12-05 11:44:36 +03:00
|
|
|
defaultLogPath = "/var/log/netsender"
|
2018-09-20 04:48:11 +03:00
|
|
|
pkg = "revid-cli:"
|
2018-04-19 09:42:07 +03:00
|
|
|
)
|
|
|
|
|
2018-07-05 14:24:10 +03:00
|
|
|
// canProfile is set to false with revid-cli is built with "-tags profile".
|
|
|
|
var canProfile = true
|
|
|
|
|
2018-09-10 12:19:09 +03:00
|
|
|
// The logger that will be used throughout
|
2019-01-02 08:09:47 +03:00
|
|
|
var log *logger.Logger
|
2018-09-10 12:19:09 +03:00
|
|
|
|
2018-09-12 04:41:48 +03:00
|
|
|
func main() {
|
2018-12-05 12:24:52 +03:00
|
|
|
useNetsender := flag.Bool("NetSender", false, "Are we checking vars through netsender?")
|
|
|
|
runDurationPtr := flag.Duration("runDuration", defaultRunDuration, "How long do you want revid to run for?")
|
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg := handleFlags()
|
2018-09-11 02:25:45 +03:00
|
|
|
|
2018-09-12 04:41:48 +03:00
|
|
|
if !*useNetsender {
|
2019-02-03 13:47:44 +03:00
|
|
|
rv, err := revid.New(cfg, nil)
|
2018-12-09 08:31:47 +03:00
|
|
|
if err != nil {
|
2019-02-03 13:47:44 +03:00
|
|
|
cfg.Logger.Log(logger.Fatal, pkg+"failed to initialiase revid", "error", err.Error())
|
|
|
|
}
|
|
|
|
if err = rv.Start(); err != nil {
|
2019-01-13 14:45:30 +03:00
|
|
|
cfg.Logger.Log(logger.Fatal, pkg+"failed to start revid", "error", err.Error())
|
2018-12-09 08:31:47 +03:00
|
|
|
}
|
2018-09-12 04:41:48 +03:00
|
|
|
time.Sleep(*runDurationPtr)
|
2019-02-03 13:47:44 +03:00
|
|
|
if err = rv.Stop(); err != nil {
|
2019-01-13 14:45:30 +03:00
|
|
|
cfg.Logger.Log(logger.Error, pkg+"failed to stop revid before program termination", "error", err.Error())
|
|
|
|
}
|
2018-09-12 04:41:48 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-03 13:47:44 +03:00
|
|
|
if err := run(cfg); err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Fatal, pkg+"failed to run revid", "error", err.Error())
|
2018-09-11 02:25:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
// handleFlags parses command line flags and returns a revid configuration
|
|
|
|
// based on them.
|
|
|
|
func handleFlags() revid.Config {
|
|
|
|
var cfg revid.Config
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
var (
|
|
|
|
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
|
|
|
|
|
2018-12-28 03:14:53 +03:00
|
|
|
inputPtr = flag.String("Input", "", "The input type: Raspivid, File, Webcam")
|
2018-12-05 12:24:52 +03:00
|
|
|
inputCodecPtr = flag.String("InputCodec", "", "The codec of the input: H264, Mjpeg")
|
|
|
|
rtmpMethodPtr = flag.String("RtmpMethod", "", "The method used to send over rtmp: Ffmpeg, Librtmp")
|
|
|
|
packetizationPtr = flag.String("Packetization", "", "The method of data packetisation: Flv, Mpegts, None")
|
2018-12-10 02:09:20 +03:00
|
|
|
quantizePtr = flag.Bool("Quantize", false, "Quantize input (non-variable bitrate)")
|
2018-12-05 12:24:52 +03:00
|
|
|
verbosityPtr = flag.String("Verbosity", "", "Verbosity: Info, Warning, Error, Fatal")
|
2018-12-10 02:09:20 +03:00
|
|
|
framesPerClipPtr = flag.Uint("FramesPerClip", 0, "Number of frames per clip sent")
|
2018-12-05 12:24:52 +03:00
|
|
|
rtmpUrlPtr = flag.String("RtmpUrl", "", "Url of rtmp endpoint")
|
2018-12-10 02:09:20 +03:00
|
|
|
bitratePtr = flag.Uint("Bitrate", 0, "Bitrate of recorded video")
|
2018-12-05 12:24:52 +03:00
|
|
|
outputFileNamePtr = flag.String("OutputFileName", "", "The directory of the output file")
|
|
|
|
inputFileNamePtr = flag.String("InputFileName", "", "The directory of the input file")
|
2018-12-10 02:09:20 +03:00
|
|
|
heightPtr = flag.Uint("Height", 0, "Height in pixels")
|
|
|
|
widthPtr = flag.Uint("Width", 0, "Width in pixels")
|
|
|
|
frameRatePtr = flag.Uint("FrameRate", 0, "Frame rate of captured video")
|
2018-12-05 12:24:52 +03:00
|
|
|
httpAddressPtr = flag.String("HttpAddress", "", "Destination address of http posts")
|
2018-12-10 02:09:20 +03:00
|
|
|
quantizationPtr = flag.Uint("Quantization", 0, "Desired quantization value: 0-40")
|
|
|
|
intraRefreshPeriodPtr = flag.Uint("IntraRefreshPeriod", 0, "The IntraRefreshPeriod i.e. how many keyframes we send")
|
|
|
|
verticalFlipPtr = flag.Bool("VerticalFlip", false, "Flip video vertically: Yes, No")
|
|
|
|
horizontalFlipPtr = flag.Bool("HorizontalFlip", false, "Flip video horizontally: Yes, No")
|
2018-12-05 12:24:52 +03:00
|
|
|
rtpAddrPtr = flag.String("RtpAddr", "", "Rtp destination address: <IP>:<port> (port is generally 6970-6999)")
|
2019-01-05 01:18:47 +03:00
|
|
|
logPathPtr = flag.String("LogPath", defaultLogPath, "The log path")
|
|
|
|
configFilePtr = flag.String("ConfigFile", "", "NetSender config file")
|
2018-12-05 12:24:52 +03:00
|
|
|
)
|
2018-09-11 02:25:45 +03:00
|
|
|
|
2019-01-19 12:09:43 +03:00
|
|
|
var outputs flagStrings
|
|
|
|
flag.Var(&outputs, "Output", "output type: Http, Rtmp, File, Udp, Rtp (may be used more than once)")
|
|
|
|
|
2018-09-12 04:30:04 +03:00
|
|
|
flag.Parse()
|
|
|
|
|
2019-01-05 01:18:47 +03:00
|
|
|
log = logger.New(defaultLogVerbosity, &smartlogger.New(*logPathPtr).LogRoller)
|
2018-09-11 02:25:45 +03:00
|
|
|
|
2019-01-02 08:09:47 +03:00
|
|
|
cfg.Logger = log
|
2018-09-12 04:27:56 +03:00
|
|
|
|
2018-07-05 14:24:10 +03:00
|
|
|
if *cpuprofile != "" {
|
|
|
|
if canProfile {
|
|
|
|
f, err := os.Create(*cpuprofile)
|
|
|
|
if err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Fatal, pkg+"could not create CPU profile", "error", err.Error())
|
2018-07-05 14:24:10 +03:00
|
|
|
}
|
|
|
|
if err := pprof.StartCPUProfile(f); err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Fatal, pkg+"could not start CPU profile", "error", err.Error())
|
2018-07-05 14:24:10 +03:00
|
|
|
}
|
|
|
|
defer pprof.StopCPUProfile()
|
|
|
|
} else {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"ignoring cpuprofile flag - http/pprof built in.")
|
2018-07-05 14:24:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *inputPtr {
|
2018-04-15 13:42:06 +03:00
|
|
|
case "Raspivid":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Input = revid.Raspivid
|
2019-01-17 08:34:04 +03:00
|
|
|
case "v4l":
|
|
|
|
cfg.Input = revid.V4L
|
2018-04-15 13:42:06 +03:00
|
|
|
case "File":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Input = revid.File
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Error, pkg+"bad input argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *inputCodecPtr {
|
2018-11-18 10:43:38 +03:00
|
|
|
case "H264":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.InputCodec = revid.H264
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Error, pkg+"bad input codec argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2019-01-19 12:09:43 +03:00
|
|
|
for _, o := range outputs {
|
|
|
|
switch o {
|
|
|
|
case "File":
|
|
|
|
cfg.Outputs = append(cfg.Outputs, revid.File)
|
|
|
|
case "Http":
|
|
|
|
cfg.Outputs = append(cfg.Outputs, revid.Http)
|
|
|
|
case "Rtmp":
|
|
|
|
cfg.Outputs = append(cfg.Outputs, revid.Rtmp)
|
|
|
|
case "FfmpegRtmp":
|
|
|
|
cfg.Outputs = append(cfg.Outputs, revid.FfmpegRtmp)
|
|
|
|
case "Udp":
|
|
|
|
cfg.Outputs = append(cfg.Outputs, revid.Udp)
|
|
|
|
case "Rtp":
|
|
|
|
cfg.Outputs = append(cfg.Outputs, revid.Rtp)
|
|
|
|
case "":
|
|
|
|
default:
|
|
|
|
log.Log(logger.Error, pkg+"bad output argument", "arg", o)
|
|
|
|
}
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *rtmpMethodPtr {
|
2018-04-15 13:42:06 +03:00
|
|
|
case "Ffmpeg":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.RtmpMethod = revid.Ffmpeg
|
2018-04-15 13:42:06 +03:00
|
|
|
case "LibRtmp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.RtmpMethod = revid.LibRtmp
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Error, pkg+"bad rtmp method argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *packetizationPtr {
|
2019-01-05 03:03:32 +03:00
|
|
|
case "", "None":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Packetization = revid.None
|
2018-06-30 15:20:55 +03:00
|
|
|
case "Mpegts":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Packetization = revid.Mpegts
|
2018-04-15 13:42:06 +03:00
|
|
|
case "Flv":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Packetization = revid.Flv
|
2018-04-19 12:37:25 +03:00
|
|
|
default:
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Error, pkg+"bad packetization argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *verbosityPtr {
|
2018-04-15 13:42:06 +03:00
|
|
|
case "No":
|
2019-01-02 08:09:47 +03:00
|
|
|
cfg.LogLevel = logger.Fatal
|
2018-12-14 06:05:56 +03:00
|
|
|
case "Debug":
|
2019-01-02 08:09:47 +03:00
|
|
|
cfg.LogLevel = logger.Debug
|
|
|
|
//logger.SetLevel(logger.Debug)
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Error, pkg+"bad verbosity argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2019-01-05 01:18:47 +03:00
|
|
|
if *configFilePtr != "" {
|
|
|
|
netsender.ConfigFile = *configFilePtr
|
|
|
|
}
|
|
|
|
|
2018-12-10 02:09:20 +03:00
|
|
|
cfg.Quantize = *quantizePtr
|
|
|
|
cfg.FlipHorizontal = *horizontalFlipPtr
|
|
|
|
cfg.FlipVertical = *verticalFlipPtr
|
|
|
|
cfg.FramesPerClip = *framesPerClipPtr
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.RtmpUrl = *rtmpUrlPtr
|
|
|
|
cfg.Bitrate = *bitratePtr
|
|
|
|
cfg.OutputFileName = *outputFileNamePtr
|
|
|
|
cfg.InputFileName = *inputFileNamePtr
|
|
|
|
cfg.Height = *heightPtr
|
|
|
|
cfg.Width = *widthPtr
|
|
|
|
cfg.FrameRate = *frameRatePtr
|
|
|
|
cfg.HttpAddress = *httpAddressPtr
|
|
|
|
cfg.Quantization = *quantizationPtr
|
|
|
|
cfg.IntraRefreshPeriod = *intraRefreshPeriodPtr
|
|
|
|
cfg.RtpAddress = *rtpAddrPtr
|
|
|
|
|
|
|
|
return cfg
|
2018-09-12 04:41:48 +03:00
|
|
|
}
|
2018-04-19 09:42:07 +03:00
|
|
|
|
2018-09-12 04:41:48 +03:00
|
|
|
// initialize then run the main NetSender client
|
2019-02-03 13:47:44 +03:00
|
|
|
func run(cfg revid.Config) error {
|
2018-09-12 04:41:48 +03:00
|
|
|
// initialize NetSender and use NetSender's logger
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Info, pkg+"running in NetSender mode")
|
2018-09-12 04:41:48 +03:00
|
|
|
|
|
|
|
var ns netsender.Sender
|
2019-02-03 13:47:44 +03:00
|
|
|
if err := ns.Init(log, nil, nil, nil); err != nil {
|
2018-09-12 04:41:48 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
vars, _ := ns.Vars()
|
|
|
|
vs := ns.VarSum()
|
2019-02-03 13:47:44 +03:00
|
|
|
|
|
|
|
rv, cfg, err = updateRevid(&ns, rv, cfg, vars, false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-09-12 04:41:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
2018-12-09 08:31:47 +03:00
|
|
|
if err := send(&ns, rv); err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Error, pkg+"polling failed", "error", err.Error())
|
2018-09-12 04:41:48 +03:00
|
|
|
time.Sleep(netSendRetryTime)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if vs != ns.VarSum() {
|
|
|
|
// vars changed
|
|
|
|
vars, err := ns.Vars()
|
|
|
|
if err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Error, pkg+"netSender failed to get vars", "error", err.Error())
|
2018-09-12 04:41:48 +03:00
|
|
|
time.Sleep(netSendRetryTime)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
vs = ns.VarSum()
|
|
|
|
if vars["mode"] == "Paused" {
|
|
|
|
if !paused {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Info, pkg+"pausing revid")
|
2019-01-13 14:45:30 +03:00
|
|
|
err = stopRevid(rv)
|
|
|
|
if err != nil {
|
|
|
|
log.Log(logger.Error, pkg+"failed to stop revide", "error", err.Error())
|
|
|
|
continue
|
|
|
|
}
|
2018-09-12 04:41:48 +03:00
|
|
|
paused = true
|
|
|
|
}
|
|
|
|
} else {
|
2018-12-09 08:31:47 +03:00
|
|
|
rv, cfg, err = updateRevid(&ns, rv, cfg, vars, !paused)
|
2018-09-12 04:41:48 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if paused {
|
|
|
|
paused = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sleepTime, _ := strconv.Atoi(ns.Param("mp"))
|
|
|
|
time.Sleep(time.Duration(sleepTime) * time.Second)
|
2018-04-20 05:20:33 +03:00
|
|
|
}
|
2018-04-19 08:58:16 +03:00
|
|
|
}
|
|
|
|
|
2018-06-26 09:23:55 +03:00
|
|
|
// send implements our main NetSender client and handles NetReceiver configuration
|
2018-06-15 10:59:59 +03:00
|
|
|
// (as distinct from httpSender which just sends video data).
|
2018-12-09 08:31:47 +03:00
|
|
|
func send(ns *netsender.Sender, rv *revid.Revid) error {
|
2018-06-14 10:07:57 +03:00
|
|
|
// populate input values, if any
|
2018-06-25 03:40:37 +03:00
|
|
|
inputs := netsender.MakePins(ns.Param("ip"), "X")
|
2018-06-28 09:43:06 +03:00
|
|
|
if rv != nil {
|
|
|
|
for i, pin := range inputs {
|
|
|
|
if pin.Name == "X23" {
|
|
|
|
inputs[i].Value = rv.Bitrate()
|
|
|
|
}
|
2018-06-14 10:07:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-16 12:34:32 +03:00
|
|
|
_, reconfig, err := ns.Send(netsender.RequestPoll, inputs)
|
2018-06-08 15:45:14 +03:00
|
|
|
if err != nil {
|
2018-06-01 14:20:56 +03:00
|
|
|
return err
|
2018-06-08 15:45:14 +03:00
|
|
|
}
|
|
|
|
if reconfig {
|
|
|
|
return ns.Config()
|
2018-04-19 09:42:07 +03:00
|
|
|
}
|
2018-06-01 14:20:56 +03:00
|
|
|
return nil
|
2018-05-07 04:16:44 +03:00
|
|
|
}
|
|
|
|
|
2018-12-09 08:31:47 +03:00
|
|
|
func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars map[string]string, stop bool) (*revid.Revid, revid.Config, error) {
|
2018-05-07 04:16:44 +03:00
|
|
|
if stop {
|
2019-01-13 14:34:50 +03:00
|
|
|
err := stopRevid(rv)
|
|
|
|
if err != nil {
|
|
|
|
return nil, cfg, err
|
|
|
|
}
|
2018-05-07 04:16:44 +03:00
|
|
|
}
|
2018-04-20 11:23:59 +03:00
|
|
|
|
2018-06-01 14:20:56 +03:00
|
|
|
//look through the vars and update revid where needed
|
2018-04-19 08:58:16 +03:00
|
|
|
for key, value := range vars {
|
|
|
|
switch key {
|
2018-06-25 04:39:56 +03:00
|
|
|
case "Output":
|
2019-01-19 12:09:43 +03:00
|
|
|
// FIXME(kortschak): There can be only one!
|
|
|
|
// How do we specify outputs after the first?
|
|
|
|
//
|
|
|
|
// Maybe we shouldn't be doing this!
|
2018-06-25 04:39:56 +03:00
|
|
|
switch value {
|
|
|
|
case "File":
|
2019-01-19 12:09:43 +03:00
|
|
|
cfg.Outputs[0] = revid.File
|
2018-06-25 04:39:56 +03:00
|
|
|
case "Http":
|
2019-01-19 12:09:43 +03:00
|
|
|
cfg.Outputs[0] = revid.Http
|
2018-06-25 04:39:56 +03:00
|
|
|
case "Rtmp":
|
2019-01-19 12:09:43 +03:00
|
|
|
cfg.Outputs[0] = revid.Rtmp
|
2018-06-25 04:39:56 +03:00
|
|
|
case "FfmpegRtmp":
|
2019-01-19 12:09:43 +03:00
|
|
|
cfg.Outputs[0] = revid.FfmpegRtmp
|
2018-06-25 04:39:56 +03:00
|
|
|
default:
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"invalid Output1 param", "value", value)
|
2018-06-25 04:39:56 +03:00
|
|
|
continue
|
|
|
|
}
|
2018-05-06 11:38:45 +03:00
|
|
|
case "FramesPerClip":
|
2018-12-10 02:09:20 +03:00
|
|
|
f, err := strconv.ParseUint(value, 10, 0)
|
|
|
|
if err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"invalid framesperclip param", "value", value)
|
2018-12-10 02:09:20 +03:00
|
|
|
break
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
2018-12-10 02:09:20 +03:00
|
|
|
cfg.FramesPerClip = uint(f)
|
2018-05-06 11:38:45 +03:00
|
|
|
case "RtmpUrl":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.RtmpUrl = value
|
2018-05-06 11:38:45 +03:00
|
|
|
case "Bitrate":
|
2018-12-10 02:09:20 +03:00
|
|
|
r, err := strconv.ParseUint(value, 10, 0)
|
|
|
|
if err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"invalid framerate param", "value", value)
|
2018-12-10 02:09:20 +03:00
|
|
|
break
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
2018-12-10 02:09:20 +03:00
|
|
|
cfg.Bitrate = uint(r)
|
2018-05-06 11:38:45 +03:00
|
|
|
case "OutputFileName":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.OutputFileName = value
|
2018-05-06 11:38:45 +03:00
|
|
|
case "InputFileName":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.InputFileName = value
|
2018-05-06 11:38:45 +03:00
|
|
|
case "Height":
|
2018-12-10 02:09:20 +03:00
|
|
|
h, err := strconv.ParseUint(value, 10, 0)
|
|
|
|
if err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"invalid height param", "value", value)
|
2018-12-10 02:09:20 +03:00
|
|
|
break
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
2018-12-10 02:09:20 +03:00
|
|
|
cfg.Height = uint(h)
|
2018-05-06 11:38:45 +03:00
|
|
|
case "Width":
|
2018-12-10 02:09:20 +03:00
|
|
|
w, err := strconv.ParseUint(value, 10, 0)
|
|
|
|
if err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"invalid width param", "value", value)
|
2018-12-10 02:09:20 +03:00
|
|
|
break
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
2018-12-10 02:09:20 +03:00
|
|
|
cfg.Width = uint(w)
|
2018-05-06 11:38:45 +03:00
|
|
|
case "FrameRate":
|
2018-12-10 02:09:20 +03:00
|
|
|
r, err := strconv.ParseUint(value, 10, 0)
|
|
|
|
if err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"invalid framerate param", "value", value)
|
2018-12-10 02:09:20 +03:00
|
|
|
break
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
2018-12-10 02:09:20 +03:00
|
|
|
cfg.FrameRate = uint(r)
|
2018-05-06 11:38:45 +03:00
|
|
|
case "HttpAddress":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.HttpAddress = value
|
2018-05-06 11:38:45 +03:00
|
|
|
case "Quantization":
|
2018-12-10 02:09:20 +03:00
|
|
|
q, err := strconv.ParseUint(value, 10, 0)
|
|
|
|
if err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"invalid quantization param", "value", value)
|
2018-12-10 02:09:20 +03:00
|
|
|
break
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
2018-12-10 02:09:20 +03:00
|
|
|
cfg.Quantization = uint(q)
|
2018-05-06 11:38:45 +03:00
|
|
|
case "IntraRefreshPeriod":
|
2018-12-10 02:09:20 +03:00
|
|
|
p, err := strconv.ParseUint(value, 10, 0)
|
|
|
|
if err != nil {
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"invalid intrarefreshperiod param", "value", value)
|
2018-12-10 02:09:20 +03:00
|
|
|
break
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
2018-12-10 02:09:20 +03:00
|
|
|
cfg.IntraRefreshPeriod = uint(p)
|
2018-05-06 11:38:45 +03:00
|
|
|
case "HorizontalFlip":
|
2018-12-10 02:09:20 +03:00
|
|
|
switch strings.ToLower(value) {
|
|
|
|
case "true":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipHorizontal = true
|
2018-12-10 02:09:20 +03:00
|
|
|
case "false":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipHorizontal = false
|
2018-06-25 04:39:56 +03:00
|
|
|
default:
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"invalid HorizontalFlip param", "value", value)
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
|
|
|
case "VerticalFlip":
|
2018-12-10 02:09:20 +03:00
|
|
|
switch strings.ToLower(value) {
|
|
|
|
case "true":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipVertical = true
|
2018-12-10 02:09:20 +03:00
|
|
|
case "false":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipVertical = false
|
2018-06-25 04:39:56 +03:00
|
|
|
default:
|
2019-01-02 08:09:47 +03:00
|
|
|
log.Log(logger.Warning, pkg+"invalid VerticalFlip param", "value", value)
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
2018-06-25 04:39:56 +03:00
|
|
|
default:
|
2018-04-19 08:58:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
return startRevid(ns, cfg)
|
2018-04-19 08:58:16 +03:00
|
|
|
}
|
2019-01-19 12:09:43 +03:00
|
|
|
|
|
|
|
// flagStrings implements an appending string set flag.
|
|
|
|
type flagStrings []string
|
|
|
|
|
|
|
|
func (v *flagStrings) String() string {
|
|
|
|
if *v != nil {
|
|
|
|
return strings.Join(*v, ",")
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *flagStrings) Set(s string) error {
|
|
|
|
if s == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
for _, e := range *v {
|
|
|
|
if e == s {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*v = append(*v, s)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *flagStrings) Get() interface{} { return *v }
|