diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-02 12:07:59 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-02 12:07:59 +0200 |
commit | 6887dfcf9774cb692a8375e0320ffcf80edb9536 (patch) | |
tree | 5710f952f2ea4879c7f5affba53ad2a3fafc8572 /transcoder/src | |
parent | 50b66f818d3d890e2ee13c88c404031faaeea7ba (diff) | |
download | jellything-6887dfcf9774cb692a8375e0320ffcf80edb9536.tar jellything-6887dfcf9774cb692a8375e0320ffcf80edb9536.tar.bz2 jellything-6887dfcf9774cb692a8375e0320ffcf80edb9536.tar.zst |
started transcoding
Diffstat (limited to 'transcoder/src')
-rw-r--r-- | transcoder/src/snippet.rs | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/transcoder/src/snippet.rs b/transcoder/src/snippet.rs index c7033d8..56bd523 100644 --- a/transcoder/src/snippet.rs +++ b/transcoder/src/snippet.rs @@ -6,23 +6,58 @@ use jellybase::{cache::async_cache_file, AssetLocationExt}; use jellycommon::AssetLocation; +use std::process::Stdio; +use tokio::{fs::File, process::Command}; -pub async fn transcode( - asset: AssetLocation, - quality: f32, - speed: u8, - width: usize, -) -> anyhow::Result<AssetLocation> { +#[derive(Debug)] +pub enum Encoding { + Video { + codec: &'static str, + preset: u8, + bitrate: usize, + width: usize, + }, +} + +pub async fn transcode(asset: AssetLocation, enc: Encoding) -> anyhow::Result<AssetLocation> { let original_path = asset.path(); let asset = asset.clone(); Ok(async_cache_file( &[ "snip-tc", original_path.as_os_str().to_str().unwrap(), - &format!("{width} {quality} {speed}"), + &format!("{enc:?}"), ], move |output| async move { - + let args = match enc { + Encoding::Video { + codec, + preset, + bitrate, + width, + } => [ + "-vf".to_string(), + format!("scale={width}:-1"), + "-c:v".to_string(), + codec.to_string(), + "-preset".to_string(), + format!("{preset}"), + "-b:v".to_string(), + format!("{bitrate}"), + ] + .to_vec(), + }; + let mut proc = Command::new("ffmpeg") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .args(&["-f", "mkv", "-i", "pipe:0"]) + .args(args) + .args(&["-f", "mkv", "pipe:1"]) + .spawn()?; + + let mut stdin = proc.stdin.take().unwrap(); + let mut stdout = proc.stdout.take().unwrap(); + Ok(()) }, ) |