diff options
Diffstat (limited to 'transcoder/src/fragment.rs')
| -rw-r--r-- | transcoder/src/fragment.rs | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/transcoder/src/fragment.rs b/transcoder/src/fragment.rs index b6c3b2d..a7a6f42 100644 --- a/transcoder/src/fragment.rs +++ b/transcoder/src/fragment.rs @@ -15,7 +15,7 @@ use std::{ process::{Command, Stdio}, thread::spawn, }; -use winter_matroska::{Segment, TrackEntry as MatroskaTrackEntry}; +use winter_matroska::Segment; // TODO odd video resolutions can cause errors when transcoding to YUV42{0,2} // TODO with an implementation that cant handle it (SVT-AV1 is such an impl). @@ -24,19 +24,14 @@ pub fn transcode_init( cache: &Cache, config: &Config, kind: TrackKind, - input_key: &str, + input_format: &StreamFormatInfo, output_format: &StreamFormatInfo, ) -> Result<Segment> { - let command = transcode_command( - kind, - &MatroskaTrackEntry::default(), - output_format, - true, - config, - )?; + let command = transcode_command(kind, input_format, output_format, true, config)?; let output = cache.cache( &format!( - "transcode/media-fragment/{input_key}-{}.mkv", + "transcode/media-init/{}-{}.mkv", + input_format.metadata_str(), HashKey(&command) ), || { @@ -65,11 +60,11 @@ pub fn transcode( config: &Config, kind: TrackKind, input_key: &str, + input_format: &StreamFormatInfo, output_format: &StreamFormatInfo, - input_track: &MatroskaTrackEntry, segment: impl FnOnce() -> Result<Segment>, ) -> Result<Segment> { - let command = transcode_command(kind, &input_track, output_format, false, config).unwrap(); + let command = transcode_command(kind, &input_format, output_format, false, config).unwrap(); let output = cache.cache( &format!( @@ -131,14 +126,14 @@ pub fn transcode( fn transcode_command( kind: TrackKind, - orig_metadata: &MatroskaTrackEntry, - format: &StreamFormatInfo, + input: &StreamFormatInfo, + output: &StreamFormatInfo, dummy: bool, config: &Config, ) -> Result<String> { - let br = format.bitrate as u64; - let w = format.width.unwrap_or(0); - let h = format.height.unwrap_or(0); + let br = output.bitrate as u64; + let w = output.width.unwrap_or(0); + let h = output.height.unwrap_or(0); let mut o = String::new(); write!(o, "ffmpeg -hide_banner ")?; @@ -151,18 +146,17 @@ fn transcode_command( } if dummy { - write!(o, "-f lavfi -i testsrc2 -to 1 ")?; + write!(o, "-f lavfi -i testsrc2=s={w}x{h},format=yuv420p -to 1 ")?; } else { write!(o, "-f matroska -i pipe:0 -copyts ")?; + if config.enable_rkrga { + write!(o, "-vf scale_rkrga=w={w}:h={h}:format=nv12:afbc=1 ")?; + } else { + write!(o, "-vf scale={w}:{h} ")?; + } } - if config.enable_rkrga { - write!(o, "-vf scale_rkrga=w={w}:h={h}:format=nv12:afbc=1 ")?; - } else { - write!(o, "-vf scale={w}:{h} ")?; - } - - match format.codec.as_str() { + match output.codec.as_str() { "V_MPEG4/ISO/AVC" if config.enable_rkmpp => { write!(o, "-c:v h264_rkmpp -profile:v high -b:v {br} ")? } @@ -192,10 +186,10 @@ fn transcode_command( }; } else if kind == TrackKind::Audio { write!(o, "-f matroska -i pipe:0 -copyts ")?; - if format.codec == "A_OPUS" && orig_metadata.audio.as_ref().unwrap().channels > 2 { + if output.codec == "A_OPUS" && input.channels.unwrap_or(2) > 2 { write!(o, "-ac 2 ")?; } - match format.codec.as_str() { + match output.codec.as_str() { "A_OPUS" => write!(o, "-c:a libopus -b:a {br} ")?, _ => todo!(), } |