aboutsummaryrefslogtreecommitdiff
path: root/transcoder/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-12-08 19:53:12 +0100
committermetamuffin <metamuffin@disroot.org>2025-12-08 19:53:12 +0100
commit6edf0fd93abf7e58b4c0974e3d3e54bcf8517946 (patch)
tree32577db9d987897d4037ba9af0084b95b55e145c /transcoder/src
parente4584a8135584e6591bac7d5397cf227cf3cff92 (diff)
downloadjellything-6edf0fd93abf7e58b4c0974e3d3e54bcf8517946.tar
jellything-6edf0fd93abf7e58b4c0974e3d3e54bcf8517946.tar.bz2
jellything-6edf0fd93abf7e58b4c0974e3d3e54bcf8517946.tar.zst
human-readable cache keys
Diffstat (limited to 'transcoder/src')
-rw-r--r--transcoder/src/fragment.rs7
-rw-r--r--transcoder/src/image.rs11
-rw-r--r--transcoder/src/thumbnail.rs6
3 files changed, 15 insertions, 9 deletions
diff --git a/transcoder/src/fragment.rs b/transcoder/src/fragment.rs
index 564c94d..4380df6 100644
--- a/transcoder/src/fragment.rs
+++ b/transcoder/src/fragment.rs
@@ -5,7 +5,7 @@
*/
use crate::{Config, CONF, LOCAL_VIDEO_TRANSCODING_TASKS};
use anyhow::Result;
-use jellycache::{cache, CacheContentType, CacheKey};
+use jellycache::{cache, HashKey};
use jellyremuxer::{demuxers::create_demuxer, muxers::write_fragment, ContainerFormat};
use jellystream_types::{StreamFormatInfo, TrackKind};
use log::info;
@@ -39,7 +39,10 @@ pub fn transcode(
let had_next_kf = next_kf.is_some();
let output = cache(
- CacheKey::new(CacheContentType::Unknown, ("frag-tc", input_key, &command)),
+ &format!(
+ "transcode/media-fragment/{input_key}-{}.mkv",
+ HashKey(&command)
+ ),
|| {
let _permit = LOCAL_VIDEO_TRANSCODING_TASKS.lock().unwrap();
info!("encoding with {command:?}");
diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs
index 6943b2b..49f99bd 100644
--- a/transcoder/src/image.rs
+++ b/transcoder/src/image.rs
@@ -5,14 +5,17 @@
*/
use anyhow::{anyhow, Context, Result};
use image::imageops::FilterType;
-use jellycache::{cache, cache_read, CacheKey};
+use jellycache::{cache, cache_read, HashKey};
use log::{debug, info};
use rgb::FromSlice;
use std::io::Cursor;
-pub fn transcode(key: CacheKey, quality: f32, speed: u8, width: usize) -> Result<Vec<u8>> {
+pub fn transcode(key: &str, quality: u32, speed: u8, width: usize) -> Result<Vec<u8>> {
cache(
- CacheKey::new_image(("image-tc", key, width, quality as i32, speed)),
+ &format!(
+ "transcode/image/{}-W{width}-Q{quality}-S{speed}",
+ HashKey(key)
+ ),
move || {
let input = cache_read(key)?.ok_or(anyhow!("transcode cache key missing"))?;
info!("encoding image (speed={speed}, quality={quality}, width={width})");
@@ -53,7 +56,7 @@ pub fn transcode(key: CacheKey, quality: f32, speed: u8, width: usize) -> Result
let pixels = image.to_vec();
let encoded = ravif::Encoder::new()
.with_speed(speed.clamp(1, 10))
- .with_quality(quality.clamp(1., 100.))
+ .with_quality(quality.clamp(1, 100) as f32)
.encode_rgba(imgref::Img::new(
pixels.as_rgba(),
image.width() as usize,
diff --git a/transcoder/src/thumbnail.rs b/transcoder/src/thumbnail.rs
index eda9e04..85cb356 100644
--- a/transcoder/src/thumbnail.rs
+++ b/transcoder/src/thumbnail.rs
@@ -1,5 +1,5 @@
use anyhow::{Context, Result};
-use jellycache::{cache_store, CacheKey};
+use jellycache::{cache_store, HashKey};
use log::info;
use std::{
io::Read,
@@ -7,9 +7,9 @@ use std::{
process::{Command, Stdio},
};
-pub fn create_thumbnail(path: &Path, time: f64) -> Result<CacheKey> {
+pub fn create_thumbnail(path: &Path, time: f64) -> Result<String> {
cache_store(
- CacheKey::new_image(("thumbnail", path, time as i64)),
+ format!("media/thumbnail/{}-{}.image", HashKey(path), time as i64),
move || {
info!("creating thumbnail of {path:?} at {time}s",);