diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-21 09:52:11 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-21 09:52:11 +0200 |
commit | 82fc75dcea8f26f23eec0c6e88244e41b401a826 (patch) | |
tree | 73c233d620cecf7f4e6be6519e41d0bf39024c4c | |
parent | b70f9d308c7074b51a0327e1fd6d62fc50c09c3b (diff) | |
download | jellything-82fc75dcea8f26f23eec0c6e88244e41b401a826.tar jellything-82fc75dcea8f26f23eec0c6e88244e41b401a826.tar.bz2 jellything-82fc75dcea8f26f23eec0c6e88244e41b401a826.tar.zst |
change transcode bitrates and ensure even height for transcoding
-rw-r--r-- | stream/src/stream_info.rs | 14 | ||||
-rw-r--r-- | transcoder/src/fragment.rs | 9 |
2 files changed, 16 insertions, 7 deletions
diff --git a/stream/src/stream_info.rs b/stream/src/stream_info.rs index 8592bc4..43d9289 100644 --- a/stream/src/stream_info.rs +++ b/stream/src/stream_info.rs @@ -105,11 +105,19 @@ fn stream_formats(t: &TrackEntry, remux_bitrate: f64) -> Vec<StreamFormatInfo> { 1 => { let sw = t.video.as_ref().unwrap().pixel_width; let sh = t.video.as_ref().unwrap().pixel_height; - for (w, br) in [(3840, 8e6), (1920, 5e6), (1280, 3e6), (640, 1e6)] { + for (w, br) in [ + (3840, 6000e3), + (1920, 5000e3), + (1920, 2000e3), + (1280, 1500e3), + (640, 800e3), + (320, 200e3), + ] { if w > sw { continue; } - let h = (w * sh) / sw; + // most codecs use chroma subsampling that requires even dims + let h = ((w * sh) / sw) & !1; // clear last bit to ensure even height. for (cid, enable) in [ ("V_AV1", CONF.encoders.av1.is_some()), ("V_VP8", CONF.encoders.vp8.is_some()), @@ -120,7 +128,7 @@ fn stream_formats(t: &TrackEntry, remux_bitrate: f64) -> Vec<StreamFormatInfo> { if enable { formats.push(StreamFormatInfo { codec: cid.to_string(), - bitrate: br, + bitrate: remux_bitrate.max(br), remux: false, containers: containers_by_codec(cid), width: Some(w), diff --git a/transcoder/src/fragment.rs b/transcoder/src/fragment.rs index 3be7d39..7c5cadd 100644 --- a/transcoder/src/fragment.rs +++ b/transcoder/src/fragment.rs @@ -38,9 +38,9 @@ pub async fn transcode( .unwrap_or("ffmpeg %a".to_owned()); let filter = match kind { - TrackKind::Video => format!("-vf scale={}:-1", format.width.unwrap()), - TrackKind::Audio => String::new(), - TrackKind::Subtitle => String::new(), + TrackKind::Video => "-vf scale=%w:%h", + TrackKind::Audio => "", + TrackKind::Subtitle => "", }; let typechar = match kind { TrackKind::Video => "v", @@ -61,8 +61,9 @@ pub async fn transcode( .replace("%a", "-hide_banner %i %f %e %o") .replace("%i", "-f matroska -i pipe:0 -copyts") .replace("%o", "-f matroska pipe:1") - .replace("%w", &format.width.unwrap_or_default().to_string()) .replace("%f", &filter) + .replace("%w", &format.width.unwrap_or_default().to_string()) + .replace("%h", &format.height.unwrap_or_default().to_string()) .replace("%e", "-c:%t %c -b:%t %r") .replace("%t", typechar) .replace("%c", fallback_encoder) |