feat: add poster

This commit is contained in:
Rogee
2024-12-05 17:05:39 +08:00
parent e3085f87fc
commit e11924ea8a
3 changed files with 30 additions and 4 deletions

BIN
backend/fixtures/poster.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -1,6 +1,7 @@
package discover
import (
"fmt"
"os"
"os/exec"
"path/filepath"
@@ -66,6 +67,12 @@ func (d *DiscoverMedias) RunE(from, to string) error {
if err := d.ffmpegVideoToM3U8(video, to); err != nil {
return errors.Wrapf(err, "ffmpeg video to m3u8: %s", video)
}
d.log.Infof("snapshot", video)
posterPath := filepath.Join(to, "poster.jpg")
if err := d.ffmpegVideoToPoster(video, posterPath, 5); err != nil {
return errors.Wrapf(err, "ffmpeg snapshot : %s", video)
}
}
audios := d.globAudio(dirPath)
@@ -213,3 +220,24 @@ func (d *DiscoverMedias) runCleanup(to string) {
}
}
}
// getSnapshot get the snapshot of target seconds of a video
func (d *DiscoverMedias) ffmpegVideoToPoster(video string, output string, seconds int) error {
// ffmpeg -i input_video.mp4 -ss N -vframes 1 -vf "scale=width:height" output_image.jpg
args := []string{
"-i", video,
"-ss", fmt.Sprintf("00:%02d:00", seconds),
"-vframes", "1",
"-vf", "scale=640:360",
output,
}
d.log.Infof("cmd: ffmpeg %s", strings.Join(args, " "))
logs, err := exec.Command("ffmpeg", args...).CombinedOutput()
if err != nil {
return errors.Wrapf(err, "get snapshot: %s", video)
}
d.log.Infof("get snapshot: %s", logs)
return nil
}

View File

@@ -5,15 +5,13 @@
},
{
"path": "backend"
},
{
"path": "arco"
}
],
"settings": {
"vue3snippets.enable-compile-vue-file-on-did-save-code": true,
"cSpell.words": [
"qvyun"
]
],
"git.ignoreLimitWarning": true
}
}