From c5159c3eab3495a36332c8f22d9ca5b4e6d70cde Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sun, 9 Jul 2023 08:25:39 +0800 Subject: [PATCH] update --- server/movie.go | 76 ++++++++++++++++++++++++------------ src/Main.jsx | 6 ++- src/components/MovieCard.jsx | 21 ++++++++-- 3 files changed, 74 insertions(+), 29 deletions(-) diff --git a/server/movie.go b/server/movie.go index 6d5a2ad..b24808f 100644 --- a/server/movie.go +++ b/server/movie.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "fmt" "io/fs" "log" "os/exec" @@ -27,9 +28,11 @@ type Movie struct { // var movies []Movie var categories []Category +var IsRemakePNG = false + func initMovie() { // 需要改进 如果存在这个文件的略缩图, 就不存进movieDict里 - var movieDict map[string]string = make(map[string]string) + var movieDict map[string]*Movie = make(map[string]*Movie) matches, err := filepath.Glob("movie/*") if err != nil { @@ -43,30 +46,11 @@ func initMovie() { base = base[:strings.IndexByte(base, '.')] if _, ok := movieDict[base]; ok { - delete(movieDict, base) + if !IsRemakePNG { + delete(movieDict, base) + } } else { - movieDict[base] = filename - } - - } - - for key, filename := range movieDict { - // width := 160 - // height := 120 - log.Println(filename) - - cmd := exec.Command("ffmpeg", - "-i", filename, - "-vf", "select='isnan(prev_selected_t)+gte(t-prev_selected_t\\,35)',scale=320:180,tile=3x3", - "-frames:v", "1", - "movie/"+key+".png", - ) - - var buffer bytes.Buffer - cmd.Stdout = &buffer - if cmd.Run() != nil { - log.Println(buffer.String()) - panic("could not generate frame") + movieDict[base] = &Movie{Name: filename} } } @@ -101,6 +85,11 @@ func initMovie() { Image: base[:strings.IndexByte(base, '.')] + ".png", Duration: int(duration / 60.0), } + + if m, ok := movieDict[base[:strings.IndexByte(base, '.')]]; ok { + m.Duration = movie.Duration + } + if movie.Duration <= 15 { categories[0].Movies = append(categories[0].Movies, movie) } else if movie.Duration <= 30 { @@ -122,5 +111,44 @@ func initMovie() { }) } + for key, movie := range movieDict { + // width := 160 + // height := 120 + // if movie.Duration <= 40 { + // continue + // } + + log.Println(movie.Name, "时长:", movie.Duration) + var filter string + + if movie.Duration <= 2 { + filter = "select='isnan(prev_selected_t)+gte(t-prev_selected_t\\,5)',scale=320:180,tile=3x3" + } else if movie.Duration <= 5 { + filter = "select='isnan(prev_selected_t)+gte(t-prev_selected_t\\,10)',scale=320:180,tile=3x3" + } else if movie.Duration <= 30 { + filter = "select='isnan(prev_selected_t)+gte(t-prev_selected_t\\,20)',scale=320:180,tile=3x3" + } else if movie.Duration <= 60 { + filter = "select='isnan(prev_selected_t)+gte(t-prev_selected_t\\,35)',scale=320:180,tile=3x3" + } else { + filter = "select='isnan(prev_selected_t)+gte(t-prev_selected_t\\,60)',scale=320:180,tile=3x3" + } + + cmd := exec.Command("ffmpeg", + "-i", movie.Name, + "-vf", filter, + "-frames:v", "1", + "-y", + "movie/"+key+".png", + ) + + var buffer bytes.Buffer + cmd.Stdout = &buffer + if cmd.Run() != nil { + log.Println(buffer.String()) + panic(fmt.Errorf("could not generate frame %s %d", movie.Name, movie.Duration)) + } + + } + // log.Printf("%##v", categories) } diff --git a/src/Main.jsx b/src/Main.jsx index 1ec5f79..ac70a9f 100644 --- a/src/Main.jsx +++ b/src/Main.jsx @@ -11,6 +11,10 @@ import ConfigContext from './Config'; import MovieCard from './components/MovieCard'; import CategoryNav from './components/CategoryNav'; +import Select from '@mui/material/Select'; +import MenuItem from '@mui/material/MenuItem'; +import FormControl from '@mui/material/FormControl'; +import InputLabel from '@mui/material/InputLabel'; const Main = () => { const config = useContext(ConfigContext); @@ -88,7 +92,7 @@ const Main = () => { currentCategory={currentCategory} onCategoryChange={handleCategoryChange} /> - +