A filter-intra key frame decodes pixel-exact through ffmpeg
Browse files at this commit24771c9a3d9fbadd55c1202fe125662aa0e01d95Parent: b978eaa- test
- a filter-intra key frame decodes pixel-exact through ffmpeg
- native gate prints the fire rate
2 changed files +77 -0
- crates/ec-av1/src/decode.rs +62 -0
- crates/ec-av1/src/encode.rs +15 -0
crates/ec-av1/src/decode.rsmodified+62 -0
| @@ -38018,6 +38018,68 @@ mod tests { | |||
| 38018 | } | 38018 | } |
| 38019 | } | 38019 | } |
| 38020 | 38020 | ||
| 38021 | + /// lane-fintra: the encoder's own filter-intra blocks, read back by BOTH | ||
| 38022 | + /// decoders. Two claims in one gate: the stream really exercises the tool | ||
| 38023 | + /// (the decoder's own `use_filter_intra == 1` counter moves, class | ||
| 38024 | + /// `gate-blind-to-feature` -- a feature that never fires is not measured), | ||
| 38025 | + /// and every sample of the frame that carries them matches ffmpeg's | ||
| 38026 | + /// (class `fixture-proves-symbol-not-signal`: the symbol alone would not | ||
| 38027 | + /// prove the recursive predictor, the tx_type row or the syntax position | ||
| 38028 | + /// between the palette colours and the colour-index maps). | ||
| 38029 | + #[test] | ||
| 38030 | + fn a_filter_intra_key_frame_decodes_pixel_exact_through_ffmpeg() { | ||
| 38031 | + let fctx = &crate::decode::FrameCtx::new(); | ||
| 38032 | + if !crate::encode::filter_intra_on() { | ||
| 38033 | + eprintln!("SKIP a_filter_intra_key_frame...: EC_AV1_FILTER_INTRA=0"); | ||
| 38034 | + return; | ||
| 38035 | + } | ||
| 38036 | + if !have_ffmpeg() { | ||
| 38037 | + eprintln!("SKIP a_filter_intra_key_frame...: no ffmpeg"); | ||
| 38038 | + return; | ||
| 38039 | + } | ||
| 38040 | + let (width, height) = (128usize, 128usize); | ||
| 38041 | + // Smooth, slowly curving content: what the recursive filter modes are | ||
| 38042 | + // for, and what a plain directional prediction leaves residual on. | ||
| 38043 | + let mut picture = crate::encode::Picture::grey(width, height); | ||
| 38044 | + for row in 0..height { | ||
| 38045 | + for col in 0..width { | ||
| 38046 | + let v = 128.0 | ||
| 38047 | + + 60.0 * ((row as f64) / 9.0).sin() * ((col as f64) / 11.0).cos() | ||
| 38048 | + + 8.0 * ((row + col) as f64 / 3.0).sin(); | ||
| 38049 | + picture.y[row * width + col] = v.clamp(0.0, 255.0) as u16; | ||
| 38050 | + } | ||
| 38051 | + } | ||
| 38052 | + let encoded = crate::encode::encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); | ||
| 38053 | + let (coded_w, coded_h) = ffprobe_size(&encoded.stream); | ||
| 38054 | + let before = filter_intra_hits(); | ||
| 38055 | + let ours = decode_key_frame_tile_lr( | ||
| 38056 | + &encoded.tile, | ||
| 38057 | + encoded.mi_cols, | ||
| 38058 | + encoded.mi_rows, | ||
| 38059 | + encoded.base_q_idx, | ||
| 38060 | + coded_w, | ||
| 38061 | + coded_h, | ||
| 38062 | + crate::encode::filter_intra_on(), | ||
| 38063 | + &encoded.cdef, | ||
| 38064 | + &encoded.loop_filter, | ||
| 38065 | + encoded.tx_select, | ||
| 38066 | + true, | ||
| 38067 | + encoded.screen, | ||
| 38068 | + encoded.allow_intrabc, | ||
| 38069 | + &encoded.loop_restoration, | ||
| 38070 | + fctx, | ||
| 38071 | + ) | ||
| 38072 | + .unwrap(); | ||
| 38073 | + let fired = filter_intra_hits() - before; | ||
| 38074 | + assert!(fired > 0, "no block took filter intra -- the gate is blind to the feature"); | ||
| 38075 | + eprintln!("a_filter_intra_key_frame: {fired} filter-intra blocks"); | ||
| 38076 | + let ffmpeg_decoded = ffmpeg_decode(&encoded.stream, coded_w as usize, coded_h as usize); | ||
| 38077 | + assert_eq!(ours.y, ffmpeg_decoded.y, "luma vs ffmpeg"); | ||
| 38078 | + assert_eq!(ours.u, ffmpeg_decoded.u, "U vs ffmpeg"); | ||
| 38079 | + assert_eq!(ours.v, ffmpeg_decoded.v, "V vs ffmpeg"); | ||
| 38080 | + assert_eq!(ours.y, encoded.reconstruction.y, "luma vs the encoder's own reconstruction"); | ||
| 38081 | + } | ||
| 38082 | + | ||
| 38021 | /// The key frame the encoder writes carries `tx_mode == TxMode::Select`, | 38083 | /// The key frame the encoder writes carries `tx_mode == TxMode::Select`, |
| 38022 | /// and that header bit is load-bearing for a decode of its tile: read as a | 38084 | /// and that header bit is load-bearing for a decode of its tile: read as a |
| 38023 | /// `TxMode::Largest` frame the very first block misses its `tx_depth` | 38085 | /// `TxMode::Largest` frame the very first block misses its `tx_depth` |
crates/ec-av1/src/encode.rsmodified+15 -0
| @@ -14092,6 +14092,7 @@ mod tests { | |||
| 14092 | let _ = crate::tile::take_palette_uv_hits(); | 14092 | let _ = crate::tile::take_palette_uv_hits(); |
| 14093 | let _ = crate::tile::take_intrabc_hits(); | 14093 | let _ = crate::tile::take_intrabc_hits(); |
| 14094 | let _ = take_intrabc_search(); | 14094 | let _ = take_intrabc_search(); |
| 14095 | + let _ = crate::tile::take_filter_intra_hits(); | ||
| 14095 | // The sequence path itself codes the pyramid now | 14096 | // The sequence path itself codes the pyramid now |
| 14096 | // (lane-av1pyrdef), and prints what it requested and what the | 14097 | // (lane-av1pyrdef), and prints what it requested and what the |
| 14097 | // content gate left effective. | 14098 | // content gate left effective. |
| @@ -14138,6 +14139,20 @@ mod tests { | |||
| 14138 | search[1], | 14139 | search[1], |
| 14139 | search[2], | 14140 | search[2], |
| 14140 | ); | 14141 | ); |
| 14142 | + // gate-blind-to-feature: how often the five recursive filter-intra | ||
| 14143 | + // modes actually won a block over this clip's four encodes -- a | ||
| 14144 | + // tool that never fires is not measured by the row above it. | ||
| 14145 | + let fi = crate::tile::take_filter_intra_hits(); | ||
| 14146 | + eprintln!( | ||
| 14147 | + "{name}: filter intra on={} blocks {} (modes DC={} V={} H={} D157={} PAETH={})", | ||
| 14148 | + filter_intra_on(), | ||
| 14149 | + fi[0], | ||
| 14150 | + fi[1], | ||
| 14151 | + fi[2], | ||
| 14152 | + fi[3], | ||
| 14153 | + fi[4], | ||
| 14154 | + fi[5], | ||
| 14155 | + ); | ||
| 14141 | let (aom, aom_wall) = external_ladder(&source, cw, ch, "libaom-av1", &aom_points); | 14156 | let (aom, aom_wall) = external_ladder(&source, cw, ch, "libaom-av1", &aom_points); |
| 14142 | let (rav1e, rav1e_wall) = external_ladder(&source, cw, ch, "librav1e", &rav1e_points); | 14157 | let (rav1e, rav1e_wall) = external_ladder(&source, cw, ch, "librav1e", &rav1e_points); |
| 14143 | assert_monotone(&format!("{name}: ours"), &ours); | 14158 | assert_monotone(&format!("{name}: ours"), &ours); |