From 169edf2224775db9e2300fc825ffa08bfc2da428 Mon Sep 17 00:00:00 2001 From: Jeff Zhang Date: Tue, 20 Oct 2026 07:23:54 +0800 Subject: [PATCH] inproc: pad odd native captures to even for the in-process encoder (#60) The in-process encoder opened its context at the raw capture size, so an odd logical desktop (e.g. two stacked 150% monitors, 2560x2507) made every H.264/HEVC/NVENC encoder fail to open. The encoder size is now rounded up to even, and a native capture is copied into a zeroed frame of that size so the extra row/column stays black. Scaled output paths are unchanged. Co-authored-by: ferstar --- src/inproc_encoder.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/inproc_encoder.rs b/src/inproc_encoder.rs index e417e43..0a96a3b 100644 --- a/src/inproc_encoder.rs +++ b/src/inproc_encoder.rs @@ -101,7 +101,9 @@ fn drain(encoder: &mut encoder::Video, packet: &mut Packet, units: &mpsc::Sender /// Opens the selected video encoder for `config`. Returns the encoder, its input pixel format and output size. fn open_encoder(config: &Config) -> Result<(encoder::Video, Pixel, u32, u32), String> { + // H.264/HEVC 4:2:0 and NVENC need even dimensions; an odd native capture is padded (see run_damage). let (width, height) = config.output.unwrap_or(config.input); + let (width, height) = (width + width % 2, height + height % 2); let codec = encoder::find_by_name(config.encoder.name_for(config.codec)) .ok_or_else(|| format!("{} is not available in this FFmpeg build", config.encoder.name_for(config.codec)))?; // Allocate for this codec so FFmpeg fills its defaults; libx264 rejects a context allocated without one. @@ -278,7 +280,11 @@ pub fn run(config: Config, units: mpsc::Sender, stop: Arc, stop: Arc, idr: Arc, budget: Arc) -> Result<(), String> { let (mut encoder, pixel, width, height) = open_encoder(&config)?; let (cap_width, cap_height) = capture.size(); - let mut captured = frame::Video::new(Pixel::BGRZ, cap_width, cap_height); + // Native size uses the even encoder size. The extra row/column is never overwritten, so it stays black. + let native = config.output.is_none(); + let (frame_width, frame_height) = if native { (width, height) } else { (cap_width, cap_height) }; + let mut captured = frame::Video::new(Pixel::BGRZ, frame_width, frame_height); + if native { captured.data_mut(0).fill(0); } let mut converted = frame::Video::empty(); let mut scaler = None; let mut packet = Packet::empty(); @@ -324,11 +330,11 @@ fn run_damage(config: Config, mut capture: DamageCapture, units: mpsc::Sender