aboutsummaryrefslogtreecommitdiff
path: root/transcoder/src
diff options
context:
space:
mode:
Diffstat (limited to 'transcoder/src')
-rw-r--r--transcoder/src/snippet.rs33
1 files changed, 19 insertions, 14 deletions
diff --git a/transcoder/src/snippet.rs b/transcoder/src/snippet.rs
index 3cc9736..9253c2c 100644
--- a/transcoder/src/snippet.rs
+++ b/transcoder/src/snippet.rs
@@ -5,7 +5,7 @@
*/
use jellybase::cache::async_cache_file;
-use jellycommon::AssetLocation;
+use jellycommon::{AssetLocation, EncodingProfile};
use log::info;
use std::process::Stdio;
use tokio::{
@@ -13,19 +13,9 @@ use tokio::{
process::{ChildStdin, Command},
};
-#[derive(Debug)]
-pub enum Encoding {
- Video {
- codec: &'static str,
- preset: u8,
- bitrate: usize,
- width: usize,
- },
-}
-
pub async fn transcode(
key: &str,
- enc: Encoding,
+ enc: &EncodingProfile,
input: impl FnOnce(ChildStdin),
) -> anyhow::Result<AssetLocation> {
Ok(async_cache_file(
@@ -33,7 +23,7 @@ pub async fn transcode(
move |mut output| async move {
info!("transcoding snippet {key}");
let args = match enc {
- Encoding::Video {
+ EncodingProfile::Video {
codec,
preset,
bitrate,
@@ -49,6 +39,21 @@ pub async fn transcode(
format!("{bitrate}"),
]
.to_vec(),
+ EncodingProfile::Audio {
+ codec,
+ bitrate,
+ sample_rate: _,
+ } => [
+ // TODO resample?
+ "-c:a".to_string(),
+ codec.to_string(),
+ "-b:a".to_string(),
+ format!("{bitrate}"),
+ ]
+ .to_vec(),
+ EncodingProfile::Subtitles { codec } => {
+ ["-c:s".to_string(), codec.to_string()].to_vec()
+ }
};
info!("encoding with {:?}", args.join(" "));
@@ -65,7 +70,7 @@ pub async fn transcode(
input(stdin);
copy(&mut stdout, &mut output).await?;
-
+
proc.wait().await.unwrap().exit_ok()?;
info!("done");
Ok(())