This commit is contained in:
eson 2023-07-09 08:25:39 +08:00
parent 29331006a6
commit c5159c3eab
3 changed files with 74 additions and 29 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"fmt"
"io/fs" "io/fs"
"log" "log"
"os/exec" "os/exec"
@ -27,9 +28,11 @@ type Movie struct {
// var movies []Movie // var movies []Movie
var categories []Category var categories []Category
var IsRemakePNG = false
func initMovie() { func initMovie() {
// 需要改进 如果存在这个文件的略缩图, 就不存进movieDict里 // 需要改进 如果存在这个文件的略缩图, 就不存进movieDict里
var movieDict map[string]string = make(map[string]string) var movieDict map[string]*Movie = make(map[string]*Movie)
matches, err := filepath.Glob("movie/*") matches, err := filepath.Glob("movie/*")
if err != nil { if err != nil {
@ -43,30 +46,11 @@ func initMovie() {
base = base[:strings.IndexByte(base, '.')] base = base[:strings.IndexByte(base, '.')]
if _, ok := movieDict[base]; ok { if _, ok := movieDict[base]; ok {
delete(movieDict, base) if !IsRemakePNG {
delete(movieDict, base)
}
} else { } else {
movieDict[base] = filename movieDict[base] = &Movie{Name: 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")
} }
} }
@ -101,6 +85,11 @@ func initMovie() {
Image: base[:strings.IndexByte(base, '.')] + ".png", Image: base[:strings.IndexByte(base, '.')] + ".png",
Duration: int(duration / 60.0), Duration: int(duration / 60.0),
} }
if m, ok := movieDict[base[:strings.IndexByte(base, '.')]]; ok {
m.Duration = movie.Duration
}
if movie.Duration <= 15 { if movie.Duration <= 15 {
categories[0].Movies = append(categories[0].Movies, movie) categories[0].Movies = append(categories[0].Movies, movie)
} else if movie.Duration <= 30 { } 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) // log.Printf("%##v", categories)
} }

View File

@ -11,6 +11,10 @@ import ConfigContext from './Config';
import MovieCard from './components/MovieCard'; import MovieCard from './components/MovieCard';
import CategoryNav from './components/CategoryNav'; 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 Main = () => {
const config = useContext(ConfigContext); const config = useContext(ConfigContext);
@ -88,7 +92,7 @@ const Main = () => {
currentCategory={currentCategory} currentCategory={currentCategory}
onCategoryChange={handleCategoryChange} onCategoryChange={handleCategoryChange}
/> />
<div style={{ textAlign: 'center', marginBottom: 20 }}> <div style={{ textAlign: 'center', marginBottom: 20 }}>
<Pagination <Pagination
count={pagination.length} count={pagination.length}

View File

@ -1,8 +1,7 @@
import React from 'react'; import React from 'react';
import Card from '@mui/material/Card';
import CardMedia from '@mui/material/CardMedia'; import { Card, CardContent, CardMedia, Typography } from '@mui/material';
import CardContent from '@mui/material/CardContent'; import { styled, useTheme } from '@mui/system';
import Typography from '@mui/material/Typography';
const MovieCard = ({ movie, config }) => { const MovieCard = ({ movie, config }) => {
const truncateFilename = (filename, maxLength) => { const truncateFilename = (filename, maxLength) => {
@ -11,7 +10,20 @@ const MovieCard = ({ movie, config }) => {
: filename; : filename;
}; };
const theme = useTheme();
console.log(theme.shadows)
const StyledCard = styled(Card)({
'&:hover': {
transform: 'scale(1.05)',
boxShadow: '0px 6px 16px rgba(0, 0, 0, 0.1)',
zIndex: 1,
},
});
return ( return (
<StyledCard>
<Card <Card
style={{ style={{
width: '100%', width: '100%',
@ -35,6 +47,7 @@ const MovieCard = ({ movie, config }) => {
</Typography> </Typography>
</CardContent> </CardContent>
</Card> </Card>
</StyledCard>
); );
}; };