2016-11-18 06:44:27 +00:00
|
|
|
package thumbnail
|
|
|
|
|
|
|
|
import (
|
2016-11-18 07:02:22 +00:00
|
|
|
"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",
|
|
|
|
"-",
|
|
|
|
)
|
|
|
|
|
2016-11-18 07:02:22 +00:00
|
|
|
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
|
|
|
}
|