Pin the encoder's own streams byte for byte
Browse files at this commitf79740b48e83ead3933f40b961fa41d163e54869Parent: eadf8b5- test
- pin the encoder's own streams byte for byte
1 changed file +40 -0
- crates/ec-av1/src/encode.rs +40 -0
crates/ec-av1/src/encode.rsmodified+40 -0
| @@ -7071,6 +7071,46 @@ mod tests { | ||
| 7071 | 7071 | (ladder, wall) |
| 7072 | 7072 | } |
| 7073 | 7073 | |
| 7074 | + /// Byte-exactness gate for encoder work that is meant to change only | |
| 7075 | + /// how long the encoder takes. | |
| 7076 | + /// | |
| 7077 | + /// The BD gate above measures quality, which a speed lane can move by a | |
| 7078 | + /// hair without failing anything; this pins the streams themselves. | |
| 7079 | + /// Every number below was measured 2026-09-06 (lane-av1fwd) and is | |
| 7080 | + /// identical at `a6649c4e`, the merge before that lane's three exact | |
| 7081 | + /// speed steps. | |
| 7082 | + #[test] | |
| 7083 | + fn the_encoders_own_streams_are_byte_identical_to_their_pins() { | |
| 7084 | + if !have_ffmpeg() { | |
| 7085 | + eprintln!("SKIP the_encoders_own_streams_are_byte_identical_to_their_pins: no ffmpeg"); | |
| 7086 | + return; | |
| 7087 | + } | |
| 7088 | + let clip = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 7089 | + .join("../../fixtures/video/h264-1080p-23.976-8bit.mp4"); | |
| 7090 | + if !clip.exists() { | |
| 7091 | + eprintln!("SKIP the_encoders_own_streams_are_byte_identical_to_their_pins: no clip"); | |
| 7092 | + return; | |
| 7093 | + } | |
| 7094 | + let source = clip_frames(clip.to_str().unwrap(), "0", 640, 384, 4); | |
| 7095 | + // FNV-1a over the stream: a witness that every coded bit is where it | |
| 7096 | + // was, which a byte count alone is not. | |
| 7097 | + let fnv = |b: &[u8]| { | |
| 7098 | + b.iter().fold(0xcbf2_9ce4_8422_2325u64, |h, &v| { | |
| 7099 | + (h ^ u64::from(v)).wrapping_mul(0x0000_0100_0000_01b3) | |
| 7100 | + }) | |
| 7101 | + }; | |
| 7102 | + let pins: [(u8, usize, u64); 2] = | |
| 7103 | + [(150, 7823, 0x81db_18bb_91be_0d89), (60, 28189, 0x25fb_2fce_1bd1_e000)]; | |
| 7104 | + for (q, bytes, hash) in pins { | |
| 7105 | + let encoded = encode_sequence(&source, q, 0.5).unwrap(); | |
| 7106 | + assert_eq!( | |
| 7107 | + (encoded.stream.len(), fnv(&encoded.stream)), | |
| 7108 | + (bytes, hash), | |
| 7109 | + "q={q}: the encoder's stream moved" | |
| 7110 | + ); | |
| 7111 | + } | |
| 7112 | + } | |
| 7113 | + | |
| 7074 | 7114 | /// A ladder is only a ladder if both axes rise together. |
| 7075 | 7115 | fn assert_monotone(name: &str, ladder: &[(f64, f64)]) { |
| 7076 | 7116 | assert_eq!(ladder.len(), 4, "{name}: wanted four quality points"); |