diff --git a/backend/fixtures/poster.jpg b/backend/fixtures/poster.jpg new file mode 100644 index 0000000..04726a3 Binary files /dev/null and b/backend/fixtures/poster.jpg differ diff --git a/backend/modules/tasks/discover/discover_medias.go b/backend/modules/tasks/discover/discover_medias.go index 6599502..1318b0f 100644 --- a/backend/modules/tasks/discover/discover_medias.go +++ b/backend/modules/tasks/discover/discover_medias.go @@ -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 +} diff --git a/mp.code-workspace b/mp.code-workspace index 77b8fc7..74b299b 100644 --- a/mp.code-workspace +++ b/mp.code-workspace @@ -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 } }