From f42f125766337bcb7885bb040441dab4ccac4d64 Mon Sep 17 00:00:00 2001 From: shockrah Date: Wed, 20 Oct 2021 21:45:47 -0700 Subject: [PATCH] * Optimizing thumbnail generation so they're 640x? This makes them literally 30Kb on average for my personal use Also they're thumbnails so they could actually be smaller ! forcing thumbnails to be jpg as well --- api/src/thumbnail.rs | 8 +++----- api/src/video.rs | 2 +- scripts/tn-tree-clone.sh | 2 ++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/src/thumbnail.rs b/api/src/thumbnail.rs index da78e3a..8280318 100644 --- a/api/src/thumbnail.rs +++ b/api/src/thumbnail.rs @@ -11,11 +11,9 @@ pub async fn get(file: PathBuf) -> Option { if file_path.is_file() { return match file_path.extension() { Some(ext) => { - if ext == "jpg" || ext == "png" || ext == "jpeg" { - NamedFile::open(file_path).await.ok() - } else { - println!("bad extension"); - None + match ext == "jpg" { + true => NamedFile::open(file_path).await.ok(), + false => None } }, None => None diff --git a/api/src/video.rs b/api/src/video.rs index 8aec679..1c7d11f 100644 --- a/api/src/video.rs +++ b/api/src/video.rs @@ -48,7 +48,7 @@ pub fn list(cat: PathBuf) -> Option>> { let name = name.to_string_lossy(); let cat = cat.to_string_lossy(); - let thumbnail = format!("/thumbnail/{}/{}", cat, name); + let thumbnail = format!("/thumbnail/{}/{}.jpg", cat, name); let item = VideoPreview { name: name.to_string(), diff --git a/scripts/tn-tree-clone.sh b/scripts/tn-tree-clone.sh index 67cce30..496fe04 100644 --- a/scripts/tn-tree-clone.sh +++ b/scripts/tn-tree-clone.sh @@ -43,6 +43,8 @@ pushd "$vids" > /dev/null # Make sure only errors pop up here ffmpeg -hide_banner -loglevel error \ -y -ss 00:00:01 -i "$if" -frames:v 1 "$of.jpg" > /dev/null + ffmpeg -hide_banner -loglevel error \ + -y -i "$of.jpg" -vf scale=640:-1 "$of.jpg" > /dev/null echo $of done popd > /dev/null \ No newline at end of file