edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiB978e685Tahinli3 months ago627 commits
| 1 | //! HEVC export: the codec this project could read and not write until OxideAV's |
| 2 | //! pure-Rust H.265 gave it an encoder -- an **intra-only** one, every frame a |
| 3 | //! self-contained IDR, which is the only shape of it fast enough to wait for |
| 4 | //! (the inter modes code 1080p at 0.81 fps across 12 cores; the intra path does |
| 5 | //! 4.30 fps on the same picture). |
| 6 | //! |
| 7 | //! Three things are under test here: that the *containers* say HEVC in the |
| 8 | //! words their readers expect (this project's own demuxer, and ffprobe where it |
| 9 | //! is installed); that a picture whose height is not a multiple of the 64-sample |
| 10 | //! coding tree block -- 1080, the resolution -- comes back out at its own size, |
| 11 | //! coded padded to 1088 and cropped by the SPS conformance window; and, for the |
| 12 | //! hardware seat only, that what it codes is the *picture that went in* rather |
| 13 | //! than a stream that merely decodes. That last one is not a nicety: a seat |
| 14 | //! whose parameter sets disagree with its coded syntax hands back the right |
| 15 | //! number of frames and the wrong pixels, and nothing else here would see it. |
| 16 | //! |
| 17 | //! ```text |
| 18 | //! cargo test -p engine --release --test hevc_export -- --test-threads=1 |
| 19 | //! ``` |
| 20 | //! |
| 21 | //! Release, always: a debug intra encode is minutes a frame. The 1080p twin |
| 22 | //! needs the `ffmpeg` CLI to make its source and `ffprobe` to read the coded |
| 23 | //! size back; without them it says so and passes, exactly as the hardware tests |
| 24 | //! here do. |
| 25 | |
| 26 | use ; |
| 27 | use Command; |
| 28 | use ; |
| 29 | |
| 30 | use ; |
| 31 | use ; |
| 32 | use Scratch; |
| 33 | use ; |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | /// Runs an export to completion, failing on the deadline rather than hanging. |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | /// Two frames of the A/V fixture: what is under test is the wiring from the |
| 68 | /// format to the muxer, not how long an encoder takes. |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | /// The container half, in both boxes: an HEVC export is read back as HEVC, at |
| 77 | /// the size and the count it was written at, with the timeline's sound beside |
| 78 | /// it. The `hvcC` record this writes is the one `demux` parses -- Matroska in |
| 79 | /// `CodecPrivate`, mp4 in the sample entry -- so this is where the writer and |
| 80 | /// the reader either agree or do not. |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | /// The %16 half, and the reason the vendored encoder carries a patch at all: |
| 124 | /// 1080 is not a multiple of the 16-sample CTB, so the picture is coded at |
| 125 | /// 1920x1088 and the SPS crops it back with a §7.4.3.2.1 conformance window. |
| 126 | /// ffprobe is what says whether that worked -- it reads the *bitstream*, not |
| 127 | /// the container's own claim -- and ffmpeg decoding the file without a |
| 128 | /// complaint is what says the stream is legal. |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | /// The loop closed where it matters to a user: the file this wrote is opened |
| 172 | /// again *by edith*, picture and all. HEVC has no software decoder here at all, |
| 173 | /// so the way back in is the plugin -- which is what makes this the twin that |
| 174 | /// needs one, and what makes the test above (the containers, read by the |
| 175 | /// demuxer) the one that does not. |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | /// The same 1080p picture, coded by the **GPU**, and the test that would have |
| 202 | /// caught what shipped: the hardware seat's file decoded frame for frame while |
| 203 | /// every frame of it was a band of noise over flat green, because the parameter |
| 204 | /// sets promised coding tools the driver was not using. Nothing that counts |
| 205 | /// frames sees that. Three things do, and all three are asserted here -- |
| 206 | /// ffmpeg's decoder saying *nothing at all* on its error channel, the coded |
| 207 | /// size still cropping back to 1920x1080, and the picture being the source's |
| 208 | /// rather than a fill (SSIM against the very frames that went in; a desynced |
| 209 | /// stream scores about 0.2, this one about 0.98). |
| 210 | /// |
| 211 | /// `testsrc2` is what makes it bite: 1080p of it splits transform trees deep |
| 212 | /// enough and pushes the rate controller hard enough to need the syntax the |
| 213 | /// parameter sets have to declare. The two-frame fixtures above are flat and |
| 214 | /// pass either way, which is exactly how the defect got through. |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | /// An audio-only timeline has no picture to code, and an HEVC export says so by |
| 265 | /// name exactly as the mp4 and AV1 ones do -- and writes nothing. |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | /// A cancelled HEVC export leaves nothing behind -- not the file and not the |
| 289 | /// `.part` the worker was writing. An intra-only export of a whole fixture is |
| 290 | /// long enough to catch mid-flight, and the frame loop checks for a cancel |
| 291 | /// every picture, so this stops in a frame or two rather than at the end. |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | /// `codec,width,height` of the file's video stream as ffprobe reads it, or |
| 320 | /// `None` where ffprobe is not installed. |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | /// Mean SSIM of `out` against `source`, over the frames the two have in common, |
| 340 | /// as ffmpeg's own filter measures it. `None` where ffmpeg is not installed or |
| 341 | /// said nothing -- the caller decides whether that is a skip or a failure. |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | /// A two-second 1920x1080 H.264 fixture in the temp directory -- the assets are |
| 361 | /// all 720p, which is a multiple of 16 in both directions and would leave the |
| 362 | /// crop path untested. `None` where ffmpeg is not installed. |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 |