aboutsummaryrefslogtreecommitdiff
path: root/transcoder/src
diff options
context:
space:
mode:
Diffstat (limited to 'transcoder/src')
-rw-r--r--transcoder/src/image.rs6
-rw-r--r--transcoder/src/lib.rs4
-rw-r--r--transcoder/src/snippet.rs2
3 files changed, 9 insertions, 3 deletions
diff --git a/transcoder/src/image.rs b/transcoder/src/image.rs
index 06a2f80..3cd9986 100644
--- a/transcoder/src/image.rs
+++ b/transcoder/src/image.rs
@@ -1,3 +1,4 @@
+use crate::LOCAL_TRANSCODING_TASKS;
use anyhow::Context;
use image::{imageops::FilterType, ImageFormat};
use jellybase::{cache::async_cache_file, AssetLocationExt};
@@ -22,11 +23,10 @@ pub async fn transcode(
&format!("{width} {quality} {speed}"),
],
move |mut output| async move {
+ let _permit = LOCAL_TRANSCODING_TASKS.acquire().await?;
+ info!("encoding {asset:?} (speed={speed}, quality={quality}, width={width})");
let encoded = tokio::task::spawn_blocking(move || {
let original_path = asset.path();
- info!(
- "encoding {original_path:?} (speed={speed}, quality={quality}, width={width})"
- );
// TODO shouldn't be neccessary with guessed format.
let file = BufReader::new(File::open(&original_path).context("opening source")?);
let mut reader = image::io::Reader::new(file);
diff --git a/transcoder/src/lib.rs b/transcoder/src/lib.rs
index 240d37a..673946b 100644
--- a/transcoder/src/lib.rs
+++ b/transcoder/src/lib.rs
@@ -5,5 +5,9 @@
*/
#![feature(async_closure)]
#![feature(exit_status_error)]
+
+use tokio::sync::Semaphore;
pub mod image;
pub mod snippet;
+
+static LOCAL_TRANSCODING_TASKS: Semaphore = Semaphore::const_new(2);
diff --git a/transcoder/src/snippet.rs b/transcoder/src/snippet.rs
index 42847a0..e9569da 100644
--- a/transcoder/src/snippet.rs
+++ b/transcoder/src/snippet.rs
@@ -4,6 +4,7 @@
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
+use crate::LOCAL_TRANSCODING_TASKS;
use jellybase::cache::async_cache_file;
use jellycommon::{jhls::EncodingProfile, AssetLocation};
use log::info;
@@ -21,6 +22,7 @@ pub async fn transcode(
Ok(async_cache_file(
&["snip-tc", key, &format!("{enc:?}")],
move |mut output| async move {
+ let _permit = LOCAL_TRANSCODING_TASKS.acquire().await?;
info!("transcoding snippet {key}");
let args = match enc {
EncodingProfile::Video {