diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-04 10:32:22 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-04 10:32:22 +0200 |
commit | b68ad41289dbbf4dac6b56f8b0a9a49ee7f47417 (patch) | |
tree | 19635bf7ae869903f59dff1402f7dc045d10bc5b | |
parent | 8d3faa3d3d765441a0753748c92079db08fb8374 (diff) | |
download | jellything-b68ad41289dbbf4dac6b56f8b0a9a49ee7f47417.tar jellything-b68ad41289dbbf4dac6b56f8b0a9a49ee7f47417.tar.bz2 jellything-b68ad41289dbbf4dac6b56f8b0a9a49ee7f47417.tar.zst |
add more params to transcoding profile
-rw-r--r-- | common/src/config.rs | 14 | ||||
-rw-r--r-- | common/src/jhls.rs | 5 | ||||
-rw-r--r-- | transcoder/src/snippet.rs | 57 |
3 files changed, 46 insertions, 30 deletions
diff --git a/common/src/config.rs b/common/src/config.rs index 65d7326..399e96a 100644 --- a/common/src/config.rs +++ b/common/src/config.rs @@ -62,31 +62,33 @@ mod default { vec![ EncodingProfile::Video { codec: "libsvtav1".to_string(), - preset: 8, + preset: Some(8), bitrate: 2_000_000, - width: 1920, + width: Some(1920), }, EncodingProfile::Video { codec: "libsvtav1".to_string(), - preset: 8, + preset: Some(8), bitrate: 1_200_000, - width: 1280, + width: Some(1280), }, EncodingProfile::Video { codec: "libsvtav1".to_string(), - preset: 8, + preset: Some(8), bitrate: 300_000, - width: 640, + width: Some(640), }, EncodingProfile::Audio { codec: "libopus".to_string(), bitrate: 128_000, sample_rate: None, + channels: Some(2), }, EncodingProfile::Audio { codec: "libopus".to_string(), bitrate: 64_000, sample_rate: None, + channels: Some(2), }, EncodingProfile::Subtitles { codec: "webvtt".to_string(), diff --git a/common/src/jhls.rs b/common/src/jhls.rs index e3ef23c..fe3ffa0 100644 --- a/common/src/jhls.rs +++ b/common/src/jhls.rs @@ -20,13 +20,14 @@ pub struct JhlsTrack { pub enum EncodingProfile { Video { codec: String, - preset: u8, + preset: Option<u8>, bitrate: usize, - width: usize, + width: Option<usize>, }, Audio { codec: String, bitrate: usize, + channels: Option<usize>, sample_rate: Option<f64>, }, Subtitles { diff --git a/transcoder/src/snippet.rs b/transcoder/src/snippet.rs index e9569da..969a2ec 100644 --- a/transcoder/src/snippet.rs +++ b/transcoder/src/snippet.rs @@ -24,37 +24,50 @@ pub async fn transcode( move |mut output| async move { let _permit = LOCAL_TRANSCODING_TASKS.acquire().await?; info!("transcoding snippet {key}"); - let args = match enc { + + let mut args = Vec::new(); + match enc { EncodingProfile::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(), + } => { + if let Some(width) = width { + args.push("-vf".to_string()); + args.push(format!("scale={width}:-1")); + } + args.push("-c:v".to_string()); + args.push(codec.to_string()); + if let Some(preset) = preset { + args.push("-preset".to_string()); + args.push(format!("{preset}")); + } + args.push("-b:v".to_string()); + args.push(format!("{bitrate}")); + } EncodingProfile::Audio { codec, bitrate, - sample_rate: _, - } => [ - // TODO resample? - "-c:a".to_string(), - codec.to_string(), - "-b:a".to_string(), - format!("{bitrate}"), - ] - .to_vec(), + sample_rate, + channels, + } => { + if let Some(channels) = channels { + args.push("-ac".to_string()); + args.push(format!("{channels}")) + } + if let Some(sample_rate) = sample_rate { + args.push("-ar".to_string()); + args.push(format!("{sample_rate}")) + } + args.push("-c:a".to_string()); + args.push(codec.to_string()); + args.push("-b:a".to_string()); + args.push(format!("{bitrate}")); + } EncodingProfile::Subtitles { codec } => { - ["-c:s".to_string(), codec.to_string()].to_vec() + args.push("-c:s".to_string()); + args.push(codec.to_string()); } }; info!("encoding with {:?}", args.join(" ")); |