edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBcc667e6Tahinli3 months ago285 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 | //! A cue is not always words. `S_HDMV/PGS` off a BluRay remux is *pictures* -- |
| 18 | //! run-length bitmaps the disc composed against its own frame -- and one of |
| 19 | //! those is a [`Cue`] with a [`CueImage`] on it and no text. The decoding is |
| 20 | //! `oxideav-sub-image`, for the reason above. Everything downstream carries the |
| 21 | //! picture the way it carries the string: [`crate::export::timeline_cues`] maps |
| 22 | //! it onto the timeline, a front-end draws it over the film. |
| 23 | //! |
| 24 | //! What is still *refused* is refused by name rather than by omission |
| 25 | //! ([`SubtitleTrack::refused`]): VobSub off a DVD is a picture format nothing |
| 26 | //! here reads, and a file carrying one opens with a row that says so instead of |
| 27 | //! opening with an empty list. |
| 28 | |
| 29 | use ; |
| 30 | use Arc; |
| 31 | |
| 32 | use plain_text; |
| 33 | |
| 34 | /// One line of subtitle: on screen from `start_us` to `end_us`, microseconds |
| 35 | /// from the start of the media, which is the unit every parser here speaks. |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | /// A cue that is a picture: one PGS display set, kept the way the Matroska |
| 59 | /// block held it -- run-length and palettised, tens of kilobytes -- and turned |
| 60 | /// into pixels only when something is about to draw it ([`Self::rgba`]). |
| 61 | /// |
| 62 | /// Kept encoded because decoded is enormous: this film's canvas is 8 MB of |
| 63 | /// RGBA and its four PGS tracks carry about eleven thousand display sets |
| 64 | /// between them, so a track that decoded itself at import would cost gigabytes |
| 65 | /// where it now costs the thirty megabytes the file already spends on it. |
| 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 | /// The segments of a display set as a Matroska block holds them: a type byte, a |
| 128 | /// big-endian size, that many bytes of body, and again until the block is out. |
| 129 | /// `None` for bytes that do not walk -- a truncated or mislabelled block. |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | /// A subtitle track: where it came from and what it says. |
| 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 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | /// The one door a saved subtitle line comes back in through: a standalone file |
| 196 | /// (`track` is `None`) or track `n` of a Matroska file. |
| 197 | /// |
| 198 | /// Never an error, whatever is wrong: a deleted `.srt`, a media file that is |
| 199 | /// not there any more, a track number the file no longer has, a codec of |
| 200 | /// pictures. All of them come back [`refused`](SubtitleTrack::refused) by name, |
| 201 | /// because a project that opened yesterday has to open today -- a subtitle is |
| 202 | /// not what a whole timeline should refuse over. |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | /// A standalone subtitle file, parsed by its extension. |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | /// Every subtitle track of a Matroska file, in file order -- the text ones with |
| 244 | /// their cues, the bitmap ones refused by name (see the module docs). |
| 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 | /// The cues of one Matroska subtitle track, or why it has none. |
| 271 | /// |
| 272 | /// A Matroska text track carries the *timing* on the block and the *text* in |
| 273 | /// it, so neither codec is parsed as its own file would be: `S_TEXT/UTF8` is |
| 274 | /// one SRT cue's body per block, `S_TEXT/ASS` is one `Dialogue` line per block |
| 275 | /// with the `Start` and `End` fields cut out and the `[Script Info]` header |
| 276 | /// filed away in `CodecPrivate`. Both are put back into the shape their parser |
| 277 | /// reads -- rather than the markup being re-derived here -- which is also what |
| 278 | /// makes an embedded track and the standalone file it was muxed from come back |
| 279 | /// as the same cues. |
| 280 | /// |
| 281 | /// A PGS track is neither: its blocks are pictures, and they are moved out of |
| 282 | /// `track` rather than copied ([`pgs_cues`]) -- thirty megabytes a track is not |
| 283 | /// a thing to hold twice. |
| 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 | /// The cues of an `S_HDMV/PGS` track: one display set per block, and a display |
| 313 | /// set is a picture the disc composes onto its own canvas. |
| 314 | /// |
| 315 | /// Only the blocks that compose *something* are cues. The other half of them |
| 316 | /// are the disc's "take it off again" -- a composition with no object on it -- |
| 317 | /// and they are what says when the picture before them goes away, which is why |
| 318 | /// they are walked and not skipped. A muxer writes `BlockDuration` zero for all |
| 319 | /// of them, so [`end_of`] is what pairs the two. |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | /// The canvas of a display set that paints something -- its `PCS` says how big |
| 344 | /// the disc's picture is, and how many objects are composed onto it. |
| 345 | /// |
| 346 | /// `None` when nothing is composed, which is the disc clearing the screen, and |
| 347 | /// `None` for bytes that are not a display set at all. |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | /// When a cue goes away: its `BlockDuration`, or -- for the muxer that writes |
| 361 | /// none, and for the PGS block that writes a zero, which says the same thing -- |
| 362 | /// when the next one arrives, and [`NO_DURATION_US`] for the last. |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | /// The text of one `S_TEXT/UTF8` block with its markup resolved: through the |
| 379 | /// SRT parser, around a timing line this then throws away, because SRT markup |
| 380 | /// is exactly what such a block holds and a second implementation of it here |
| 381 | /// would be a second set of bugs. |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | /// The cues of an `S_TEXT/ASS` track: the script header out of `CodecPrivate` |
| 397 | /// with every block put back as a `Dialogue` line under it, parsed once as the |
| 398 | /// `.ass` file it came from. |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | /// Microseconds as ASS writes a time: `H:MM:SS.cc`. |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | /// A standalone subtitle file, by extension: the formats this engine reads at |
| 461 | /// all. Anything else is refused by name, as an unknown media file is. |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 |