edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBf91abd5Tahinli2 months ago3774 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """ffmpeg pixel-oracle comparator for ec-av1 4:2:2 (and 4:2:0 / 4:4:4 controls). |
| 3 | |
| 4 | Discipline (oracle-comparator-liveness-control): |
| 5 | |
| 6 | 1. Geometry is an EXPLICIT argument read from the SEQUENCE HEADER via ffprobe |
| 7 | (coded_width / coded_height / pix_fmt of the AV1 stream), never derived |
| 8 | from a file size. A raw frame whose byte length disagrees with the geometry |
| 9 | is a hard error. |
| 10 | 2. Plane attribution is per FRAME, from that frame's own plane lengths, with a |
| 11 | monotone cursor -- never absolute thresholds from frame 0. |
| 12 | 3. A wrong SAMPLE is one bps-wide unit. At 10 bit the comparator walks |
| 13 | 16-bit LE samples, so the top bits cannot hide. |
| 14 | 4. A count over zero frames is a hard error (vacuous 0/0/0). |
| 15 | 5. Decode-order (ours, EC_AV1_FINAL_DUMP) -> display-order (ffmpeg rawvideo) |
| 16 | mapping is derived by LUMA-IDENTITY content match under a strictly |
| 17 | increasing assignment, then re-verified per frame. Exactly one decode frame |
| 18 | must have no display partner: the hidden alt-ref picture. |
| 19 | """ |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | = |
| 27 | = |
| 28 | |
| 29 | |
| 30 | |
| 31 | """ffprobe reads the AV1 SEQUENCE HEADER: coded_width/coded_height and the |
| 32 | chroma format/depth it implies. Never the raw output's byte length.""" |
| 33 | = |
| 34 | |
| 35 | |
| 36 | = |
| 37 | , , = , , |
| 38 | = |
| 39 | |
| 40 | |
| 41 | = |
| 42 | |
| 43 | |
| 44 | = |
| 45 | return , , , , , |
| 46 | |
| 47 | |
| 48 | |
| 49 | = - |
| 50 | = - |
| 51 | = |
| 52 | return , * |
| 53 | |
| 54 | |
| 55 | |
| 56 | , = , 0 |
| 57 | |
| 58 | |
| 59 | += 1 |
| 60 | return |
| 61 | |
| 62 | |
| 63 | |
| 64 | = |
| 65 | |
| 66 | |
| 67 | |
| 68 | return |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | return |
| 78 | |
| 79 | |
| 80 | |
| 81 | """Every way to assign each decode frame either a distinct display partner |
| 82 | or the hidden role, covering the display side exactly. Enumerated, not |
| 83 | guessed: a duplicated picture can make the assignment genuinely ambiguous, |
| 84 | and the caller then has to show the ambiguity does not change the answer. |
| 85 | |
| 86 | Two bounds, both learned the hard way: without the feasibility prune, an |
| 87 | instance whose candidate lists cannot cover the display side explores the |
| 88 | whole 2**frames tree before returning empty (that is what made three |
| 89 | 43-frame cells burn a 300 s cap with 15 minutes of user CPU and never |
| 90 | finish), and without a node cap a pathological instance would hang the |
| 91 | comparator instead of reporting.""" |
| 92 | = |
| 93 | = 0 |
| 94 | |
| 95 | |
| 96 | nonlocal |
| 97 | += 1 |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | return |
| 104 | |
| 105 | return # not enough decode frames left to cover the display side |
| 106 | |
| 107 | |
| 108 | |
| 109 | return |
| 110 | |
| 111 | |
| 112 | |
| 113 | = |
| 114 | |
| 115 | del |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | return |
| 123 | |
| 124 | |
| 125 | |
| 126 | """Identity of each decode-order frame is carried by its LUMA plane; full-frame |
| 127 | identity is preferred when it exists. Every assignment that covers the |
| 128 | display side is enumerated, so a duplicated picture shows up as an |
| 129 | explicit solution COUNT rather than a silent pick. Real altref streams |
| 130 | REORDER display against decode (measured: decode f2..f8 -> display |
| 131 | 7,3,1,2,5,4,6), so no monotonicity prior is applied -- an unjustified one |
| 132 | is exactly the class of silent mismatch this instrument exists to catch.""" |
| 133 | = * |
| 134 | |
| 135 | = |
| 136 | |
| 137 | = |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | return |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | = 1 |
| 153 | , = |
| 154 | = |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | = |
| 162 | |
| 163 | |
| 164 | = |
| 165 | = |
| 166 | , = , None |
| 167 | = |
| 168 | |
| 169 | |
| 170 | |
| 171 | continue |
| 172 | = |
| 173 | , = , 0 |
| 174 | |
| 175 | = |
| 176 | |
| 177 | = * |
| 178 | |
| 179 | += 1 |
| 180 | += 1 |
| 181 | += 1 |
| 182 | , = |
| 183 | = |
| 184 | |
| 185 | = |
| 186 | |
| 187 | = |
| 188 | |
| 189 | = |
| 190 | |
| 191 | = |
| 192 | |
| 193 | = |
| 194 | |
| 195 | |
| 196 | += * |
| 197 | |
| 198 | return , , , , |
| 199 | |
| 200 | |
| 201 | """Per-plane differing-SAMPLE counts at 8-bit, at C speed: XOR the two |
| 202 | planes as big ints, then count non-zero bytes per plane. Equivalent to |
| 203 | the per-sample loop above, and the only reason a 43-frame cell with 64 |
| 204 | candidate assignments used to cost half an hour.""" |
| 205 | = ^ |
| 206 | = |
| 207 | , = , 0 |
| 208 | |
| 209 | = |
| 210 | += |
| 211 | |
| 212 | return |
| 213 | |
| 214 | |
| 215 | = |
| 216 | |
| 217 | |
| 218 | = |
| 219 | |
| 220 | = |
| 221 | = |
| 222 | return |
| 223 | |
| 224 | = |
| 225 | |
| 226 | = |
| 227 | |
| 228 | = |
| 229 | += |
| 230 | += |
| 231 | += |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | = |
| 239 | , = |
| 240 | |
| 241 | = |
| 242 | = |
| 243 | , = None, |
| 244 | |
| 245 | , , , , = |
| 246 | |
| 247 | # 16-bit planes: the sample loop below is the only path today. |
| 248 | |
| 249 | = |
| 250 | = |
| 251 | |
| 252 | |
| 253 | *= |
| 254 | |
| 255 | = |
| 256 | = |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | , , , , = |
| 263 | , = |
| 264 | |
| 265 | |
| 266 | |
| 267 | return |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | = |
| 278 | return f + |
| 279 | |
| 280 | |
| 281 | |
| 282 | """Flip bit 0 of one oracle SAMPLE's low byte: exactly +1 wrong sample in |
| 283 | both depths (2**bitdepth < 2**16, so nothing carries out of the container). |
| 284 | Returns a new list; the caller drops it to restore.""" |
| 285 | = |
| 286 | = |
| 287 | ^= 1 |
| 288 | = |
| 289 | return |
| 290 | |
| 291 | |
| 292 | |
| 293 | , , , , , = |
| 294 | = 1 |
| 295 | , = |
| 296 | = |
| 297 | = |
| 298 | |
| 299 | |
| 300 | |
| 301 | = |
| 302 | = |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | return , , , , |
| 308 | |
| 309 | |
| 310 | |
| 311 | , , = |
| 312 | = |
| 313 |