edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! The display matrix: a file that says "turn me" is turned -- in the preview |
| 2 | //! and in the export, from the same numbers. |
| 3 | //! |
| 4 | //! A phone records a portrait video as a landscape picture plus a `tkhd` matrix |
| 5 | //! saying which way to turn it. Before this the engine read neither: the |
| 6 | //! preview showed a portrait clip on its side and an export re-coded the |
| 7 | //! landscape pixels with a unity matrix, so the file played sideways anywhere |
| 8 | //! -- the one rendition nobody ever wanted. |
| 9 | //! |
| 10 | //! `test_rotation90/180/270.mp4` (`scripts/gen_fixtures.sh`) are one 320x180 |
| 11 | //! source of four coloured quadrants written back out with a turn asked for, so |
| 12 | //! a single sampled pixel per corner names the layout and a *wrong direction* |
| 13 | //! cannot pass -- a 180-degree mix-up, a mirror, or "ignore it" each produce a |
| 14 | //! different set of four corners. The layouts asserted here are ffmpeg's own |
| 15 | //! autorotation of each file, measured rather than derived. |
| 16 | //! |
| 17 | //! `test_rotation45.mp4` is the other half of the contract: a matrix that is a |
| 18 | //! rotation but not a quarter turn has no correct rendition here, and it is |
| 19 | //! refused *by name* at the door rather than shown wrong. |
| 20 | |
| 21 | use ; |
| 22 | use Once; |
| 23 | use ; |
| 24 | |
| 25 | use ExportSettings; |
| 26 | use Scratch; |
| 27 | use ; |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | /// Which seat an export takes is decided by *process-wide* environment |
| 36 | /// variables, so a test binary that shares the machine has to borrow them |
| 37 | /// rather than assume: this pins both decode and encode to software, which is |
| 38 | /// the seat every machine has, and holds the borrow for the whole test binary. |
| 39 | static SEAT: RwLock = new; |
| 40 | |
| 41 | type Shared = RwLockReadGuard; |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | /// What colour a decoded BGRA pixel is, by the quadrant it came from. ffmpeg's |
| 71 | /// `red`/`green`/`blue`/`yellow` are far apart enough that the chroma of a |
| 72 | /// 4:2:0 edge never reaches a quadrant's centre, and the labels are what the |
| 73 | /// fixture's own comment says it drew. |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | /// The four corners of one tightly packed BGRA picture, top-left first and |
| 87 | /// clockwise -- sampled deep enough inside each quadrant that a 4:2:0 boundary |
| 88 | /// cannot colour the sample. |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | /// What the coded picture holds, before anything turns it: this is the layout |
| 104 | /// every expectation below is *not*. |
| 105 | const CODED: = ; |
| 106 | |
| 107 | /// One frame of `path` and the size it came out at: the preview path exactly |
| 108 | /// ([`DecodeSession`] is the same funnel [`PlaybackSession`] paints from). |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | /// The same four corners ffmpeg's own autorotation of each file produces -- |
| 116 | /// measured with `ffmpeg -i f.mp4 -f rawvideo -pix_fmt rgb24 -` on this |
| 117 | /// machine, which is the arbiter a display matrix is read against. |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | /// The header says which way the picture lies: a quarter turn swaps the |
| 140 | /// displayed size and names the turn, and a half turn does neither. |
| 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 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | /// The preview: the picture is turned before it is painted, at the size the |
| 183 | /// turn gives it. |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | /// The export: the turn is baked into the pixels, so the file plays upright |
| 216 | /// everywhere -- which means the output is portrait *and* declares no matrix of |
| 217 | /// its own. A file that kept the source's matrix and the source's landscape |
| 218 | /// pixels would satisfy neither half. |
| 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 | |
| 265 | |
| 266 | /// A turn that is not a quarter turn is refused by name at the door, with the |
| 267 | /// angle in the sentence -- the honest answer to a picture this engine has no way |
| 268 | /// to show right. The capability really is absent: nothing here turns by an |
| 269 | /// arbitrary angle ([`engine::scale::rotate_i420_90s`] takes whole quarters), and |
| 270 | /// the refusal is what says so instead of a sideways picture. |
| 271 | /// |
| 272 | /// **Both doors**, because they are two spellings of one question: an mp4 states |
| 273 | /// the turn in a `tkhd` matrix and an mkv in a `Projection` roll, and a file |
| 274 | /// whose picture is 45 degrees off is the same missing capability either way -- |
| 275 | /// the mkv twin exists for exactly this assertion. |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | /// The number a refusal states, as the sentence spells it: the text between |
| 298 | /// "matrix of " and the degree sign. |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | /// The `rotation` side data ffprobe reports for the file's video track: the |
| 306 | /// counter-clockwise angle, in ffprobe's own sign. |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | /// The refused angle is stated in the same convention for both containers, and |
| 333 | /// that convention is ffprobe's: a 45-degree matrix in an mp4 and the same turn |
| 334 | /// as an mkv roll both say `45.0`, the counter-clockwise angle ffprobe reports |
| 335 | /// for each (`-atan2(b, a)` on the mp4 side, the roll itself on the mkv side). |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | /// A rotated file whose *coded* height and *displayed* height sit on opposite |
| 360 | /// sides of the 720-line rule an untagged stream's matrix is guessed from |
| 361 | /// ([`engine::colorspace::ColorDescription::resolve`]): `test_rotation90tall` is |
| 362 | /// 1280x640 as stored and 640x1280 as shown, and neither container tags it (the |
| 363 | /// mkv's `Colour` element carries only chroma siting, the mp4 has no `colr` |
| 364 | /// box), so that guess is the only thing deciding bt601 against bt709. |
| 365 | /// |
| 366 | /// Both doors must feed the height the picture is *shown* at -- bt709 here -- and |
| 367 | /// this is the assertion that fails if a door reads the coded height instead |
| 368 | /// (`video.height`, 640, is bt601). The two doors agreeing is the whole point of |
| 369 | /// resolving the size the same way in both. |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 |