aboutsummaryrefslogtreecommitdiff
path: root/transcoder/src/thumbnail.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-01-16 21:53:40 +0100
committermetamuffin <metamuffin@disroot.org>2024-01-16 21:53:40 +0100
commit98b379afb31e455b529d443dcfc5797b8dd6723e (patch)
tree98ee2cbbca36fd7e5d4a4c4495a8d62144d4e3d1 /transcoder/src/thumbnail.rs
parent4558265c09dbb8ff53462ca842d82f2abfe39cb4 (diff)
downloadjellything-98b379afb31e455b529d443dcfc5797b8dd6723e.tar
jellything-98b379afb31e455b529d443dcfc5797b8dd6723e.tar.bz2
jellything-98b379afb31e455b529d443dcfc5797b8dd6723e.tar.zst
thumbnail generation
Diffstat (limited to 'transcoder/src/thumbnail.rs')
-rw-r--r--transcoder/src/thumbnail.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/transcoder/src/thumbnail.rs b/transcoder/src/thumbnail.rs
new file mode 100644
index 0000000..5baf888
--- /dev/null
+++ b/transcoder/src/thumbnail.rs
@@ -0,0 +1,35 @@
+use crate::LOCAL_IMAGE_TRANSCODING_TASKS;
+use jellybase::cache::async_cache_file;
+use jellycommon::AssetLocation;
+use log::info;
+use std::{path::Path, process::Stdio};
+use tokio::{io::copy, process::Command};
+
+pub async fn create_thumbnail(path: &Path, time: f64) -> anyhow::Result<AssetLocation> {
+ Ok(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",);
+
+ 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?;
+
+ proc.wait().await.unwrap().exit_ok()?;
+ info!("done");
+ Ok(())
+ },
+ )
+ .await?)
+}