edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiB2e2ed69Tahinli3 months ago69 commits
| 1 | //! MP4 demux: pulls the H.264 track out as Annex-B access units. |
| 2 | |
| 3 | use File; |
| 4 | use BufReader; |
| 5 | use Path; |
| 6 | |
| 7 | use ; |
| 8 | |
| 9 | use crate; |
| 10 | |
| 11 | const START_CODE: = ; |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 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 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 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 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | /// Frames per second off the sample table. `mp4 0.14`'s own |
| 131 | /// [`Mp4Track::frame_rate`] divides the sample count by whole *milliseconds* |
| 132 | /// before the float cast (`track.rs:166`), so 24000/1001 reads back as a flat |
| 133 | /// 23.0 -- with the audio clock as master that is 4 % of drift, five minutes of |
| 134 | /// it by the end of a two-hour film. |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | /// Whole track over whole track: constant-delta tables (the common case) come |
| 140 | /// out as exactly `timescale / delta`, and a table that spreads 3753/3754 ticks |
| 141 | /// to average 3753.75 averages instead of truncating. All of it in `f64`, which |
| 142 | /// is the bug the caller above exists to avoid. |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | /// What the edit list really trims off the front, in media ticks: its |
| 161 | /// `media_time` less the first sample's own composition offset. A stream with |
| 162 | /// B-frames carries a `ctts` delay, and every muxer writes `media_time` equal to |
| 163 | /// exactly that delay -- which is not a trim at all, it is the container saying |
| 164 | /// "sample 1 is still the first picture". Reading it as one drops real frames |
| 165 | /// (`test_high.mp4` loses two, and so did the film this bug came from). What is |
| 166 | /// left over after the delay is the genuine trim. |
| 167 | /// |
| 168 | /// ponytail: empty edits are ignored and `media_time` is otherwise taken at face |
| 169 | /// value, which is exactly what [`crate::audio::edit_media_time`] gives the audio |
| 170 | /// track -- symmetry between the two is the point, not a full edit-list engine. |
| 171 | /// Their *empty* edits can differ (83 ms of video against 62 ms of audio in that |
| 172 | /// film, so the picture stays 21 ms -- half a frame -- early); honouring those is |
| 173 | /// the upgrade path, and it belongs to both tracks at once. |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | /// 1-based id of the sample the presentation starts on, for a track trimmed by |
| 188 | /// `trim` media ticks ([`trim_ticks`]). `None` (no edit list) and zero are both |
| 189 | /// "no trim", i.e. the first sample. |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | /// Largest entry of the ascending sync table that is `<= sample_id`. An empty |
| 195 | /// table means every sample is a sync sample. When `sample_id` sits before the |
| 196 | /// first sync sample there is nothing decodable earlier, so that one wins. |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | /// avcC length-prefixed NALs -> Annex-B. Assumes a 4-byte length prefix, which |
| 208 | /// mp4 0.14 does not expose; a wrong guess misparses immediately, hence the check. |
| 209 | /// |
| 210 | /// ponytail: hardcoded 4-byte NAL length prefix (lengthSizeMinusOne == 3). 1/2-byte |
| 211 | /// prefixes exist in the wild; upgrade path is parsing the avcC box from |
| 212 | /// `track.trak` instead of assuming. |
| 213 | |
| 214 | |
| 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 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 |