edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiB80ecf3dTahinli3 months ago230 commits
| 1 | //! Subtitles: a list of cues with a time on them, out of a file beside the |
| 2 | //! media (`.srt`, `.vtt`, `.ass`) or out of a track inside it. |
| 3 | //! |
| 4 | //! One model for both, because a timeline cannot care which it was: a |
| 5 | //! [`SubtitleTrack`] is where it came from -- a path, and the Matroska track |
| 6 | //! number when it is one of several inside that path -- plus the [`Cue`]s. That |
| 7 | //! pair is also all a `.edith` writes ([`crate::edith`]): the cues are read |
| 8 | //! back out of the file on the way in, exactly as a clip's *pictures* are, so a |
| 9 | //! project file stays an edit list and not a copy of the subtitles. |
| 10 | //! |
| 11 | //! Parsing is `oxideav-subtitle` (SRT, WebVTT) and `oxideav-ass` (ASS/SSA) -- |
| 12 | //! the markup, the override tags and the encoding quirks of a dozen dialects |
| 13 | //! are not this project's to re-derive. What comes back here is plain text: the |
| 14 | //! renderer is a later thing, and a cue nobody can draw yet is still a cue that |
| 15 | //! has to be listed, timed and saved. |
| 16 | //! |
| 17 | //! What is *refused* is refused by name rather than by omission |
| 18 | //! ([`SubtitleTrack::refused`]): the bitmap subtitle formats -- PGS off a |
| 19 | //! BluRay remux, VobSub off a DVD -- are pictures, and a film carrying four of |
| 20 | //! them opens with four rows that say so instead of opening with an empty list. |
| 21 | |
| 22 | use ; |
| 23 | |
| 24 | use plain_text; |
| 25 | |
| 26 | /// One line of subtitle: on screen from `start_us` to `end_us`, microseconds |
| 27 | /// from the start of the media, which is the unit every parser here speaks. |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | /// A subtitle track: where it came from and what it says. |
| 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 | /// The one door a saved subtitle line comes back in through: a standalone file |
| 79 | /// (`track` is `None`) or track `n` of a Matroska file. |
| 80 | /// |
| 81 | /// Never an error, whatever is wrong: a deleted `.srt`, a media file that is |
| 82 | /// not there any more, a track number the file no longer has, a codec of |
| 83 | /// pictures. All of them come back [`refused`](SubtitleTrack::refused) by name, |
| 84 | /// because a project that opened yesterday has to open today -- a subtitle is |
| 85 | /// not what a whole timeline should refuse over. |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | /// A standalone subtitle file, parsed by its extension. |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | /// Every subtitle track of a Matroska file, in file order -- the text ones with |
| 125 | /// their cues, the bitmap ones refused by name (see the module docs). |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | /// The cues of one Matroska subtitle track, or why it has none. |
| 150 | /// |
| 151 | /// A Matroska text track carries the *timing* on the block and the *text* in |
| 152 | /// it, so neither codec is parsed as its own file would be: `S_TEXT/UTF8` is |
| 153 | /// one SRT cue's body per block, `S_TEXT/ASS` is one `Dialogue` line per block |
| 154 | /// with the `Start` and `End` fields cut out and the `[Script Info]` header |
| 155 | /// filed away in `CodecPrivate`. Both are put back into the shape their parser |
| 156 | /// reads -- rather than the markup being re-derived here -- which is also what |
| 157 | /// makes an embedded track and the standalone file it was muxed from come back |
| 158 | /// as the same cues. |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | /// When a cue goes away: its `BlockDuration`, or -- for the muxer that writes |
| 181 | /// none -- when the next one arrives, and [`NO_DURATION_US`] for the last. |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | /// The text of one `S_TEXT/UTF8` block with its markup resolved: through the |
| 198 | /// SRT parser, around a timing line this then throws away, because SRT markup |
| 199 | /// is exactly what such a block holds and a second implementation of it here |
| 200 | /// would be a second set of bugs. |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | /// The cues of an `S_TEXT/ASS` track: the script header out of `CodecPrivate` |
| 216 | /// with every block put back as a `Dialogue` line under it, parsed once as the |
| 217 | /// `.ass` file it came from. |
| 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 | /// Microseconds as ASS writes a time: `H:MM:SS.cc`. |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | /// A standalone subtitle file, by extension: the formats this engine reads at |
| 279 | /// all. Anything else is refused by name, as an unknown media file is. |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 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 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 |