From a123a1997f3ab527ab83b44ca18bec94883f46d0 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 18 Apr 2025 23:33:29 +0200 Subject: use impl Hash for cache key instead of string --- transcoder/src/thumbnail.rs | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'transcoder/src/thumbnail.rs') diff --git a/transcoder/src/thumbnail.rs b/transcoder/src/thumbnail.rs index c8bfb1c..caef397 100644 --- a/transcoder/src/thumbnail.rs +++ b/transcoder/src/thumbnail.rs @@ -5,30 +5,27 @@ use std::{path::Path, process::Stdio}; use tokio::{io::copy, process::Command}; pub async fn create_thumbnail(path: &Path, time: f64) -> anyhow::Result { - async_cache_file( - &["thumb", path.to_str().unwrap(), &format!("{time}")], - move |mut output| async move { - let _permit = LOCAL_IMAGE_TRANSCODING_TASKS.acquire().await?; - info!("creating thumbnail of {path:?} at {time}s",); + async_cache_file("thumb", (path, time as i64), move |mut output| async move { + let _permit = LOCAL_IMAGE_TRANSCODING_TASKS.acquire().await?; + info!("creating thumbnail of {path:?} at {time}s",); - let mut proc = Command::new("ffmpeg") - .stdout(Stdio::piped()) - .args(["-ss", &format!("{time}")]) - .args(["-f", "matroska", "-i", path.to_str().unwrap()]) - .args(["-frames:v", "1"]) - .args(["-c:v", "qoi"]) - .args(["-f", "image2"]) - .args(["-update", "1"]) - .arg("pipe:1") - .spawn()?; + let mut proc = Command::new("ffmpeg") + .stdout(Stdio::piped()) + .args(["-ss", &format!("{time}")]) + .args(["-f", "matroska", "-i", path.to_str().unwrap()]) + .args(["-frames:v", "1"]) + .args(["-c:v", "qoi"]) + .args(["-f", "image2"]) + .args(["-update", "1"]) + .arg("pipe:1") + .spawn()?; - let mut stdout = proc.stdout.take().unwrap(); - copy(&mut stdout, &mut output).await?; + let mut stdout = proc.stdout.take().unwrap(); + copy(&mut stdout, &mut output).await?; - proc.wait().await.unwrap().exit_ok()?; - info!("done"); - Ok(()) - }, - ) + proc.wait().await.unwrap().exit_ok()?; + info!("done"); + Ok(()) + }) .await } -- cgit v1.2.3-70-g09d2