From 9ebffac8af30e8877e2a700094adc3d5470b99fb Mon Sep 17 00:00:00 2001 From: selikhov Date: Sat, 3 Oct 2026 06:35:27 +0300 Subject: [PATCH] voelin-media: give av1_vaapi a two-second rate-control buffer The measurements on the RX 7900 GRE had av1_vaapi as the one backend that did not hold its bitrate: 3.5 % over at 1080p60 / 6 Mbit/s and 7.9 % over at 1440p60 / 10 Mbit/s, on the desktop pattern, every frame encoded. A stream that keeps sending more than the estimate allows is answered by the congestion control with loss and a lower target. Measured directly on the encoder, 600 frames after 120 of warm-up: `maxrate`, `rc_mode`, `blbrc` and the QP bounds change nothing; only the buffer does. With twice the bitrate as `bufsize` it lands at -0.8 % (1440p60), -0.2 % (1080p60) and -1.2 % (720p30 / 2 Mbit/s), no frame skipped, the largest frame 68 KB against 64 KB before (h264_vaapi's largest at the same settings is 86 KB). Every other backend keeps the one-second buffer it was within 2 % with. Co-Authored-By: Claude Opus 5.5 --- crates/voelin-media/src/ffmpeg/encoder.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/voelin-media/src/ffmpeg/encoder.rs b/crates/voelin-media/src/ffmpeg/encoder.rs index 72df3b9..d2f5757 100644 --- a/crates/voelin-media/src/ffmpeg/encoder.rs +++ b/crates/voelin-media/src/ffmpeg/encoder.rs @@ -806,7 +806,15 @@ impl FfmpegEncoder { // SVT-AV1 takes CBR from its own `rc=2` and rejects a maximum // that is not above the target. generic("maxrate", if self.spec.name == "libsvtav1" { 0 } else { bitrate }), - generic("bufsize", bitrate), + // A one-second buffer, except for VA-API AV1: with one second + // Mesa's rate control overshot by 3.5 % at 1080p60 / 6 Mbit/s and + // 7.9 % at 1440p60 / 10 Mbit/s (RX 7900 GRE, desktop pattern); + // with two it lands within 1.2 % at both and at 720p30, no frame + // skipped, the largest 68 KB against 64 KB at 1440p60. + generic( + "bufsize", + u64::from(bitrate) * if self.spec.name == "av1_vaapi" { 2 } else { 1 }, + ), generic("g", gop), generic("bf", 0), generic("colorspace", "smpte170m"),