Files
butterfliu/internal/util/ffmpeg.go
lzw-723 169b2c1858
All checks were successful
Go CI / test-and-build (push) Successful in 2m3s
实现封面缓存
2026-04-08 20:56:18 +08:00

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
}