From b5fe725836701ffb1e513d293742701dafa6c725 Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 5 Dec 2016 19:01:00 +1300 Subject: [PATCH] video: add extra ffmpeg magic for aspect-scaling --- video.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/video.go b/video.go index 8ed2fc3..d479208 100644 --- a/video.go +++ b/video.go @@ -2,18 +2,25 @@ package thumbnail import ( "bytes" + "fmt" "io" "os/exec" ) func (this *Thumbnailer) RenderScaledFfmpeg(absPath string) ([]byte, error) { + scaleCmd := fmt.Sprintf( + `thumbnail,scale='if(gt(a,%d/%d),%d,-1)':'if(gt(a,%d/%d),-1,%d)'`, + this.Height, this.Width, this.Height, + this.Height, this.Width, this.Width, + ) + cmd := exec.Command( "ffmpeg", "-loglevel", "0", "-an", "-i", absPath, - "-vf", "thumbnail,scale=100:100", + "-vf", scaleCmd, "-frames:v", "1", "-f", "image2pipe", "-c:v", "png",