From d7863863c7b1f4aad21a2127e1bd0e5d3a96e6f8 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 4 Mar 2019 11:53:28 +1030 Subject: [PATCH 1/6] cmd/revid-cli: structuring flags by type, and added a Rotate flag so that video can be rotated using raspivid rotate flag. --- cmd/revid-cli/main.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 625d9356..49bbbffa 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -109,25 +109,24 @@ 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.") + 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") + rotatePtr = flag.Uint("Rotate", 0, "Rotate video output. (0-359 degrees)") ) var outputs flagStrings From 2d229077a2effbba3bd54e93217db25b8105d3a3 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 4 Mar 2019 12:07:28 +1030 Subject: [PATCH 2/6] revid & cmd/revid-cli: removed any mention of horizontal and vertical flip and replaced with rotate --- cmd/revid-cli/main.go | 3 +-- revid/config.go | 12 +++++++----- revid/revid.go | 42 ++++++++++-------------------------------- 3 files changed, 18 insertions(+), 39 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 49bbbffa..3db4e1d7 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -238,8 +238,7 @@ func handleFlags() revid.Config { } cfg.Quantize = *quantizePtr - cfg.FlipHorizontal = *horizontalFlipPtr - cfg.FlipVertical = *verticalFlipPtr + cfg.Rotate = *rotatePtr cfg.FramesPerClip = *framesPerClipPtr cfg.RtmpUrl = *rtmpUrlPtr cfg.Bitrate = *bitratePtr diff --git a/revid/config.go b/revid/config.go index b3d91964..c4465f08 100644 --- a/revid/config.go +++ b/revid/config.go @@ -49,11 +49,6 @@ type Config struct { // bitrate. Quantize bool - // FlipHorizonatla and FlipVertical specify - // whether video frames should be flipped. - FlipHorizontal bool - FlipVertical bool - FramesPerClip uint RtmpUrl string Bitrate uint @@ -69,6 +64,7 @@ type Config struct { Logger Logger SendRetry bool BurstPeriod uint + Rotate uint } // Enums for config struct @@ -116,6 +112,7 @@ const ( defaultVerbosity = No // FIXME(kortschak): This makes no sense whatsoever. No is currently 15. defaultRtpAddr = "localhost:6970" defaultBurstPeriod = 10 // Seconds + defaultRotate = 0 // Degrees ) // Validate checks for any errors in the config fields and defaults settings @@ -215,6 +212,11 @@ func (c *Config) Validate(r *Revid) error { c.FramesPerClip = defaultFramesPerClip } + if c.Rotate > 359 { + c.Logger.Log(logger.Warning, pkg+"bad rotate angle, defaulting", "angle", defaultRotate) + c.Rotate = defaultRotate + } + if c.Width == 0 { c.Logger.Log(logger.Warning, pkg+"no width defined, defaulting", "width", defaultWidth) c.Width = defaultWidth diff --git a/revid/revid.go b/revid/revid.go index f36cbca0..a48570b2 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -457,6 +457,13 @@ func (r *Revid) Update(vars map[string]string) error { break } r.config.FrameRate = uint(v) + case "Rotate": + v, err := strconv.ParseUint(value, 10, 0) + if err != nil || v > 359 { + r.config.Logger.Log(logger.Warning, pkg+"invalid rotate param", "value", value) + break + } + r.config.Rotate = uint(v) case "HttpAddress": r.config.HttpAddress = value case "Quantization": @@ -473,24 +480,6 @@ func (r *Revid) Update(vars map[string]string) error { break } r.config.IntraRefreshPeriod = uint(p) - case "HorizontalFlip": - switch strings.ToLower(value) { - case "true": - r.config.FlipHorizontal = true - case "false": - r.config.FlipHorizontal = false - default: - r.config.Logger.Log(logger.Warning, pkg+"invalid HorizontalFlip param", "value", value) - } - case "VerticalFlip": - switch strings.ToLower(value) { - case "true": - r.config.FlipVertical = true - case "false": - r.config.FlipVertical = false - default: - r.config.Logger.Log(logger.Warning, pkg+"invalid VerticalFlip param", "value", value) - } case "BurstPeriod": v, err := strconv.ParseUint(value, 10, 0) if err != nil { @@ -609,13 +598,9 @@ func (r *Revid) startRaspivid() error { "--height", fmt.Sprint(r.config.Height), "--bitrate", fmt.Sprint(r.config.Bitrate), "--framerate", fmt.Sprint(r.config.FrameRate), + "--rotate", fmt.Sprint(r.config.Rotate), } - 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) @@ -662,14 +647,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), From cfcb899bcbc778bd9f7851670ab2222aa94f7581 Mon Sep 17 00:00:00 2001 From: Saxon Date: Mon, 4 Mar 2019 12:11:34 +1030 Subject: [PATCH 3/6] revid & cmd/revid-cli: rotate => rotation --- cmd/revid-cli/main.go | 4 ++-- revid/config.go | 10 +++++----- revid/revid.go | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 3db4e1d7..0f8119fd 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -126,7 +126,7 @@ func handleFlags() revid.Config { 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") - rotatePtr = flag.Uint("Rotate", 0, "Rotate video output. (0-359 degrees)") + rotationPtr = flag.Uint("Rotatation", 0, "Rotate video output. (0-359 degrees)") ) var outputs flagStrings @@ -238,7 +238,7 @@ func handleFlags() revid.Config { } cfg.Quantize = *quantizePtr - cfg.Rotate = *rotatePtr + cfg.Rotation = *rotationPtr cfg.FramesPerClip = *framesPerClipPtr cfg.RtmpUrl = *rtmpUrlPtr cfg.Bitrate = *bitratePtr diff --git a/revid/config.go b/revid/config.go index c4465f08..b9f46f16 100644 --- a/revid/config.go +++ b/revid/config.go @@ -64,7 +64,7 @@ type Config struct { Logger Logger SendRetry bool BurstPeriod uint - Rotate uint + Rotation uint } // Enums for config struct @@ -112,7 +112,7 @@ const ( defaultVerbosity = No // FIXME(kortschak): This makes no sense whatsoever. No is currently 15. defaultRtpAddr = "localhost:6970" defaultBurstPeriod = 10 // Seconds - defaultRotate = 0 // Degrees + defaultRotation = 0 // Degrees ) // Validate checks for any errors in the config fields and defaults settings @@ -212,9 +212,9 @@ func (c *Config) Validate(r *Revid) error { c.FramesPerClip = defaultFramesPerClip } - if c.Rotate > 359 { - c.Logger.Log(logger.Warning, pkg+"bad rotate angle, defaulting", "angle", defaultRotate) - c.Rotate = defaultRotate + if c.Rotation > 359 { + c.Logger.Log(logger.Warning, pkg+"bad rotate angle, defaulting", "angle", defaultRotation) + c.Rotation = defaultRotation } if c.Width == 0 { diff --git a/revid/revid.go b/revid/revid.go index a48570b2..84d33a3a 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -457,13 +457,13 @@ func (r *Revid) Update(vars map[string]string) error { break } r.config.FrameRate = uint(v) - case "Rotate": + case "Rotatation": v, err := strconv.ParseUint(value, 10, 0) if err != nil || v > 359 { - r.config.Logger.Log(logger.Warning, pkg+"invalid rotate param", "value", value) + r.config.Logger.Log(logger.Warning, pkg+"invalid rotation param", "value", value) break } - r.config.Rotate = uint(v) + r.config.Rotation = uint(v) case "HttpAddress": r.config.HttpAddress = value case "Quantization": @@ -598,7 +598,7 @@ func (r *Revid) startRaspivid() error { "--height", fmt.Sprint(r.config.Height), "--bitrate", fmt.Sprint(r.config.Bitrate), "--framerate", fmt.Sprint(r.config.FrameRate), - "--rotate", fmt.Sprint(r.config.Rotate), + "--rotation", fmt.Sprint(r.config.Rotation), } switch r.config.InputCodec { From 0767f41d4a69c771f65216bbf1a21baf49a32a8b Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Mon, 4 Mar 2019 01:52:39 +0000 Subject: [PATCH 4/6] revid: corrected spelling error in netreceiver var check --- revid/revid.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/revid/revid.go b/revid/revid.go index 84d33a3a..ac3b222f 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -457,7 +457,7 @@ func (r *Revid) Update(vars map[string]string) error { break } r.config.FrameRate = uint(v) - case "Rotatation": + 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) From 3a9e90dcf8ab25470147387e829deb48cccac69a Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 6 Mar 2019 11:51:55 +1030 Subject: [PATCH 5/6] cmd/revid-cli & revid: added back vertical and horizontal flip options --- cmd/revid-cli/main.go | 4 ++++ revid/config.go | 5 +++++ revid/revid.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 0f8119fd..f942fa9d 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -119,6 +119,8 @@ func handleFlags() revid.Config { 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") @@ -239,6 +241,8 @@ func handleFlags() revid.Config { cfg.Quantize = *quantizePtr cfg.Rotation = *rotationPtr + cfg.FlipHorizontal = *horizontalFlipPtr + cfg.FlipVertical = *verticalFlipPtr cfg.FramesPerClip = *framesPerClipPtr cfg.RtmpUrl = *rtmpUrlPtr cfg.Bitrate = *bitratePtr diff --git a/revid/config.go b/revid/config.go index b9f46f16..c2ec9f3c 100644 --- a/revid/config.go +++ b/revid/config.go @@ -49,6 +49,11 @@ type Config struct { // bitrate. Quantize bool + // FlipHorizonatla and FlipVertical specify + // whether video frames should be flipped. + FlipHorizontal bool + FlipVertical bool + FramesPerClip uint RtmpUrl string Bitrate uint diff --git a/revid/revid.go b/revid/revid.go index ac3b222f..e9dc5e42 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -480,6 +480,25 @@ func (r *Revid) Update(vars map[string]string) error { break } r.config.IntraRefreshPeriod = uint(p) + + case "HorizontalFlip": + switch strings.ToLower(value) { + case "true": + r.config.FlipHorizontal = true + case "false": + r.config.FlipHorizontal = false + default: + r.config.Logger.Log(logger.Warning, pkg+"invalid HorizontalFlip param", "value", value) + } + case "VerticalFlip": + switch strings.ToLower(value) { + case "true": + r.config.FlipVertical = true + case "false": + r.config.FlipVertical = false + default: + r.config.Logger.Log(logger.Warning, pkg+"invalid VerticalFlip param", "value", value) + } case "BurstPeriod": v, err := strconv.ParseUint(value, 10, 0) if err != nil { @@ -601,6 +620,15 @@ func (r *Revid) startRaspivid() error { "--rotation", fmt.Sprint(r.config.Rotation), } + 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") + } + switch r.config.InputCodec { default: return fmt.Errorf("revid: invalid input codec: %v", r.config.InputCodec) From a7ae1aa643c44321d007c005bd47c4a04fc3333c Mon Sep 17 00:00:00 2001 From: Saxon Milton Date: Wed, 6 Mar 2019 01:38:13 +0000 Subject: [PATCH 6/6] revid: fixed raspivid flag usage for vertical and horizontal flipping - tested and working --- revid/revid.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index e9dc5e42..64d44817 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -620,13 +620,11 @@ func (r *Revid) startRaspivid() error { "--rotation", fmt.Sprint(r.config.Rotation), } - 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") + if r.config.FlipVertical { + args = append(args, "--vflip") + } + if r.config.FlipHorizontal { + args = append(args, "--hflip") } switch r.config.InputCodec {