2022-06-23 09:06:07 +00:00
|
|
|
package local
|
2022-11-09 03:20:09 +00:00
|
|
|
|
|
|
|
import (
|
2023-02-22 13:19:42 +00:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
ffmpeg "github.com/u2takey/ffmpeg-go"
|
2022-11-09 03:20:09 +00:00
|
|
|
"io/fs"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
func isSymlinkDir(f fs.FileInfo, path string) bool {
|
|
|
|
if f.Mode()&os.ModeSymlink == os.ModeSymlink {
|
|
|
|
dst, err := os.Readlink(filepath.Join(path, f.Name()))
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2022-11-09 10:15:42 +00:00
|
|
|
if !filepath.IsAbs(dst) {
|
|
|
|
dst = filepath.Join(path, dst)
|
|
|
|
}
|
2022-11-09 03:20:09 +00:00
|
|
|
stat, err := os.Stat(dst)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return stat.IsDir()
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2023-02-22 13:19:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|