video: add extra ffmpeg magic for aspect-scaling

This commit is contained in:
mappu 2016-12-05 19:01:00 +13:00
parent 08f0c94131
commit b5fe725836
1 changed files with 8 additions and 1 deletions

View File

@ -2,18 +2,25 @@ package thumbnail
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"os/exec" "os/exec"
) )
func (this *Thumbnailer) RenderScaledFfmpeg(absPath string) ([]byte, error) { 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( cmd := exec.Command(
"ffmpeg", "ffmpeg",
"-loglevel", "0", "-loglevel", "0",
"-an", "-an",
"-i", absPath, "-i", absPath,
"-vf", "thumbnail,scale=100:100", "-vf", scaleCmd,
"-frames:v", "1", "-frames:v", "1",
"-f", "image2pipe", "-f", "image2pipe",
"-c:v", "png", "-c:v", "png",