edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits
| 1 | //! The mp4 display matrix, read three ways that must agree: the engine's |
| 2 | //! reading (`engine::demux::Demuxer`), the container demuxer's own |
| 3 | //! (`ec_mp4`'s track rotation), and ffprobe's side data. |
| 4 | //! |
| 5 | //! Every fixture is generated here with ffmpeg, so nothing depends on a file |
| 6 | //! someone happened to keep in `assets/`. The expectations are the turns the |
| 7 | //! engine reported before its reading moved to `ec_mp4`, which |
| 8 | //! `tests/rotation.rs` already pins against ffmpeg's own autorotation. |
| 9 | |
| 10 | use File; |
| 11 | use BufReader; |
| 12 | use Path; |
| 13 | use Command; |
| 14 | |
| 15 | use Rotation as EcRotation; |
| 16 | use Rotation; |
| 17 | use Scratch; |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | /// One 320x180 H.264 mp4 of ffmpeg's test pattern, 10 frames, no rotation. |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | /// The same stream remuxed with `-display_rotation <degrees>`, the way |
| 58 | /// `scripts/gen_fixtures.sh` writes its `test_rotation*.mp4` files. |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | /// The rotation ffprobe's `side_data` states, in its own convention: the |
| 80 | /// counter-clockwise angle, as ffprobe prints it (`90` for a file that is |
| 81 | /// shown a quarter turn clockwise). Absent side data is no turn. |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | /// ffprobe's counter-clockwise angle, turned into the clockwise quarter turn |
| 106 | /// the engine names. |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | /// The rotation `ec_mp4` reports for the file's track, read from the container |
| 118 | /// by the demuxer alone. |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | /// What the engine reports for `degrees` of `-display_rotation`, and what |
| 128 | /// `ec_mp4` reports for the same matrix. These are the values the engine's own |
| 129 | /// `tkhd` parse gave before the switch. |
| 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 | /// A mirror is not a turn: `ec_mp4` carries its four terms verbatim, and the |
| 167 | /// engine still refuses it by name, with the same angle in the sentence as |
| 168 | /// before. The matrix is written into a copy of the unrotated fixture's `tkhd` |
| 169 | /// (`a = -1`, `d = 1`), which ffmpeg has no option to state. |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 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 | /// Overwrites the `tkhd` display matrix of a version-0 mp4 with the four linear |
| 201 | /// terms `[a, b, c, d]` in 16.16 fixed point. The FullBox payload starts after the |
| 202 | /// fourcc; the matrix sits at byte 40 of it, and `a`, `b`, `u`, `c`, `d` are |
| 203 | /// consecutive words there. ffmpeg has no option that writes an arbitrary matrix. |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | /// A matrix 0.3 degrees past a quarter turn is still that quarter turn: the |
| 221 | /// engine has always tolerated half a degree, and `ec-mp4` snaps the same way |
| 222 | /// (its track rotation is already quantised, so the engine takes it as it is). |
| 223 | /// Byte-patched into an ffmpeg-made file, `a = cos 90.3`, `b = sin 90.3`. |
| 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 |