aboutsummaryrefslogtreecommitdiff
path: root/transcoder
diff options
context:
space:
mode:
Diffstat (limited to 'transcoder')
-rw-r--r--transcoder/src/fragment.rs11
-rw-r--r--transcoder/src/image.rs18
-rw-r--r--transcoder/src/thumbnail.rs51
3 files changed, 45 insertions, 35 deletions
diff --git a/transcoder/src/fragment.rs b/transcoder/src/fragment.rs
index 5aca1f7..6603afa 100644
--- a/transcoder/src/fragment.rs
+++ b/transcoder/src/fragment.rs
@@ -3,10 +3,10 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-use crate::{Config, CONF, LOCAL_VIDEO_TRANSCODING_TASKS};
+use crate::{CONF, Config, LOCAL_VIDEO_TRANSCODING_TASKS};
use anyhow::Result;
-use jellycache::{cache, HashKey};
-use jellyremuxer::{demuxers::create_demuxer, muxers::write_fragment, ContainerFormat};
+use jellycache::{Cache, HashKey};
+use jellyremuxer::{ContainerFormat, demuxers::create_demuxer, muxers::write_fragment};
use jellystream_types::{StreamFormatInfo, TrackKind};
use log::info;
use std::{
@@ -15,12 +15,13 @@ use std::{
process::{Command, Stdio},
thread::spawn,
};
-use winter_matroska::{block::Block, Cluster, Segment, TrackEntry as MatroskaTrackEntry};
+use winter_matroska::{Cluster, Segment, TrackEntry as MatroskaTrackEntry, block::Block};
// TODO odd video resolutions can cause errors when transcoding to YUV42{0,2}
// TODO with an implementation that cant handle it (SVT-AV1 is such an impl).
pub fn transcode(
+ cache: &Cache,
kind: TrackKind,
input_key: &str,
output_format: &StreamFormatInfo,
@@ -38,7 +39,7 @@ pub fn transcode(
let input_duration = input.info.duration;
let had_next_kf = next_kf.is_some();
- let output = cache(
+ let output = cache.cache(
&format!(
"transcode/media-fragment/{input_key}-{}.mkv",
HashKey(&command)
diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs
index 14b3e53..eaf8b86 100644
--- a/transcoder/src/image.rs
+++ b/transcoder/src/image.rs
@@ -3,21 +3,29 @@
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-use anyhow::{anyhow, Context, Result};
+use anyhow::{Context, Result, anyhow};
use image::imageops::FilterType;
-use jellycache::{cache, cache_read, HashKey};
+use jellycache::{Cache, HashKey};
use log::{debug, info};
use rgb::FromSlice;
use std::io::Cursor;
-pub fn transcode(key: &str, quality: u32, speed: u8, width: usize) -> Result<Vec<u8>> {
- cache(
+pub fn transcode(
+ cache: &Cache,
+ key: &str,
+ quality: u32,
+ speed: u8,
+ width: usize,
+) -> Result<Vec<u8>> {
+ cache.cache(
&format!(
"transcode/image/{}-W{width}-Q{quality}-S{speed}",
HashKey(key)
),
move || {
- let input = cache_read(key)?.ok_or(anyhow!("transcode cache key missing"))?;
+ let input = cache
+ .read(key)?
+ .ok_or(anyhow!("transcode cache key missing"))?;
info!("encoding image (speed={speed}, quality={quality}, width={width})");
// TODO: use better image library that supports AVIF
diff --git a/transcoder/src/thumbnail.rs b/transcoder/src/thumbnail.rs
index 85cb356..9207c30 100644
--- a/transcoder/src/thumbnail.rs
+++ b/transcoder/src/thumbnail.rs
@@ -1,5 +1,5 @@
use anyhow::{Context, Result};
-use jellycache::{cache_store, HashKey};
+use jellycache::{Cache, HashKey};
use log::info;
use std::{
io::Read,
@@ -7,31 +7,32 @@ use std::{
process::{Command, Stdio},
};
-pub fn create_thumbnail(path: &Path, time: f64) -> Result<String> {
- cache_store(
- format!("media/thumbnail/{}-{}.image", HashKey(path), time as i64),
- move || {
- info!("creating thumbnail of {path:?} at {time}s",);
+pub fn create_thumbnail(cache: &Cache, path: &Path, time: f64) -> Result<String> {
+ cache
+ .store(
+ format!("media/thumbnail/{}-{}.image", HashKey(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();
- let mut output = Vec::new();
- stdout.read_to_end(&mut output)?;
+ let mut stdout = proc.stdout.take().unwrap();
+ let mut output = Vec::new();
+ stdout.read_to_end(&mut output)?;
- proc.wait().unwrap().exit_ok()?;
- info!("done");
- Ok(output)
- },
- )
- .context("creating thumbnail")
+ proc.wait().unwrap().exit_ok()?;
+ info!("done");
+ Ok(output)
+ },
+ )
+ .context("creating thumbnail")
}