feat(local): add thumbnail for video with ffmpeg (#3556)

* feat(local): add ffmpeg

* fix: missed `+`

---------

Co-authored-by: Andy Hsu <i@nn.ci>
This commit is contained in:
GodFinal
2023-02-22 21:19:42 +08:00
committed by GitHub
parent c08fdfc868
commit 309d6558fb
4 changed files with 70 additions and 9 deletions

View File

@ -1,6 +1,9 @@
package local
import (
"bytes"
"fmt"
ffmpeg "github.com/u2takey/ffmpeg-go"
"io/fs"
"os"
"path/filepath"
@ -23,3 +26,16 @@ func isSymlinkDir(f fs.FileInfo, path string) bool {
}
return false
}
func GetSnapshot(videoPath string, frameNum int) (imgData *bytes.Buffer, err error) {
srcBuf := bytes.NewBuffer(nil)
err = ffmpeg.Input(videoPath).Filter("select", ffmpeg.Args{fmt.Sprintf("gte(n,%d)", frameNum)}).
Output("pipe:", ffmpeg.KwArgs{"vframes": 1, "format": "image2", "vcodec": "mjpeg"}).
WithOutput(srcBuf, os.Stdout).
Run()
if err != nil {
return nil, err
}
return srcBuf, nil
}