Skip to content

Commit

Permalink
Keep aspect ratio in video and snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
brutella committed Apr 11, 2019
1 parent acfcc4b commit 28861fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ffmpeg/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:]...)
Expand Down
3 changes: 2 additions & 1 deletion ffmpeg/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 28861fb

Please sign in to comment.