diff --git a/crates/punktfunk-host/src/encode/linux/mod.rs b/crates/punktfunk-host/src/encode/linux/mod.rs index 4a592d66..d495c0be 100644 --- a/crates/punktfunk-host/src/encode/linux/mod.rs +++ b/crates/punktfunk-host/src/encode/linux/mod.rs @@ -311,12 +311,7 @@ impl NvencEncoder { // hold frame size roughly constant and absorb motion as a momentary QP (quality) dip instead // — the trade we want. Default = 1 frame of bits (bitrate/fps); PUNKTFUNK_VBV_FRAMES tunes it // (larger = better motion quality but bigger per-frame bursts). - let vbv_frames = std::env::var("PUNKTFUNK_VBV_FRAMES") - .ok() - .and_then(|s| s.parse::().ok()) - .filter(|v| v.is_finite() && *v > 0.0) - .unwrap_or(1.0); - let vbv_bits = ((bitrate_bps as f64 / fps.max(1) as f64) * vbv_frames as f64) + let vbv_bits = ((bitrate_bps as f64 / fps.max(1) as f64) * crate::encode::vbv_frames_env()) .clamp(1.0, i32::MAX as f64); // SAFETY: `video` is the ffmpeg-next encoder builder wrapping a freshly-allocated // `AVCodecContext` that we hold by value and have not opened yet; `video.as_mut_ptr()` returns diff --git a/crates/punktfunk-host/src/encode/linux/vaapi.rs b/crates/punktfunk-host/src/encode/linux/vaapi.rs index 5385b4f6..7a0903b1 100644 --- a/crates/punktfunk-host/src/encode/linux/vaapi.rs +++ b/crates/punktfunk-host/src/encode/linux/vaapi.rs @@ -195,13 +195,8 @@ unsafe fn open_vaapi_encoder_mode( video.set_frame_rate(Some(Rational(fps as i32, 1))); video.set_bit_rate(bitrate_bps as usize); video.set_max_bit_rate(bitrate_bps as usize); // == target → vaapi_encode picks CBR when supported - let vbv_frames = std::env::var("PUNKTFUNK_VBV_FRAMES") - .ok() - .and_then(|s| s.parse::().ok()) - .filter(|v| v.is_finite() && *v > 0.0) - .unwrap_or(1.0); - let vbv_bits = - ((bitrate_bps as f64 / fps.max(1) as f64) * vbv_frames as f64).clamp(1.0, i32::MAX as f64); + let vbv_bits = ((bitrate_bps as f64 / fps.max(1) as f64) * crate::encode::vbv_frames_env()) + .clamp(1.0, i32::MAX as f64); video.set_max_b_frames(0); let raw = video.as_mut_ptr(); (*raw).rc_buffer_size = vbv_bits as i32; diff --git a/crates/punktfunk-host/src/encode/windows/ffmpeg_win.rs b/crates/punktfunk-host/src/encode/windows/ffmpeg_win.rs index ebbefd4a..39fd3da7 100644 --- a/crates/punktfunk-host/src/encode/windows/ffmpeg_win.rs +++ b/crates/punktfunk-host/src/encode/windows/ffmpeg_win.rs @@ -191,13 +191,8 @@ unsafe fn open_win_encoder( video.set_frame_rate(Some(Rational(fps as i32, 1))); video.set_bit_rate(bitrate_bps as usize); video.set_max_bit_rate(bitrate_bps as usize); // target == max → CBR - let vbv_frames = std::env::var("PUNKTFUNK_VBV_FRAMES") - .ok() - .and_then(|s| s.parse::().ok()) - .filter(|v| v.is_finite() && *v > 0.0) - .unwrap_or(1.0); - let vbv_bits = - ((bitrate_bps as f64 / fps.max(1) as f64) * vbv_frames as f64).clamp(1.0, i32::MAX as f64); + let vbv_bits = ((bitrate_bps as f64 / fps.max(1) as f64) * crate::encode::vbv_frames_env()) + .clamp(1.0, i32::MAX as f64); video.set_max_b_frames(0); let raw = video.as_mut_ptr(); (*raw).rc_buffer_size = vbv_bits as i32;