feat: add poster
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user