diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index dda75858..1eaf4cfe 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -109,25 +109,26 @@ func handleFlags() revid.Config { 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") - quantizePtr = flag.Bool("Quantize", false, "Quantize input (non-variable bitrate)") - verbosityPtr = flag.String("Verbosity", "Info", "Verbosity: Info, Warning, Error, Fatal") - framesPerClipPtr = flag.Uint("FramesPerClip", 0, "Number of frames per clip sent") - rtmpUrlPtr = flag.String("RtmpUrl", "", "Url of rtmp endpoint") - bitratePtr = flag.Uint("Bitrate", 0, "Bitrate of recorded video") - outputPathPtr = flag.String("OutputPath", "", "The directory of the output file") - inputFilePtr = flag.String("InputPath", "", "The directory of the input file") - 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") - httpAddressPtr = flag.String("HttpAddress", "", "Destination address of http posts") - 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") rtpAddrPtr = flag.String("RtpAddr", "", "Rtp destination address: : (port is generally 6970-6999)") logPathPtr = flag.String("LogPath", defaultLogPath, "The log path") configFilePtr = flag.String("ConfigFile", "", "NetSender config file") + rtmpUrlPtr = flag.String("RtmpUrl", "", "Url of rtmp endpoint") + outputPathPtr = flag.String("OutputPath", "", "The directory of the output file") + inputFilePtr = flag.String("InputPath", "", "The directory of the input file") + verbosityPtr = flag.String("Verbosity", "Info", "Verbosity: Info, Warning, Error, Fatal") + httpAddressPtr = flag.String("HttpAddress", "", "Destination address of http posts") + quantizePtr = flag.Bool("Quantize", false, "Quantize input (non-variable bitrate)") sendRetryPtr = flag.Bool("retry", false, "Specify whether a failed send should be retried.") + verticalFlipPtr = flag.Bool("VerticalFlip", false, "Flip video vertically: Yes, No") + horizontalFlipPtr = flag.Bool("HorizontalFlip", false, "Flip video horizontally: Yes, No") + framesPerClipPtr = flag.Uint("FramesPerClip", 0, "Number of frames per clip sent") + bitratePtr = flag.Uint("Bitrate", 0, "Bitrate of recorded video") + 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") + quantizationPtr = flag.Uint("Quantization", 0, "Desired quantization value: 0-40") + intraRefreshPeriodPtr = flag.Uint("IntraRefreshPeriod", 0, "The IntraRefreshPeriod i.e. how many keyframes we send") + rotationPtr = flag.Uint("Rotatation", 0, "Rotate video output. (0-359 degrees)") ) var outputs flagStrings @@ -239,6 +240,7 @@ func handleFlags() revid.Config { } cfg.Quantize = *quantizePtr + cfg.Rotation = *rotationPtr cfg.FlipHorizontal = *horizontalFlipPtr cfg.FlipVertical = *verticalFlipPtr cfg.FramesPerClip = *framesPerClipPtr diff --git a/revid/config.go b/revid/config.go index 56292a08..d7e906a2 100644 --- a/revid/config.go +++ b/revid/config.go @@ -69,6 +69,7 @@ type Config struct { Logger Logger SendRetry bool BurstPeriod uint + Rotation uint } // Enums for config struct @@ -116,6 +117,7 @@ const ( defaultVerbosity = No // FIXME(kortschak): This makes no sense whatsoever. No is currently 15. defaultRtpAddr = "localhost:6970" defaultBurstPeriod = 10 // Seconds + defaultRotation = 0 // Degrees ) // Validate checks for any errors in the config fields and defaults settings @@ -215,6 +217,11 @@ func (c *Config) Validate(r *Revid) error { c.FramesPerClip = defaultFramesPerClip } + if c.Rotation > 359 { + c.Logger.Log(logger.Warning, pkg+"bad rotate angle, defaulting", "angle", defaultRotation) + c.Rotation = defaultRotation + } + if c.Width == 0 { c.Logger.Log(logger.Info, pkg+"no width defined, defaulting", "width", defaultWidth) c.Width = defaultWidth diff --git a/revid/revid.go b/revid/revid.go index 33c3d0cc..d2426432 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -433,6 +433,13 @@ func (r *Revid) Update(vars map[string]string) error { break } r.config.FrameRate = uint(v) + case "Rotation": + v, err := strconv.ParseUint(value, 10, 0) + if err != nil || v > 359 { + r.config.Logger.Log(logger.Warning, pkg+"invalid rotation param", "value", value) + break + } + r.config.Rotation = uint(v) case "HttpAddress": r.config.HttpAddress = value case "Quantization": @@ -449,6 +456,7 @@ func (r *Revid) Update(vars map[string]string) error { break } r.config.IntraRefreshPeriod = uint(p) + case "HorizontalFlip": switch strings.ToLower(value) { case "true": @@ -585,13 +593,16 @@ func (r *Revid) startRaspivid() error { "--height", fmt.Sprint(r.config.Height), "--bitrate", fmt.Sprint(r.config.Bitrate), "--framerate", fmt.Sprint(r.config.FrameRate), + "--rotation", fmt.Sprint(r.config.Rotation), + } + + if r.config.FlipVertical { + args = append(args, "--vflip") } if r.config.FlipHorizontal { args = append(args, "--hflip") } - if r.config.FlipVertical { - args = append(args, "--vflip") - } + switch r.config.InputCodec { default: return fmt.Errorf("revid: invalid input codec: %v", r.config.InputCodec) @@ -638,14 +649,7 @@ func (r *Revid) startV4L() error { "-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),