forge
Explore
Log in

Don't you dare go Hollow

The software H264 export refuses sub-macroblock pictures by name

Browse files at this commit

0e9d3b7c2b2863a99d9d5d758e93bea84d64db16Ahmet Kaan GümüşParent: 02e2308
  • feat
    • the software H264 export refuses sub-macroblock pictures by name
Show full message
🛡️ feat(engine): the software H264 export refuses sub-macroblock pictures by name

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.rsmodified+31 -1
@@ -3885,7 +3885,18 @@ impl Enc {
3885 eprintln!("export encoder: hardware (VA-API plugin)");3885 eprintln!("export encoder: hardware (VA-API plugin)");
3886 return Ok(Self::Hw(hw));3886 return Ok(Self::Hw(hw));
3887 }3887 }
3888- eprintln!("export encoder: software (ec-h264)");3888+ // H.264 codes 16x16 macroblocks, and ec-h264's floor is the
3889+ // macroblock itself -- the old encoder took any positive even size.
3890+ // Named here, where a card can show it, rather than let the encoder's
3891+ // error surface from inside an export already under way.
3892+ if meta.width < 16 || meta.height < 16 {
3893+ return Err(format!(
3894+ "{}x{} cannot be written as H.264: the picture is smaller \
3895+ than one 16x16 macroblock",
3896+ meta.width, meta.height
3897+ )
3898+ .into());
3899+ }
3889 // 4:2:0 addresses its conformance window in *chroma* samples, so an odd3900 // 4:2:0 addresses its conformance window in *chroma* samples, so an odd
3890 // picture cannot be cropped back to itself -- and an odd dimension has3901 // picture cannot be cropped back to itself -- and an odd dimension has
3891 // no chroma plane of its own to begin with. Named rather than padded to3902 // no chroma plane of its own to begin with. Named rather than padded to
@@ -5353,6 +5364,25 @@ mod tests {
5353 assert!(Enc::open(&meta(1920, 1080), &settings).is_ok());5364 assert!(Enc::open(&meta(1920, 1080), &settings).is_ok());
5354 }5365 }
5355 5366
5367+ /// H.264 codes 16x16 macroblocks and ec-h264's floor is the macroblock
5368+ /// itself -- the old encoder took any positive even size -- so a
5369+ /// sub-macroblock picture is refused by name, like every other seat
5370+ /// refusal, rather than surfaced from inside a running export.
5371+ #[test]
5372+ fn a_sub_macroblock_picture_is_refused_an_h264_export_by_name() {
5373+ let settings = ExportSettings {
5374+ format: Format::Mp4,
5375+ seat: EncoderSeat::Software,
5376+ ..Default::default()
5377+ };
5378+ let refused = Enc::open(&meta(8, 8), &settings)
5379+ .err()
5380+ .expect("8x8 is smaller than one macroblock")
5381+ .to_string();
5382+ assert!(refused.contains("8x8"), "{refused}");
5383+ assert!(refused.contains("16x16"), "{refused}");
5384+ }
5385+
5356 /// Weights ramp from just above 0 to just below 1 and never touch either5386 /// Weights ramp from just above 0 to just below 1 and never touch either
5357 /// end -- the frame *after* the window is where a viewer would see plain5387 /// end -- the frame *after* the window is where a viewer would see plain
5358 /// B, and the window itself never quite repeats a hard cut's own instant.5388 /// B, and the window itself never quite repeats a hard cut's own instant.