mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 08:50:40 +01:00
nvenc: opt-in UU_NVENC_BUFFER_MS VBV buffer for high-resolution keyframes (#103)
The 100-500 kbit NVENC default squeezes a 1440p IDR into ~62 KB, so the picture blurs and sharpens once per GOP. Share the VAAPI buffer parser so UU_NVENC_BUFFER_MS (10-1000 ms of the bitrate cap) applies to the FFmpeg pipeline and the in-process engine; default unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
648eeca03d
commit
ba82bc432a
3 files changed
+20
-17
No files matched your search
@@ -348,6 +348,7 @@ Common environment variables:
|
||||
| `UU_TERMINAL_SHORTCUTS=0` | Disable the Ctrl+V paste rewrite in terminal windows |
|
||||
| `UU_VIDEO_ENCODER` | `cpu`: libx264; `vaapi`: opt-in Intel/AMD; `nvenc`: force NVENC; unset or `auto`: a background probe (one synthetic IDR per candidate, 3 s each). With an NVIDIA driver the order is NVENC then CPU; without one the only candidate is CPU and the probe is skipped. A session that starts before the probe finishes uses the previous rule (NVENC if NVIDIA is present, else CPU). On a self-built `--features inproc-av` binary, a process-only failure of NVENC when the in-process engine would try it first on X11 is logged `native_unprobed` and keeps the previous NVENC choice (Wayland, portal, and KMS fall back to CPU). The skipped CPU-only probe is logged `not probed (only candidate)`. A successful probe and that CPU-only skip stay cached while NVIDIA presence matches the report. A later desktop connection whose presence differs starts one background re-probe and still uses the cached encoder until the new result is stored. A hardware-candidate failure (NVENC failed, CPU chosen) is kept for 10 minutes; the next desktop connection after that starts the same re-probe and still uses the cached encoder until the new result is stored. Explicit `cpu` / `vaapi` / `nvenc` does not start the probe. Another failure restarts the 10 minutes. `native_unprobed` is not a temporary failure. A non-`auto` `video_encoder` in `host_settings.json` wins. VAAPI stays out of auto until #33 |
|
||||
| `UU_VAAPI_BUFFER_MS` | VAAPI VBV buffer in ms (10-1000, VAAPI only); raise it when keyframes are squeezed into a blur at high resolution |
|
||||
| `UU_NVENC_BUFFER_MS` | NVENC VBV buffer in ms (10-1000, NVENC only, including the in-process engine); the default is 100-500 kbit, set `1000` when high-resolution keyframes blur and flicker once per GOP (#103) |
|
||||
| `UU_FFMPEG_ROOT` | Use FFmpeg from this prefix |
|
||||
| `UU_AUDIO=0` | Disable sound; `UU_AUDIO_SOURCE` picks the PulseAudio source |
|
||||
| `UU_REMOTE_ASSIST=0` | Disable remote assistance (no guest assistance before sign-in either) |
|
||||
|
||||
@@ -316,6 +316,7 @@ systemctl --user restart uuremote-native.service
|
||||
| `UU_TERMINAL_SHORTCUTS=0` | 关闭终端窗口里的 Ctrl+V 粘贴转换 |
|
||||
| `UU_VIDEO_ENCODER` | `cpu` 强制 CPU;`vaapi` 显式启用 Intel/AMD 硬编;`nvenc` 强制 NVENC;未设置或 `auto` 时后台探测(每个候选编码一帧,限时 3 秒)。有 NVIDIA 驱动时顺序是 NVENC → CPU;没有 NVIDIA 时只有 CPU,不探测。探测未完成就建流则沿用旧规则(有 NVIDIA 用 NVENC,否则 CPU)。自行编译的 `--features inproc-av` 上,仅 X11 会先走进程内引擎:外部 FFmpeg 探测失败时记为 `native_unprobed`,沿用旧规则(NVENC);Wayland、portal、KMS 回退 CPU。只有 CPU 时跳过探测,记为 `not probed (only candidate)`。探测成功和这种只含 CPU 的跳过会缓存到 NVIDIA 是否存在发生变化为止(`/proc/driver/nvidia/version` 或 `/dev/nvidia0`)。之后的桌面连接在后台再探测一次(不挡住这一路,仍用缓存的编码器)。NVENC 探测失败、选用 CPU 时只缓存 10 分钟;到期后下一次桌面连接同样在后台再探测一次,再次失败则重新计 10 分钟。显式 `cpu` / `vaapi` / `nvenc` 不启动探测。`native_unprobed` 不算失败缓存。优先级低于 `host_settings.json` 里非 `auto` 的 `video_encoder`。VAAPI 要等 #33 解决后才会进入 auto |
|
||||
| `UU_VAAPI_BUFFER_MS` | VAAPI 的 VBV 缓冲(10–1000 ms,仅 `UU_VIDEO_ENCODER=vaapi` 时生效);高分辨率下关键帧被压糊时用它换稳定画质 |
|
||||
| `UU_NVENC_BUFFER_MS` | NVENC 的 VBV 缓冲(10–1000 ms,仅 NVENC 生效,含进程内引擎);默认 100–500 kbit,1440p 等高分辨率下关键帧被压糊、按 GOP 周期闪烁时设 `1000`(#103) |
|
||||
| `UU_FFMPEG_ROOT` | 使用指定目录下的 FFmpeg |
|
||||
| `UU_AUDIO=0` | 关闭声音转发;`UU_AUDIO_SOURCE` 指定 PulseAudio 采集源 |
|
||||
| `UU_LOGIN_WINDOW=0` | 凭证缺失时不自动弹出登录窗口 |
|
||||
|
||||
+18
-17
@@ -780,19 +780,20 @@ async fn read_inprocess(
|
||||
/// whole IDR frame, otherwise large desktops get near-grey keyframes that sharpen over the GOP (#8).
|
||||
/// Half a second of bitrate still starved repeated 0.5 s-GOP keyframes at 3296x2036/2M; one second did not.
|
||||
fn buffer_kbits(max_kbps: u32, encoder: Encoder) -> u32 {
|
||||
if encoder == Encoder::Cpu { max_kbps.clamp(500, 8000) }
|
||||
else if encoder == Encoder::Vaapi {
|
||||
let requested = std::env::var("UU_VAAPI_BUFFER_MS").ok();
|
||||
vaapi_buffer_kbits(max_kbps, requested.as_deref()).unwrap_or((max_kbps / 8).clamp(100, 500))
|
||||
}
|
||||
else { (max_kbps / 8).clamp(100, 500) }
|
||||
let env = match encoder {
|
||||
Encoder::Cpu => return max_kbps.clamp(500, 8000),
|
||||
Encoder::Vaapi => "UU_VAAPI_BUFFER_MS",
|
||||
Encoder::Nvenc => "UU_NVENC_BUFFER_MS",
|
||||
};
|
||||
let requested = std::env::var(env).ok();
|
||||
buffer_ms_kbits(max_kbps, requested.as_deref()).unwrap_or((max_kbps / 8).clamp(100, 500))
|
||||
}
|
||||
|
||||
/// Opt-in VAAPI VBV buffer: `码率上限 × 毫秒 / 1000` for `UU_VAAPI_BUFFER_MS` in 10-1000 ms.
|
||||
/// The 100-500 kbit default is sized for NVENC; VAAPI quantizes a whole desktop keyframe when
|
||||
/// the buffer is that small, which reads as a blur that sharpens over each GOP (#42).
|
||||
/// Opt-in hardware VBV buffer: `码率上限 × 毫秒 / 1000` for `UU_VAAPI_BUFFER_MS` /
|
||||
/// `UU_NVENC_BUFFER_MS` in 10-1000 ms. With the 100-500 kbit default the encoder quantizes a
|
||||
/// whole desktop keyframe, which reads as a blur that sharpens over each GOP (#42 VAAPI, #103 NVENC).
|
||||
/// Unset, out of range or unparsable values keep the default buffer.
|
||||
fn vaapi_buffer_kbits(max_kbps: u32, value: Option<&str>) -> Option<u32> {
|
||||
fn buffer_ms_kbits(max_kbps: u32, value: Option<&str>) -> Option<u32> {
|
||||
let ms = value?.trim().parse::<u32>().ok().filter(|ms| (10..=1000).contains(ms))?;
|
||||
Some((max_kbps.saturating_mul(ms) / 1000).max(1))
|
||||
}
|
||||
@@ -1570,17 +1571,17 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vaapi_buffer_env_is_opt_in_and_bounded() {
|
||||
assert_eq!(vaapi_buffer_kbits(30_000, None), None);
|
||||
assert_eq!(vaapi_buffer_kbits(30_000, Some("250")), Some(7500));
|
||||
assert_eq!(vaapi_buffer_kbits(30_000, Some(" 10 ")), Some(300));
|
||||
assert_eq!(vaapi_buffer_kbits(30_000, Some("1000")), Some(30_000));
|
||||
fn hw_buffer_env_is_opt_in_and_bounded() {
|
||||
assert_eq!(buffer_ms_kbits(30_000, None), None);
|
||||
assert_eq!(buffer_ms_kbits(30_000, Some("250")), Some(7500));
|
||||
assert_eq!(buffer_ms_kbits(30_000, Some(" 10 ")), Some(300));
|
||||
assert_eq!(buffer_ms_kbits(30_000, Some("1000")), Some(30_000));
|
||||
// Out of the documented range, empty or unparsable keeps the default buffer.
|
||||
for value in ["", "9", "1001", "0", "abc", "-250", "250ms"] {
|
||||
assert_eq!(vaapi_buffer_kbits(30_000, Some(value)), None, "{value}");
|
||||
assert_eq!(buffer_ms_kbits(30_000, Some(value)), None, "{value}");
|
||||
}
|
||||
// A tiny cap must not produce a zero-sized buffer.
|
||||
assert_eq!(vaapi_buffer_kbits(1, Some("10")), Some(1));
|
||||
assert_eq!(buffer_ms_kbits(1, Some("10")), Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user