From 0e9d3b7c2b2863a99d9d5d758e93bea84d64db16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 12 Sep 2026 20:19:39 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20feat(engine):=20the=20s?= =?UTF-8?q?oftware=20H264=20export=20refuses=20sub-macroblock=20pictures?= =?UTF-8?q?=20by=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit H.264 codes 16x16 macroblocks and ec-h264's floor is the macroblock itself, where the retired encoder took any positive even size. Named at the seat where a card can show it -- the same shape as the odd-dimension refusal -- instead of surfacing the encoder's error from inside a running export. Found by review during the seat swap. --- crates/engine/src/export.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index 0ddb4b8..8829d83 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -3885,7 +3885,18 @@ impl Enc { eprintln!("export encoder: hardware (VA-API plugin)"); return Ok(Self::Hw(hw)); } - eprintln!("export encoder: software (ec-h264)"); + // H.264 codes 16x16 macroblocks, and ec-h264's floor is the + // macroblock itself -- the old encoder took any positive even size. + // Named here, where a card can show it, rather than let the encoder's + // error surface from inside an export already under way. + if meta.width < 16 || meta.height < 16 { + return Err(format!( + "{}x{} cannot be written as H.264: the picture is smaller \ + than one 16x16 macroblock", + meta.width, meta.height + ) + .into()); + } // 4:2:0 addresses its conformance window in *chroma* samples, so an odd // picture cannot be cropped back to itself -- and an odd dimension has // no chroma plane of its own to begin with. Named rather than padded to @@ -5353,6 +5364,25 @@ mod tests { assert!(Enc::open(&meta(1920, 1080), &settings).is_ok()); } + /// H.264 codes 16x16 macroblocks and ec-h264's floor is the macroblock + /// itself -- the old encoder took any positive even size -- so a + /// sub-macroblock picture is refused by name, like every other seat + /// refusal, rather than surfaced from inside a running export. + #[test] + fn a_sub_macroblock_picture_is_refused_an_h264_export_by_name() { + let settings = ExportSettings { + format: Format::Mp4, + seat: EncoderSeat::Software, + ..Default::default() + }; + let refused = Enc::open(&meta(8, 8), &settings) + .err() + .expect("8x8 is smaller than one macroblock") + .to_string(); + assert!(refused.contains("8x8"), "{refused}"); + assert!(refused.contains("16x16"), "{refused}"); + } + /// Weights ramp from just above 0 to just below 1 and never touch either /// end -- the frame *after* the window is where a viewer would see plain /// B, and the window itself never quite repeats a hard cut's own instant.