Compare commits

..
3 Commits
Author SHA1 Message Date
VallierDevandClaude Opus 5.5 15bb35573d Release v0.1.8
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 12:12:31 +08:00
VallierDevandClaude Opus 5.5 6dda2e16a4 x264: VBV buffer of one second of bitrate so large keyframes fit (#8)
The 500 kbit cap left a 3296x2036 IDR (~130 KB at the 2M preset) no room, so
x264 emitted near-grey keyframes that sharpened over each 0.5 s GOP. Reproduced
with a static 3296x2036 desktop-like image at the 2M preset over 6 s: 250k and
1000k buffers produce grey keyframes (154/360 frames at 1000k), 2000k and 4000k
none. NVENC ull and VAAPI keep the small low-latency buffer. Thanks to
@liangjiahui01 for the analysis.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 12:12:16 +08:00
VallierDevandClaude Opus 5.5 a01fd39f06 Try NVENC only when an NVIDIA driver is present (#10); document the Hyprland screencopy frame-rate cap (#9)
ffmpeg lists h264_nvenc even without NVIDIA hardware, so AMD/Intel hosts ran a
doomed NVENC process before every libx264 stream. UU_VIDEO_ENCODER=nvenc forces it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-15 12:06:57 +08:00
7 changed files with 62 additions and 19 deletions

No files matched your search

+1 -1
View File
@@ -108,7 +108,7 @@ viewer does not reconnect them automatically.
| `UU_INPUT_BACKEND` | `auto` (uinput on Wayland/portal when `/dev/uinput` is accessible, udev `uaccess` rule in README) / `uinput` / `native`. X11 keeps XTest (held-key autorepeat handling) |
| `UU_TERMINAL_SHORTCUTS=0` | disable Ctrl+V → Ctrl+Shift+V in focused X11 terminals (Mac Cmd and Ctrl both arrive as VK_LCONTROL) |
| `contrib/virtual-desktop/` | Xvfb + session (`UU_VIRTUAL_SESSION`, `UU_VIRTUAL_BUS=user|private`) for monitorless hosts; serve it with `DISPLAY=:99` |
| `UU_VIDEO_ENCODER` | `cpu`: libx264; `vaapi`: explicit Intel/AMD; unset: NVENC→CPU |
| `UU_VIDEO_ENCODER` | `cpu`: libx264; `vaapi`: explicit Intel/AMD; `nvenc`: force; unset: NVENC→CPU only if `/proc/driver/nvidia/version` or `/dev/nvidia0` exists, else CPU (#10) |
| `UU_FFMPEG_ROOT` | FFmpeg prefix (`bin/ffmpeg`, libs in `lib/x86_64-linux-gnu`) |
| `UU_AUDIO=0`, `UU_AUDIO_SOURCE` | disable sound / choose the Pulse source (default `@DEFAULT_MONITOR@`) |
| `UU_LOGIN_WINDOW=0` | don't auto-open the login window |
Generated
+1 -1
View File
@@ -2649,7 +2649,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uu-remote-linux"
version = "0.1.7"
version = "0.1.8"
dependencies = [
"base64 0.22.1",
"bytes",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "uu-remote-linux"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
authors = ["uu-remote-linux contributors"]
description = "Unofficial Linux host for NetEase UU Remote: control a Linux desktop from the official clients"
+2 -2
View File
@@ -64,7 +64,7 @@ Apart from GNOME on X11, these desktops have been tested in virtual machines so
real hardware, please [open an issue](../../issues) with your distribution, desktop, GPU and the relevant lines from
`journalctl --user -u uuremote-native.service`.
Wayland limits: single screen, fixed resolution. The portal backend does not support screen wake or
Wayland limits: single screen, fixed resolution. The native Hyprland backend captures via shm screencopy, so the frame rate is bounded by the compositor (about 16–22 fps measured at 2560x1600) and the viewer fps option has no effect. The portal backend does not support screen wake or
dynamic resolution yet; the clipboard syncs while the viewer's remote window has focus. On the first connection the desktop asks for "Remote Desktop / Screen Sharing"
permission; the permission is remembered once granted.
@@ -203,7 +203,7 @@ Common environment variables:
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` / `kms` (experimental feature) / `none` (headless) |
| `UU_INPUT_BACKEND` | `auto` (default: uinput on Wayland when accessible) / `uinput` / `native` |
| `UU_TERMINAL_SHORTCUTS=0` | Disable the Ctrl+V paste rewrite in terminal windows |
| `UU_VIDEO_ENCODER` | `cpu`: libx264; `vaapi`: opt-in Intel/AMD; unset: existing NVENC→CPU |
| `UU_VIDEO_ENCODER` | `cpu`: libx264; `vaapi`: opt-in Intel/AMD; `nvenc`: force NVENC; unset: NVENC only when an NVIDIA driver is loaded, else CPU |
| `UU_FFMPEG_ROOT` | Use FFmpeg from this prefix |
| `UU_AUDIO=0` | Disable sound; `UU_AUDIO_SOURCE` picks the PulseAudio source |
| `UU_LOGIN_WINDOW=0` | Do not open the login window automatically when credentials are missing |
+2 -2
View File
@@ -59,7 +59,7 @@
除 GNOME(X11)外,其余桌面目前都是在虚拟机里测试的。如果你在真机上遇到问题,欢迎[提交 issue](../../issues),
请附上发行版、桌面环境、显卡型号和 `journalctl --user -u uuremote-native.service` 里的相关日志。
Wayland 下的限制:只支持单屏、固定分辨率;portal 后端暂不支持唤醒屏幕和动态分辨率;剪贴板只在控制端的远控窗口处于前台时同步。
Wayland 下的限制:只支持单屏、固定分辨率;Hyprland 原生后端通过 shm screencopy 截屏,帧率受合成器限制(2560x1600 实测约 16~22 帧),控制端的帧率选项不生效;portal 后端暂不支持唤醒屏幕和动态分辨率;剪贴板只在控制端的远控窗口处于前台时同步。
首次连接时,桌面会弹窗请求「远程桌面 / 屏幕共享」授权,同意后会记住授权。
## 尚未实现 / 不支持
@@ -193,7 +193,7 @@ systemctl --user restart uuremote-native.service
| `UU_DESKTOP_BACKEND` | `auto` / `x11` / `wayland` / `portal` / `kms`(实验性特性) / `none`(无头模式) |
| `UU_INPUT_BACKEND` | `auto`(默认,Wayland 下可用时用 uinput)/ `uinput` / `native` |
| `UU_TERMINAL_SHORTCUTS=0` | 关闭终端窗口里的 Ctrl+V 粘贴转换 |
| `UU_VIDEO_ENCODER` | `cpu` 强制 CPU;`vaapi` 显式启用 Intel/AMD 硬编;未设置时保留 NVENC→CPU |
| `UU_VIDEO_ENCODER` | `cpu` 强制 CPU;`vaapi` 显式启用 Intel/AMD 硬编;`nvenc` 强制 NVENC;未设置时检测到 NVIDIA 驱动才用 NVENC,否则用 CPU |
| `UU_FFMPEG_ROOT` | 使用指定目录下的 FFmpeg |
| `UU_AUDIO=0` | 关闭声音转发;`UU_AUDIO_SOURCE` 指定 PulseAudio 采集源 |
| `UU_LOGIN_WINDOW=0` | 凭证缺失时不自动弹出登录窗口 |
+20
View File
@@ -0,0 +1,20 @@
修复大分辨率 CPU 编码时画面周期性变灰,以及非 NVIDIA 机器上每次建流都白跑一次 NVENC。/ Fixes grey keyframes on large CPU-encoded desktops and needless NVENC attempts on non-NVIDIA hosts.
### 修复 / Fixed
- **大分辨率 CPU 编码画面周期性变灰**(#8,感谢 @liangjiahui01 的详细分析):libx264 的 VBV 缓冲原来最多 500 kbit,
3296×2036 这类大屏的关键帧放不下,x264 只能输出近乎纯灰的关键帧再逐步补清晰。现在 CPU 编码的缓冲改为 1 秒的码率
(500k~8000k),NVENC 和 VAAPI 不变。用 3296×2036 静态画面、高清 2M 档复现验证:原来每个关键帧都变灰,修复后不再出现。
x264 VBV buffer is now one second of bitrate; NVENC/VAAPI unchanged.
- **非 NVIDIA 机器每次建流都先试一次 NVENC**(#10,感谢 @hiclaw):`ffmpeg -encoders` 在没有 N 卡时也会列出 `h264_nvenc`,
所以以前 AMD/Intel 机器上每次连接或切换画质都会先启动一个注定失败的 NVENC 编码。现在未设置 `UU_VIDEO_ENCODER` 时,
只有检测到 NVIDIA 驱动才尝试 NVENC,否则直接用 CPU 编码;新增 `UU_VIDEO_ENCODER=nvenc` 可以强制使用。
NVENC is only tried when an NVIDIA driver is present; `UU_VIDEO_ENCODER=nvenc` forces it.
### 文档 / Docs
- README 的 Wayland 限制里写明:Hyprland 原生后端通过 shm screencopy 截屏,帧率受合成器限制(2560×1600 实测约 16~22 帧),
控制端的帧率选项不生效(#9,后续会尝试 dmabuf 零拷贝)。
### 下载 / Download
`uu-remote-linux-v0.1.8-x86_64-linux.tar.gz`:X11 版可执行文件(x86_64,glibc ≥ 2.35),附带 `contrib/`。
**非官方项目,与网易无关。** / **Unofficial, not affiliated with NetEase.**
+35 -12
View File
@@ -56,12 +56,18 @@ const RTP_CLOCK: u64 = 90_000;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum Encoder { Cpu, Nvenc, Vaapi }
impl Encoder {
pub(crate) fn requested() -> Self { Self::from_setting(std::env::var("UU_VIDEO_ENCODER").ok().as_deref()) }
fn from_setting(value: Option<&str>) -> Self {
match value { Some("cpu") => Self::Cpu, Some("vaapi") => Self::Vaapi, _ => Self::Nvenc }
pub(crate) fn requested() -> Self { Self::from_setting(std::env::var("UU_VIDEO_ENCODER").ok().as_deref(), nvidia_present()) }
/// Unset/auto tries NVENC only with an NVIDIA driver loaded: `ffmpeg -encoders` lists h264_nvenc
/// on any machine, so without this every stream start first ran a doomed NVENC process (#10).
fn from_setting(value: Option<&str>, nvidia: bool) -> Self {
match value { Some("cpu") => Self::Cpu, Some("vaapi") => Self::Vaapi, Some("nvenc") => Self::Nvenc,
_ => if nvidia { Self::Nvenc } else { Self::Cpu } }
}
pub(crate) fn name(self) -> &'static str { match self { Self::Cpu => "libx264", Self::Nvenc => "h264_nvenc", Self::Vaapi => "h264_vaapi" } }
}
fn nvidia_present() -> bool {
std::path::Path::new("/proc/driver/nvidia/version").exists() || std::path::Path::new("/dev/nvidia0").exists()
}
pub(crate) fn vaapi_device() -> String { std::env::var("UU_VAAPI_DEVICE").unwrap_or_else(|_| "/dev/dri/renderD128".into()) }
/// NV12 conversion must precede upload; scaling runs on software frames, before hwupload.
@@ -70,7 +76,7 @@ fn vaapi_filter(output: Option<(u32, u32)>) -> String {
format!("{scale}format=nv12,hwupload")
}
fn vaapi_options(settings: &VideoSettings, gop: &str) -> Vec<String> {
let (maxrate, buffer) = rate_args(settings);
let (maxrate, buffer) = rate_args(settings, Encoder::Vaapi);
// QVBR is not uniformly available on Intel/AMD drivers. VBR + qmin sets a quality
// floor while retaining the viewer's bitrate cap; unsupported drivers fall back to CPU.
["-c:v", "h264_vaapi", "-profile:v", "constrained_baseline", "-g", gop, "-bf", "0",
@@ -182,10 +188,16 @@ async fn read_inprocess(
/// Rate-control arguments: constant quality capped at 30M (自动), or capped at the viewer's
/// chosen bitrate. The VBV buffer stays at most 500k so a cap never adds queueing latency.
fn rate_args(settings: &VideoSettings) -> (String, String) {
/// VBV buffer in kbit. NVENC ull and VAAPI keep the small low-latency buffer; libx264 needs room for a
/// 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 { (max_kbps / 8).clamp(100, 500) }
}
fn rate_args(settings: &VideoSettings, encoder: Encoder) -> (String, String) {
let max_kbps = settings.max_kbps().unwrap_or(30_000);
let buffer_kbits = (max_kbps / 8).clamp(100, 500);
(format!("{max_kbps}k"), format!("{buffer_kbits}k"))
(format!("{max_kbps}k"), format!("{}k", buffer_kbits(max_kbps, encoder)))
}
async fn read_encoder_with(
@@ -206,7 +218,7 @@ async fn read_encoder_with(
display: display.clone(), input: size, output: settings.output, fps: u32::from(settings.fps),
gop: gop_frames(settings.fps, true) as u32, cq: settings.cq() as u32,
target_bps: settings.max_kbps().map_or(16_000, |k| i64::from(k) * 3 / 4) * 1000,
max_bps: max_kbps * 1000, buffer_bits: (max_kbps / 8).clamp(100, 500) * 1000, encoder,
max_bps: max_kbps * 1000, buffer_bits: i64::from(buffer_kbits(max_kbps as u32, encoder)) * 1000, encoder,
damage: crate::inproc_encoder::damage_enabled(),
};
log::info!("Desktop encoder: display={} source={}x{} output={:?} fps={} cq={} maxrate={}k encoder={} pipeline=in-process",
@@ -219,7 +231,7 @@ async fn read_encoder_with(
let fps = settings.fps.to_string();
// Keep the IDR interval at 2 s whatever the frame rate.
let gop = gop_frames(settings.fps, false).to_string();
let (maxrate, bufsize) = rate_args(&settings);
let (maxrate, bufsize) = rate_args(&settings, encoder);
let cq = settings.cq().to_string();
let target = settings.max_kbps().map_or("16M".to_string(), |k| format!("{}k", k * 3 / 4));
log::info!("Desktop encoder: display={} source={} output={:?} fps={} cq={} maxrate={} encoder={} low_latency=true",display,size,settings.output,settings.fps,cq,maxrate,encoder.name());
@@ -452,11 +464,22 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<TrackLocalSta
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn x264_buffer_fits_keyframes() {
assert_eq!(buffer_kbits(2000, Encoder::Nvenc), 250);
assert_eq!(buffer_kbits(2000, Encoder::Vaapi), 250);
assert_eq!(buffer_kbits(2000, Encoder::Cpu), 2000);
assert_eq!(buffer_kbits(300, Encoder::Cpu), 500);
assert_eq!(buffer_kbits(30_000, Encoder::Cpu), 8000);
}
#[test]
fn vaapi_is_explicit_and_upload_follows_scale() {
assert_eq!(Encoder::from_setting(None), Encoder::Nvenc);
assert_eq!(Encoder::from_setting(Some("cpu")), Encoder::Cpu);
assert_eq!(Encoder::from_setting(Some("vaapi")), Encoder::Vaapi);
assert_eq!(Encoder::from_setting(None, true), Encoder::Nvenc);
assert_eq!(Encoder::from_setting(None, false), Encoder::Cpu);
assert_eq!(Encoder::from_setting(Some("nvenc"), false), Encoder::Nvenc);
assert_eq!(Encoder::from_setting(Some("cpu"), true), Encoder::Cpu);
assert_eq!(Encoder::from_setting(Some("vaapi"), true), Encoder::Vaapi);
assert_eq!(vaapi_filter(None), "format=nv12,hwupload");
assert_eq!(vaapi_filter(Some((1280,720))), "scale=1280:720:flags=bilinear,format=nv12,hwupload");
let options = vaapi_options(&VideoSettings::default(), "30");