thumbnail/video.go

46 lines
630 B
Go
Raw Normal View History

2016-11-18 06:44:27 +00:00
package thumbnail
import (
"bytes"
"io"
2016-11-18 06:44:27 +00:00
"os/exec"
)
func (this *Thumbnailer) RenderScaledFfmpeg(absPath string) ([]byte, error) {
cmd := exec.Command(
"ffmpeg",
"-loglevel", "0",
"-an",
"-i", absPath,
"-vf", "thumbnail,scale=100:100",
"-frames:v", "1",
"-f", "image2pipe",
"-c:v", "png",
"-",
)
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
err = cmd.Start()
if err != nil {
return nil, err
}
out := bytes.Buffer{}
_, err = io.Copy(&out, stdout)
if err != nil {
return nil, err
}
err = cmd.Wait()
if err != nil {
return nil, err
}
return out.Bytes(), nil
2016-11-18 06:44:27 +00:00
}