aboutsummaryrefslogtreecommitdiff
path: root/transcoder/src/thumbnail.rs
diff options
context:
space:
mode:
Diffstat (limited to 'transcoder/src/thumbnail.rs')
-rw-r--r--transcoder/src/thumbnail.rs56
1 files changed, 31 insertions, 25 deletions
diff --git a/transcoder/src/thumbnail.rs b/transcoder/src/thumbnail.rs
index 8cefac3..eda9e04 100644
--- a/transcoder/src/thumbnail.rs
+++ b/transcoder/src/thumbnail.rs
@@ -1,31 +1,37 @@
-use crate::LOCAL_IMAGE_TRANSCODING_TASKS;
-use jellycache::{async_cache_file, CachePath};
+use anyhow::{Context, Result};
+use jellycache::{cache_store, CacheKey};
use log::info;
-use std::{path::Path, process::Stdio};
-use tokio::{io::copy, process::Command};
+use std::{
+ io::Read,
+ path::Path,
+ process::{Command, Stdio},
+};
-pub async fn create_thumbnail(path: &Path, time: f64) -> anyhow::Result<CachePath> {
- 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",);
+pub fn create_thumbnail(path: &Path, time: f64) -> Result<CacheKey> {
+ cache_store(
+ CacheKey::new_image(("thumbnail", path, time as i64)),
+ move || {
+ 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();
+ let mut output = Vec::new();
+ stdout.read_to_end(&mut output)?;
- proc.wait().await.unwrap().exit_ok()?;
- info!("done");
- Ok(())
- })
- .await
+ proc.wait().unwrap().exit_ok()?;
+ info!("done");
+ Ok(output)
+ },
+ )
+ .context("creating thumbnail")
}