From 28861fb6e87db802eff0d7f159cad6b440b18f93 Mon Sep 17 00:00:00 2001 From: Matthias Hochgatterer Date: Thu, 11 Apr 2019 18:14:19 +0200 Subject: [PATCH] Keep aspect ratio in video and snapshot --- ffmpeg/snapshot.go | 3 ++- ffmpeg/stream.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ffmpeg/snapshot.go b/ffmpeg/snapshot.go index 7cca08c..df3e4fe 100644 --- a/ffmpeg/snapshot.go +++ b/ffmpeg/snapshot.go @@ -16,7 +16,8 @@ func snapshot(width, height uint, inputDevice, inputFilename string) (*image.Ima fileName := fmt.Sprintf("snapshot_%s.jpeg", time.Now().Format(time.RFC3339)) filePath := path.Join(os.TempDir(), fileName) - arg := fmt.Sprintf("-f %s -framerate 30 -i %s -s %dx%d -frames:v 1 %s", inputDevice, inputFilename, width, height, filePath) + // height "-2" keeps the aspect ratio + arg := fmt.Sprintf("-f %s -framerate 30 -i %s -vf scale=%d:-2 -frames:v 1 %s", inputDevice, inputFilename, width, filePath) args := strings.Split(arg, " ") cmd := exec.Command("ffmpeg", args[:]...) diff --git a/ffmpeg/stream.go b/ffmpeg/stream.go index 46b53af..4a6c210 100644 --- a/ffmpeg/stream.go +++ b/ffmpeg/stream.go @@ -47,7 +47,8 @@ func (s *stream) start(video rtp.VideoParameters, audio rtp.AudioParameters) err " -an" + fmt.Sprintf(" -codec:v %s", s.videoEncoder(video)) + " -pix_fmt yuv420p -vsync 2" + - fmt.Sprintf(" -video_size %dx%d", video.Attributes.Width, video.Attributes.Height) + + // height "-2" keeps the aspect ratio + fmt.Sprintf(" -video_size %d:-2", video.Attributes.Width) + fmt.Sprintf(" -framerate %d", video.Attributes.Framerate) + // 2018-08-18 (mah) Disable profile arguments because it cannot be parsed // [h264_omx @ 0x93a410] [Eval @ 0xbeaad160] Undefined constant or missing '(' in 'high'