inproc-av: 4:4:4 on the native NVENC engine (#76, #77)

H.264 High 4:4:4 / HEVC FRExt with chromaFormatIDC 3 and AQ off when 真彩 is requested; GPUs without YUV444 encode fail the capability check and fall back. full_chroma_available() no longer excludes the in-process path. UU_PROBE_CHROMA=444 for the probe.

Co-authored-by: ferstar <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-21 08:24:32 -07:00
1 parent 76941459cc
commit 059a3b1bb8
8 files changed
+45 -20

No files matched your search

+2 -2
View File
@@ -161,7 +161,7 @@ every 60 s.
Diagnostic subcommands: `doctor` (paste-safe report: session, selected backend, engine plugins, uinput, encoders, Diagnostic subcommands: `doctor` (paste-safe report: session, selected backend, engine plugins, uinput, encoders,
default codec, sign-in/service state; booleans and names only), `login [--no-gui]`, `unlock-check` (password on stdin, prints only accepted/rejected), default codec, sign-in/service state; booleans and names only), `login [--no-gui]`, `unlock-check` (password on stdin, prints only accepted/rejected),
`desktop-probe [new.png]`, `desktop-video-probe` (`UU_PROBE_FPS`, `UU_PROBE_FRAMES`, `UU_PROBE_QUALITY` 1-5 = viewer bitrate preset, 5 auto; `UU_PROBE_INPUT` fixed video/image sequence, `UU_PROBE_LOOP=1` repeats), `wayland-input-probe`, `clipboard-acceptance`, `desktop-probe [new.png]`, `desktop-video-probe` (`UU_PROBE_FPS`, `UU_PROBE_FRAMES`, `UU_PROBE_QUALITY` 1-5 = viewer bitrate preset, 5 auto; `UU_PROBE_CHROMA=444` 真彩; `UU_PROBE_INPUT` fixed video/image sequence, `UU_PROBE_LOOP=1` repeats), `wayland-input-probe`, `clipboard-acceptance`,
`portal-acceptance`, `help`. Unknown arguments exit with code 2. Builds up to v0.1.0 did **not** reject them and `portal-acceptance`, `help`. Unknown arguments exit with code 2. Builds up to v0.1.0 did **not** reject them and
started a second full host server instead, so check that a subcommand exists in the binary you run. started a second full host server instead, so check that a subcommand exists in the binary you run.
@@ -184,7 +184,7 @@ started a second full host server instead, so check that a subcommand exists in
5 Auto, 6 Custom. Resolution: 16/17 pixel size or 5/6, 10 resolution_type (3 = follow remote). 5 Auto, 6 Custom. Resolution: 16/17 pixel size or 5/6, 10 resolution_type (3 = follow remote).
Field 7 `chorma_format` (ChromaFormat 1 = 4:2:0, 3 = 4:4:4) is sent when 真彩 is toggled; ff_capture_setting versions Field 7 `chorma_format` (ChromaFormat 1 = 4:2:0, 3 = 4:4:4) is sent when 真彩 is toggled; ff_capture_setting versions
are cumulative (3 CHROMA_SAMPLING, 4 CUSTOM_BITRATE, 5 DPI_SCALE, 6 HDR). 4:4:4 = NVENC `high444p` / x264 `high444` are cumulative (3 CHROMA_SAMPLING, 4 CUSTOM_BITRATE, 5 DPI_SCALE, 6 HDR). 4:4:4 = NVENC `high444p` / x264 `high444`
with `yuv444p`; VAAPI and the in-process NVENC engine stay 4:2:0. with `yuv444p`; the in-process NVENC engine uses High 4:4:4 / HEVC FRExt (AQ off); VAAPI stays 4:2:0.
Reply `RpcResponse{2 CaptureSettingResponse{}}` (no errors = applied) and send Message 25 CaptureSettingSync Reply `RpcResponse{2 CaptureSettingResponse{}}` (no errors = applied) and send Message 25 CaptureSettingSync
(field 3 = the chroma actually encoded). (field 3 = the chroma actually encoded).
- ConnectOptions field 4 `decoder_cap_list` = DecoderCap {1 fps, 2 codec_type (1 H264, 2 H265), 3 width, 4 height, - ConnectOptions field 4 `decoder_cap_list` = DecoderCap {1 fps, 2 codec_type (1 H264, 2 H265), 3 width, 4 height,
+1 -1
View File
@@ -117,7 +117,7 @@ Switching reuses one video track and pauses input until the new source sends a f
| Feature | Status | | Feature | Status |
|---|---| |---|---|
| Switching between multiple monitors | Experimental on native Hyprland Wayland; see above | | Switching between multiple monitors | Experimental on native Hyprland Wayland; see above |
| True color (4:4:4) | Supported (v0.1.15): the default FFmpeg pipeline with NVENC / libx264 encodes H.264 High 4:4:4; VAAPI and `inproc-av` stay 4:2:0 and report that to the client | | True color (4:4:4) | Supported (v0.1.15): the default FFmpeg pipeline with NVENC / libx264 encodes H.264 High 4:4:4; `inproc-av` native NVENC encodes H.264 High 4:4:4 / HEVC FRExt; VAAPI stays 4:2:0 and reports that to the client |
| HDR | Not implemented | | HDR | Not implemented |
| Super screen / virtual display | Not implemented | | Super screen / virtual display | Not implemented |
| Privacy screen on the host | Not implemented | | Privacy screen on the host | Not implemented |
+1 -1
View File
@@ -103,7 +103,7 @@ GNOME Portal 的控制通道不再等待授权窗口或第一帧画面:先通
| 功能 | 状态 | | 功能 | 状态 |
|---|---| |---|---|
| 多显示器切换 | Hyprland 原生 Wayland 后端实验性支持,见上文 | | 多显示器切换 | Hyprland 原生 Wayland 后端实验性支持,见上文 |
| 真彩(4:4:4) | 支持(v0.1.15):NVENC / libx264 的默认 FFmpeg 管线输出 H.264 High 4:4:4;VAAPI 和 `inproc-av` 管线仍为 4:2:0,并如实回报给客户端 | | 真彩(4:4:4) | 支持(v0.1.15):NVENC / libx264 的默认 FFmpeg 管线输出 H.264 High 4:4:4;`inproc-av` 原生 NVENC 输出 H.264 High 4:4:4 / HEVC FRExt;VAAPI 管线仍为 4:2:0,并如实回报给客户端 |
| HDR | 未实现 | | HDR | 未实现 |
| 超级屏 / 虚拟显示器 | 未实现 | | 超级屏 / 虚拟显示器 | 未实现 |
| 被控端防窥模式 | 未实现 | | 被控端防窥模式 | 未实现 |
+2
View File
@@ -76,6 +76,7 @@ fn main() {
max_bps: i64, max_bps: i64,
buffer_bits: i64, buffer_bits: i64,
is_hevc: i32, is_hevc: i32,
chroma_444: i32,
} }
let cfg = NvencConfigFFI { let cfg = NvencConfigFFI {
@@ -88,6 +89,7 @@ fn main() {
max_bps: 30_000_000, max_bps: 30_000_000,
buffer_bits: 500_000, buffer_bits: 500_000,
is_hevc: 1, // H.265 / HEVC is_hevc: 1, // H.265 / HEVC
chroma_444: i32::from(std::env::var("UU_BENCH_CHROMA").as_deref() == Ok("444")),
}; };
println!("[2] In-process NVENC H.265 encoding"); println!("[2] In-process NVENC H.265 encoding");
+22 -7
View File
@@ -233,23 +233,38 @@ NvencEngine* nvenc_create(const NvencConfig* config) {
enc_cfg.rcParams.maxBitRate = (uint32_t)(config->max_bps > 0 ? config->max_bps : 15000000); enc_cfg.rcParams.maxBitRate = (uint32_t)(config->max_bps > 0 ? config->max_bps : 15000000);
enc_cfg.rcParams.vbvBufferSize = (uint32_t)(config->buffer_bits > 0 ? config->buffer_bits : (config->max_bps > 0 ? config->max_bps / 10 : 1500000)); enc_cfg.rcParams.vbvBufferSize = (uint32_t)(config->buffer_bits > 0 ? config->buffer_bits : (config->max_bps > 0 ? config->max_bps / 10 : 1500000));
enc_cfg.rcParams.targetQuality = (uint8_t)(config->cq > 0 ? config->cq : 28); enc_cfg.rcParams.targetQuality = (uint8_t)(config->cq > 0 ? config->cq : 28);
enc_cfg.rcParams.enableAQ = 1;
// Temporal AQ only where the hardware/codec reports it
NV_ENC_CAPS_PARAM caps_param; NV_ENC_CAPS_PARAM caps_param;
memset(&caps_param, 0, sizeof(caps_param)); memset(&caps_param, 0, sizeof(caps_param));
caps_param.version = NV_ENC_CAPS_PARAM_VER; caps_param.version = NV_ENC_CAPS_PARAM_VER;
caps_param.capsToQuery = NV_ENC_CAPS_SUPPORT_TEMPORAL_AQ;
int caps_val = 0; int caps_val = 0;
enc_cfg.rcParams.enableTemporalAQ = if (config->chroma_444) {
engine->fn.nvEncGetEncodeCaps(engine->encoder, codec_guid, &caps_param, &caps_val) == NV_ENC_SUCCESS && caps_val > 0; // GPUs without 4:4:4 encode fail here; the caller falls back to FFmpeg/libx264, which keep 4:4:4.
caps_param.capsToQuery = NV_ENC_CAPS_SUPPORT_YUV444_ENCODE;
if (engine->fn.nvEncGetEncodeCaps(engine->encoder, codec_guid, &caps_param, &caps_val) != NV_ENC_SUCCESS || caps_val <= 0) {
fprintf(stderr, "[nvenc] 4:4:4 encoding not supported for this codec\n");
goto fail;
}
// NVENC rejects AQ / temporal AQ in 4:4:4 mode.
enc_cfg.rcParams.enableAQ = 0;
enc_cfg.rcParams.enableTemporalAQ = 0;
} else {
enc_cfg.rcParams.enableAQ = 1;
// Temporal AQ only where the hardware/codec reports it
caps_param.capsToQuery = NV_ENC_CAPS_SUPPORT_TEMPORAL_AQ;
caps_val = 0;
enc_cfg.rcParams.enableTemporalAQ =
engine->fn.nvEncGetEncodeCaps(engine->encoder, codec_guid, &caps_param, &caps_val) == NV_ENC_SUCCESS && caps_val > 0;
}
if (engine->is_hevc) { if (engine->is_hevc) {
enc_cfg.profileGUID = NV_ENC_HEVC_PROFILE_MAIN_GUID; enc_cfg.profileGUID = config->chroma_444 ? NV_ENC_HEVC_PROFILE_FREXT_GUID : NV_ENC_HEVC_PROFILE_MAIN_GUID;
enc_cfg.encodeCodecConfig.hevcConfig.chromaFormatIDC = config->chroma_444 ? 3 : 1;
enc_cfg.encodeCodecConfig.hevcConfig.idrPeriod = enc_cfg.gopLength; enc_cfg.encodeCodecConfig.hevcConfig.idrPeriod = enc_cfg.gopLength;
enc_cfg.encodeCodecConfig.hevcConfig.repeatSPSPPS = 1; enc_cfg.encodeCodecConfig.hevcConfig.repeatSPSPPS = 1;
enc_cfg.encodeCodecConfig.hevcConfig.outputAUD = 1; enc_cfg.encodeCodecConfig.hevcConfig.outputAUD = 1;
} else { } else {
enc_cfg.profileGUID = NV_ENC_H264_PROFILE_BASELINE_GUID; enc_cfg.profileGUID = config->chroma_444 ? NV_ENC_H264_PROFILE_HIGH_444_GUID : NV_ENC_H264_PROFILE_BASELINE_GUID;
enc_cfg.encodeCodecConfig.h264Config.chromaFormatIDC = config->chroma_444 ? 3 : 1;
enc_cfg.encodeCodecConfig.h264Config.idrPeriod = enc_cfg.gopLength; enc_cfg.encodeCodecConfig.h264Config.idrPeriod = enc_cfg.gopLength;
enc_cfg.encodeCodecConfig.h264Config.repeatSPSPPS = 1; enc_cfg.encodeCodecConfig.h264Config.repeatSPSPPS = 1;
enc_cfg.encodeCodecConfig.h264Config.outputAUD = 1; enc_cfg.encodeCodecConfig.h264Config.outputAUD = 1;
+2 -1
View File
@@ -19,7 +19,8 @@ typedef struct {
int64_t target_bps; int64_t target_bps;
int64_t max_bps; int64_t max_bps;
int64_t buffer_bits; int64_t buffer_bits;
int is_hevc; // 1 = H.265, 0 = H.264 int is_hevc; // 1 = H.265, 0 = H.264
int chroma_444; // 1 = 4:4:4 (H.264 High 4:4:4 / HEVC FRExt), 0 = 4:2:0
} NvencConfig; } NvencConfig;
// Initialize and open an NVENC encoding session. Returns NULL on error. // Initialize and open an NVENC encoding session. Returns NULL on error.
+8 -2
View File
@@ -26,6 +26,7 @@ struct NvencConfigFFI {
max_bps: i64, max_bps: i64,
buffer_bits: i64, buffer_bits: i64,
is_hevc: libc::c_int, is_hevc: libc::c_int,
chroma_444: libc::c_int,
} }
extern "C" { extern "C" {
@@ -70,6 +71,8 @@ pub struct Config {
pub max_bps: i64, pub max_bps: i64,
pub buffer_bits: i64, pub buffer_bits: i64,
pub codec: crate::capture_setting::VideoCodec, pub codec: crate::capture_setting::VideoCodec,
/// ChromaFormat (capture_setting::CHROMA_444 = 4:4:4).
pub chroma: u64,
} }
pub fn disabled() -> bool { pub fn disabled() -> bool {
@@ -145,14 +148,16 @@ pub fn run(
0 0
}; };
let chroma_444 = libc::c_int::from(config.chroma == crate::capture_setting::CHROMA_444);
log::info!( log::info!(
"Initializing Native In-Process NVENC: {}x{}, {} fps, GOP {}, CQ {}, HEVC={}", "Initializing Native In-Process NVENC: {}x{}, {} fps, GOP {}, CQ {}, HEVC={}, 4:4:4={}",
width, width,
height, height,
config.fps, config.fps,
config.gop, config.gop,
config.cq, config.cq,
is_hevc == 1 is_hevc == 1,
chroma_444 == 1
); );
let ffi_cfg = NvencConfigFFI { let ffi_cfg = NvencConfigFFI {
@@ -165,6 +170,7 @@ pub fn run(
max_bps: config.max_bps, max_bps: config.max_bps,
buffer_bits: config.buffer_bits, buffer_bits: config.buffer_bits,
is_hevc, is_hevc,
chroma_444,
}; };
let mut capture = DamageCapture::open(&config.display) let mut capture = DamageCapture::open(&config.display)
+7 -6
View File
@@ -198,11 +198,9 @@ impl Encoder {
fn nvidia_present() -> bool { fn nvidia_present() -> bool {
std::path::Path::new("/proc/driver/nvidia/version").exists() || std::path::Path::new("/dev/nvidia0").exists() std::path::Path::new("/proc/driver/nvidia/version").exists() || std::path::Path::new("/dev/nvidia0").exists()
} }
/// 真彩 (4:4:4) needs the FFmpeg process pipeline with NVENC or libx264 (h264_vaapi and the /// 真彩 (4:4:4): NVENC (in-process or FFmpeg) and libx264; h264_vaapi is 4:2:0 only.
/// in-process encoder are 4:2:0 only). /// A GPU without 4:4:4 NVENC falls back to libx264, which keeps 4:4:4.
pub fn full_chroma_available() -> bool { pub fn full_chroma_available() -> bool {
#[cfg(feature = "inproc-av")]
if crate::inproc_encoder::selected(Encoder::requested()) { return false; }
Encoder::requested() != Encoder::Vaapi Encoder::requested() != Encoder::Vaapi
} }
@@ -618,7 +616,7 @@ async fn read_encoder_with(
display: display.clone(), input: size, output: settings.output, fps: u32::from(settings.fps), 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, 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, target_bps: settings.max_kbps().map_or(16_000, |k| i64::from(k) * 3 / 4) * 1000,
max_bps: max_kbps * 1000, buffer_bits: i64::from(buffer_for(&settings, encoder)) * 1000, codec: settings.codec, max_bps: max_kbps * 1000, buffer_bits: i64::from(buffer_for(&settings, encoder)) * 1000, codec: settings.codec, chroma: settings.chroma,
}; };
log::info!("Desktop encoder: display={} source={}x{} output={:?} fps={} cq={} maxrate={}k encoder={} pipeline=in-process", log::info!("Desktop encoder: display={} source={}x{} output={:?} fps={} cq={} maxrate={}k encoder={} pipeline=in-process",
display,size.0,size.1,settings.output,settings.fps,config.cq,max_kbps,encoder.name_for(settings.codec)); display,size.0,size.1,settings.output,settings.fps,config.cq,max_kbps,encoder.name_for(settings.codec));
@@ -793,7 +791,10 @@ fn probe_settings() -> Result<VideoSettings,String> {
None=>crate::capture_setting::QUALITY_AUTO, None=>crate::capture_setting::QUALITY_AUTO,
Some(v)=>v.parse::<u64>().ok().filter(|q|(1..=5).contains(q)).ok_or("UU_PROBE_QUALITY must be 1-5")?, Some(v)=>v.parse::<u64>().ok().filter(|q|(1..=5).contains(q)).ok_or("UU_PROBE_QUALITY must be 1-5")?,
}; };
Ok(VideoSettings {fps,quality,codec:probe_codec(),..VideoSettings::default()}) let mut settings=VideoSettings {fps,quality,codec:probe_codec(),..VideoSettings::default()};
// UU_PROBE_CHROMA=444 requests 真彩 like the viewer does (only where full_chroma_available()).
if std::env::var("UU_PROBE_CHROMA").as_deref()==Ok("444") && full_chroma_available() { settings.chroma=crate::capture_setting::CHROMA_444; }
Ok(settings)
} }
/// The probe follows `UU_VIDEO_CODEC` so the HEVC path can be measured at all (H.264 otherwise), /// The probe follows `UU_VIDEO_CODEC` so the HEVC path can be measured at all (H.264 otherwise),