diff options
Diffstat (limited to 'transcoder/src/fragment.rs')
-rw-r--r-- | transcoder/src/fragment.rs | 74 |
1 files changed, 21 insertions, 53 deletions
diff --git a/transcoder/src/fragment.rs b/transcoder/src/fragment.rs index b88339c..3cb4c40 100644 --- a/transcoder/src/fragment.rs +++ b/transcoder/src/fragment.rs @@ -7,7 +7,7 @@ use crate::LOCAL_VIDEO_TRANSCODING_TASKS; use jellybase::{ cache::{async_cache_file, CachePath}, - common::stream::StreamFormatInfo, + common::stream::{StreamContainer, StreamFormatInfo}, }; use log::{debug, info}; use std::process::Stdio; @@ -21,73 +21,41 @@ use tokio::{ pub async fn transcode( key: &str, - enc: &StreamFormatInfo, + format: &StreamFormatInfo, + container: StreamContainer, input: impl FnOnce(ChildStdin), ) -> anyhow::Result<CachePath> { async_cache_file( - &["frag-tc", key, &format!("{enc:?}")], + &["frag-tc", key, &format!("{format:?}")], move |mut output| async move { let _permit = LOCAL_VIDEO_TRANSCODING_TASKS.acquire().await?; - debug!("transcoding fragment with {enc:?}"); + debug!("transcoding fragment with {format:?}"); let mut args = Vec::<String>::new(); - // match enc { - // EncodingProfile::Video { - // codec, - // preset, - // bitrate, - // width, - // } => { - // 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, - // 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 } => { - // args.push("-c:s".to_string()); - // args.push(codec.to_string()); - // } - // }; + + match format.codec.as_str() { + "V_AVC" => {} + + _ => unreachable!(), + } + info!("encoding with {:?}", args.join(" ")); + let container = match container { + StreamContainer::WebM => "webm", + StreamContainer::Matroska => "matroska", + StreamContainer::WebVTT => "vtt", + StreamContainer::MPEG4 => "mp4", + StreamContainer::JVTT => unreachable!(), + }; + let mut proc = Command::new("ffmpeg") .stdin(Stdio::piped()) .stdout(Stdio::piped()) .args(["-f", "matroska", "-i", "pipe:0"]) .args(args) - .args(["-f", "webm", "pipe:1"]) + .args(["-f", container, "pipe:1"]) .spawn()?; - // let mut proc = Command::new("cat") - // .stdin(Stdio::piped()) - // .stdout(Stdio::piped()) - // .spawn()?; let stdin = proc.stdin.take().unwrap(); let mut stdout = proc.stdout.take().unwrap(); |