31 lines
604 B
Go
31 lines
604 B
Go
package util
|
|
|
|
import (
|
|
"butterfliu/config"
|
|
"os"
|
|
"os/exec"
|
|
"path"
|
|
"strconv"
|
|
)
|
|
|
|
func ExtractCover(filePath string, id int) (string, error) {
|
|
config := config.LoadConfig()
|
|
coverPath := path.Join(config.GetCachePath("cover"), strconv.Itoa(id)+".jpg")
|
|
|
|
_, err := os.Stat(coverPath)
|
|
if err == nil {
|
|
return coverPath, nil
|
|
}
|
|
|
|
if _, err := exec.LookPath("ffmpeg"); err != nil {
|
|
return "", err
|
|
}
|
|
cmd := exec.Command("ffmpeg", "-i", filePath, "-an", "-vcodec", "mjpeg", "-q:v", "5", "-f", "image2", "-y", coverPath)
|
|
if err := cmd.Run(); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return coverPath, nil
|
|
|
|
}
|