edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiB7f487c1Tahinli3 months ago659 commits
| 1 | //! Annex-B -> MP4, the mirror of `demux`: encoders emit start-code framed NALs, |
| 2 | //! an mp4 sample wants 4-byte length prefixes with SPS/PPS living in `avcC`. |
| 3 | //! |
| 4 | //! ...and AV1 -> Matroska, the mirror of the *other* half of `demux`, for the |
| 5 | //! same reason that half exists: `mp4 0.14` has no `av01` sample entry at all, |
| 6 | //! so an AV1 export is written as EBML by hand exactly as an AV1 import is read |
| 7 | //! as EBML by hand ([`MkvMuxer`]). |
| 8 | //! |
| 9 | //! AV1 goes into an **mp4** too, and the missing sample entry is written by hand |
| 10 | //! there as well ([`Mp4Muxer::create_av1`]): the crate writes the file with an |
| 11 | //! `avc1` entry and this patches that entry into the `av01` + `av1C` pair the |
| 12 | //! spec asks for, which is the only box in a whole mp4 the crate cannot spell. |
| 13 | //! Both containers carry the timeline's AAC, so no format here writes a picture |
| 14 | //! whose sound was silently left behind -- and both carry its subtitles, an mp4 |
| 15 | //! as the `tx3g` timed text `mp4 0.14` *can* spell ([`Mp4Muxer::write_subtitles`]) |
| 16 | //! and Matroska as `S_TEXT/UTF8` blocks, so neither is a file whose words were. |
| 17 | |
| 18 | use ; |
| 19 | use ; |
| 20 | use ; |
| 21 | |
| 22 | use |
| 23 | |
| 24 | |
| 25 | ; |
| 26 | |
| 27 | use crateColorDescription; |
| 28 | |
| 29 | /// 90 kHz is the H.264 convention, and it divides exactly at every *integer* |
| 30 | /// fps (3000 ticks at 30, 3600 at 25). The NTSC rates do not divide into it at |
| 31 | /// all -- 24000/1001 wants 3753.75 -- so those get their own clock; see |
| 32 | /// [`frame_timing`]. |
| 33 | const VIDEO_TIMESCALE: u32 = 90_000; |
| 34 | /// Ticks per frame for a rate the 90 kHz clock cannot express: every NTSC rate |
| 35 | /// is `n/1001`, so 1001 ticks a frame makes the timescale a whole `n`. |
| 36 | const NTSC_TICKS: u32 = 1001; |
| 37 | /// An AAC-LC packet is always 1024 samples, so with timescale == sample rate the |
| 38 | /// per-packet duration is this constant. |
| 39 | const AAC_PACKET_SAMPLES: u32 = 1024; |
| 40 | /// The clock a `tx3g` track counts in: one millisecond, the very tick a Matroska |
| 41 | /// block's timestamp is written at ([`TIMESTAMP_SCALE_NS`]), so a cue lands on |
| 42 | /// the same instant whichever of the two containers carries it. |
| 43 | const SUB_TIMESCALE: u32 = 1_000; |
| 44 | |
| 45 | const NAL_IDR: u8 = 5; |
| 46 | const NAL_SEI: u8 = 6; |
| 47 | const NAL_SPS: u8 = 7; |
| 48 | const NAL_PPS: u8 = 8; |
| 49 | const NAL_AUD: u8 = 9; |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | /// What the audio track declares: read straight off the source file's `esds` |
| 60 | /// where the export copies packets, and off this project's own encoder where it |
| 61 | /// re-encodes ([`crate::export`] decides which). `sample_rate` says the same |
| 62 | /// thing `freq_index` does and is carried beside it because Matroska states the |
| 63 | /// rate as a number rather than as an index into the AAC table. |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | /// Writes one H.264 *or* AV1 track plus an optional AAC track. mp4 0.14 ignores |
| 78 | /// `Mp4Sample::start_time` and builds all timing by accumulating `duration`, so |
| 79 | /// every sample handed over must carry an exact duration or the tracks drift. |
| 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 | /// A `ColourInformationBox` payload, ISO/IEC 14496-12 §12.1.5: the `nclx` tag |
| 111 | /// and the same three H.273 code points Matroska's `Colour` carries, plus the |
| 112 | /// range as the one-bit flag an mp4 says it with rather than Matroska's code. |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | const VIDEO_TRACK: u32 = 1; |
| 125 | const AUDIO_TRACK: u32 = 2; |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 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 | |
| 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 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 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 | |
| 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 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 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 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 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 | /// The cues of one subtitle track as the run of `tx3g` samples an mp4 carries |
| 499 | /// them in -- `(payload, duration in milliseconds)`, from instant 0 to `end`, |
| 500 | /// with no instant left out. |
| 501 | /// |
| 502 | /// A sample's payload is the ISO/IEC 14496-17 one: the text's length in 16 bits |
| 503 | /// and then the UTF-8 itself, which is two zero bytes where there is nothing on |
| 504 | /// screen. The run is walked over the cue *boundaries* rather than over the cues, |
| 505 | /// which is what makes a gap an empty sample and an overlap one sample carrying |
| 506 | /// both lines -- the two things a track of samples has to say that a list of |
| 507 | /// cues does not. |
| 508 | /// |
| 509 | /// corner-cut: the active set is looked for from the front of the list at every |
| 510 | /// boundary, so this is quadratic in the cues of one track (a 5 000-cue film |
| 511 | /// costs ~25 M compares once, at the end of an export that took minutes). The |
| 512 | /// upgrade path is a sweep holding the open cues in a heap keyed on their end. |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | /// Rewrites the finished file's one video sample entry: `colr` appended to it |
| 567 | /// always (the crate writes none), and where `entry` says so the `avc1` header |
| 568 | /// itself replaced by the `av01` + `av1C` an AV1 track declares -- or the `hvc1` |
| 569 | /// + `hvcC` an HEVC one does. Called once, on a complete file. |
| 570 | /// |
| 571 | /// `moov` sits after `mdat` (the crate writes it at `write_end`), so this only |
| 572 | /// ever rewrites the tail of the file: no sample moves and no chunk offset in |
| 573 | /// `co64` changes. The box tree is rebuilt rather than patched in place, which |
| 574 | /// is what keeps every ancestor's size right by construction. |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | /// Offset and payload of the first top-level box of type `want`. |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | /// `moov` down to the sample descriptions, which is where the entry lives. |
| 625 | const STSD_PATH: = ; |
| 626 | |
| 627 | /// The box at `depth` of [`STSD_PATH`], rebuilt with its `avc1` entry given a |
| 628 | /// `colr` box and, where `entry` says so, another four-character name and |
| 629 | /// configuration box. `None` where this branch holds no such entry -- an audio |
| 630 | /// `trak` is walked into and comes back untouched, which is how the *video* |
| 631 | /// track is found without being told which id it has. |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | /// The title of each subtitle track into the `trak` that carries it, in the |
| 682 | /// order they were written: a `udta` holding a `name` box, which is where an mp4 |
| 683 | /// says what a track is *called* (`Signs`) beside the `mdhd` language it is in |
| 684 | /// -- the pair Matroska spells as `Name` and `Language`, and the very boxes |
| 685 | /// ffmpeg writes a `-metadata:s:s:0 title=` into and reads back out. |
| 686 | /// `mp4 0.14`'s `TrakBox` has no `udta` field at all, so it is appended here |
| 687 | /// beside the sample entry rewrite, on the same rebuilt `moov`. |
| 688 | /// |
| 689 | /// Untouched where no track has a title -- and returned as it came for a file |
| 690 | /// with no subtitles at all, which is every export that picked none. |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | /// Whether a `trak` is a subtitle one: its `mdia`'s `hdlr` names the `sbtl` |
| 720 | /// handler, which sits after the box's version, flags and the four `pre_defined` |
| 721 | /// bytes. |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | /// One mp4 box: 32-bit size, four-character type, payload. Every box inside a |
| 730 | /// `moov` fits that form -- the 64-bit one exists for `mdat`, which this never |
| 731 | /// rewrites. |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | // Matroska element ids, written with the leading length marker they carry in the |
| 739 | // file -- the same spelling `demux` reads them back with. |
| 740 | const EBML: u32 = 0x1A45_DFA3; |
| 741 | const EBML_VERSION: u32 = 0x4286; |
| 742 | const EBML_READ_VERSION: u32 = 0x42F7; |
| 743 | const EBML_MAX_ID_LENGTH: u32 = 0x42F2; |
| 744 | const EBML_MAX_SIZE_LENGTH: u32 = 0x42F3; |
| 745 | const DOC_TYPE: u32 = 0x4282; |
| 746 | const DOC_TYPE_VERSION: u32 = 0x4287; |
| 747 | const DOC_TYPE_READ_VERSION: u32 = 0x4285; |
| 748 | const SEGMENT: u32 = 0x1853_8067; |
| 749 | const INFO: u32 = 0x1549_A966; |
| 750 | const TIMESTAMP_SCALE: u32 = 0x2AD7B1; |
| 751 | const DURATION: u32 = 0x4489; |
| 752 | const MUXING_APP: u32 = 0x4D80; |
| 753 | const WRITING_APP: u32 = 0x5741; |
| 754 | const TRACKS: u32 = 0x1654_AE6B; |
| 755 | const TRACK_ENTRY: u32 = 0xAE; |
| 756 | const TRACK_NUMBER: u32 = 0xD7; |
| 757 | const TRACK_UID: u32 = 0x73C5; |
| 758 | const TRACK_TYPE: u32 = 0x83; |
| 759 | const FLAG_LACING: u32 = 0x9C; |
| 760 | const CODEC_ID: u32 = 0x86; |
| 761 | const CODEC_PRIVATE: u32 = 0x63A2; |
| 762 | const DEFAULT_DURATION: u32 = 0x23E383; |
| 763 | const VIDEO: u32 = 0xE0; |
| 764 | const PIXEL_WIDTH: u32 = 0xB0; |
| 765 | const PIXEL_HEIGHT: u32 = 0xBA; |
| 766 | // `Colour` and the four children this writes, all inside `Video`. Byte-verified |
| 767 | // against what `demux` reads back and what ffprobe reports: the spec tables that |
| 768 | // list Range as 0x55B3 are describing ChromaSubsamplingHorz. |
| 769 | const COLOUR: u32 = 0x55B0; |
| 770 | const MATRIX_COEFFICIENTS: u32 = 0x55B1; |
| 771 | const RANGE: u32 = 0x55B9; |
| 772 | const TRANSFER_CHARACTERISTICS: u32 = 0x55BA; |
| 773 | const PRIMARIES: u32 = 0x55BB; |
| 774 | const AUDIO: u32 = 0xE1; |
| 775 | const SAMPLING_FREQUENCY: u32 = 0xB5; |
| 776 | const CHANNELS: u32 = 0x9F; |
| 777 | const CODEC_DELAY: u32 = 0x56AA; |
| 778 | const SEEK_PRE_ROLL: u32 = 0x56BB; |
| 779 | const CLUSTER: u32 = 0x1F43_B675; |
| 780 | const CLUSTER_TIMESTAMP: u32 = 0xE7; |
| 781 | const SIMPLE_BLOCK: u32 = 0xA3; |
| 782 | const TRACK_NAME: u32 = 0x536E; |
| 783 | const TRACK_LANGUAGE: u32 = 0x22B59C; |
| 784 | const BLOCK_GROUP: u32 = 0xA0; |
| 785 | const BLOCK: u32 = 0xA1; |
| 786 | const BLOCK_DURATION: u32 = 0x9B; |
| 787 | |
| 788 | /// One millisecond, the tick every Matroska muxer writes and this one's block |
| 789 | /// timestamps are in. The *rate* is not derived from these -- `DefaultDuration` |
| 790 | /// is, in exact nanoseconds -- so a millisecond is precise enough for the |
| 791 | /// presentation times and coarse enough to keep a cluster's 16-bit relative |
| 792 | /// timestamp covering half a minute. |
| 793 | const TIMESTAMP_SCALE_NS: u64 = 1_000_000; |
| 794 | /// A cluster is buffered whole (its size is a header field), so it is flushed |
| 795 | /// at the first keyframe past this -- a ceiling on what the muxer holds, not a |
| 796 | /// target. |
| 797 | const CLUSTER_BYTES: usize = 4 << 20; |
| 798 | /// ...and on how far a block's timestamp may sit from its cluster's: the field |
| 799 | /// is a signed 16-bit millisecond count. |
| 800 | const CLUSTER_MS: i64 = 30_000; |
| 801 | |
| 802 | /// The fixed four bytes of an `AV1CodecConfigurationRecord` for what both encode |
| 803 | /// paths here are configured to produce: profile 0, 8-bit, 4:2:0, no operating |
| 804 | /// point delay. `seq_level_idx` is written as 31 -- "maximum parameters", i.e. |
| 805 | /// unstated -- which is what rav1e's own `container_sequence_header` writes and |
| 806 | /// what keeps this record from claiming a level neither encoder promised. The |
| 807 | /// sequence header OBU follows it; that is where a decoder reads the real |
| 808 | /// parameters from, and `demux::parse_av1c` hands exactly those bytes back. |
| 809 | const AV1C_HEAD: = |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | ; |
| 815 | |
| 816 | /// What an AV1 Matroska track declares. `config` is the sequence header OBU, |
| 817 | /// which is [`av1_sequence_header`]'s answer for the first coded keyframe. |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | /// What an HEVC track declares in either container: the `hvcC` record |
| 826 | /// [`hvcc_record`] built out of the encoder's own VPS/SPS/PPS. The dimensions |
| 827 | /// are the *displayed* ones -- the coded picture is padded up to the 16-sample |
| 828 | /// CTB grid and the SPS crops it back with a conformance window, which is the |
| 829 | /// size a decoder outputs and therefore the size the container states. |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | /// What a *copied* track declares: the source's own codec id and configuration |
| 838 | /// record, in the space its samples are really in. |
| 839 | /// |
| 840 | /// Nothing here is derived from the timeline -- the copy exists precisely |
| 841 | /// because none of it changed -- so the picture keeps the size, the rate, the |
| 842 | /// curve and the parameter sets it was coded with. |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | /// The soft subtitle track a file carries beside the picture: text, timed, still |
| 863 | /// text in the file -- a player draws it and a user can turn it off, which is |
| 864 | /// what "soft" means and what burning it into the pixels is not. |
| 865 | /// |
| 866 | /// Both containers carry one: Matroska as an `S_TEXT/UTF8` track whose blocks |
| 867 | /// are the cues themselves ([`MkvMuxer`]), an mp4 as a `tx3g` timed-text track |
| 868 | /// whose samples run end to end over the film |
| 869 | /// ([`Mp4Muxer::write_subtitles`]). |
| 870 | /// |
| 871 | /// The cues are the *exported timeline's* (`export::timeline_cues` puts them |
| 872 | /// there), because the file's clock is the timeline's; nothing here shifts |
| 873 | /// anything. |
| 874 | |
| 875 | |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | /// The cues of one subtitle track waiting to be interleaved into the clusters, |
| 889 | /// [`MkvAudio`]'s twin. One of these per track the file carries. |
| 890 | |
| 891 | |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | /// Writes one AV1 video track as Matroska (`.mkv`), and the timeline's AAC |
| 900 | /// beside it where there is any: an `A_AAC` track whose `CodecPrivate` is the |
| 901 | /// two-byte `AudioSpecificConfig` an mp4's `esds` carries, which is what |
| 902 | /// symphonia's `mkv` reader -- this project's own way back in -- configures its |
| 903 | /// decoder from. An AV1 export used to be picture alone; a video file whose |
| 904 | /// sound was silently left behind is exactly the failure nobody notices until |
| 905 | /// the file has gone somewhere. |
| 906 | /// |
| 907 | /// The sound is *interleaved*: each packet is written into the cluster of the |
| 908 | /// picture it plays under, so a player has both by the time it needs them rather |
| 909 | /// than a file it must read to the end of to hear. |
| 910 | /// |
| 911 | /// The file is patched twice at [`finish`](MkvMuxer::finish) -- the segment size |
| 912 | /// and the duration -- so a killed process leaves an unfinished file rather than |
| 913 | /// a wrong one; the export's `.part` rename covers that already. |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 | |
| 931 | |
| 932 | |
| 933 | |
| 934 | |
| 935 | |
| 936 | |
| 937 | |
| 938 | |
| 939 | /// The sound waiting to be interleaved into the clusters. |
| 940 | |
| 941 | |
| 942 | |
| 943 | |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
| 948 | |
| 949 | |
| 950 | |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | |
| 964 | |
| 965 | |
| 966 | |
| 967 | |
| 968 | |
| 969 | |
| 970 | |
| 971 | |
| 972 | |
| 973 | |
| 974 | |
| 975 | |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 992 | |
| 993 | |
| 994 | |
| 995 | |
| 996 | |
| 997 | |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | |
| 1006 | |
| 1007 | |
| 1008 | |
| 1009 | |
| 1010 | |
| 1011 | |
| 1012 | |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | |
| 1019 | |
| 1020 | |
| 1021 | |
| 1022 | |
| 1023 | |
| 1024 | |
| 1025 | |
| 1026 | |
| 1027 | |
| 1028 | |
| 1029 | |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | |
| 1037 | |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | |
| 1045 | |
| 1046 | |
| 1047 | |
| 1048 | |
| 1049 | |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | |
| 1056 | |
| 1057 | |
| 1058 | |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | |
| 1063 | |
| 1064 | |
| 1065 | |
| 1066 | |
| 1067 | |
| 1068 | |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | |
| 1093 | |
| 1094 | |
| 1095 | |
| 1096 | |
| 1097 | |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | |
| 1102 | |
| 1103 | |
| 1104 | |
| 1105 | |
| 1106 | |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | |
| 1114 | |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | |
| 1143 | |
| 1144 | |
| 1145 | |
| 1146 | |
| 1147 | |
| 1148 | |
| 1149 | |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | |
| 1182 | |
| 1183 | |
| 1184 | |
| 1185 | |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | |
| 1200 | |
| 1201 | |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | |
| 1212 | |
| 1213 | |
| 1214 | |
| 1215 | |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | |
| 1264 | |
| 1265 | |
| 1266 | |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | |
| 1285 | |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | |
| 1295 | |
| 1296 | |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | |
| 1302 | |
| 1303 | |
| 1304 | |
| 1305 | |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | |
| 1328 | |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | |
| 1358 | |
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | |
| 1366 | |
| 1367 | |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 1386 | /// The `TrackEntry` of the AAC track: `A_AAC`, whose `CodecPrivate` is the |
| 1387 | /// two-byte `AudioSpecificConfig` an mp4 states inside its `esds` -- object type |
| 1388 | /// 2 (AAC-LC), the sample rate as its index into the AAC table, and the channel |
| 1389 | /// configuration. symphonia's `mkv` reader hands exactly these bytes to its AAC |
| 1390 | /// decoder, which is how a file written here reads back here. |
| 1391 | /// |
| 1392 | /// `CodecDelay` is one packet: the first AAC access unit of both paths that |
| 1393 | /// reach this -- a copy, whose head packet is the source's priming, and this |
| 1394 | /// project's own encoder, whose delay is one 1024-frame block -- is that delay, |
| 1395 | /// and an mp4 reader drops it by convention where Matroska has to be told in |
| 1396 | /// nanoseconds. |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | |
| 1411 | |
| 1412 | |
| 1413 | |
| 1414 | |
| 1415 | |
| 1416 | |
| 1417 | |
| 1418 | |
| 1419 | |
| 1420 | |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 | |
| 1425 | |
| 1426 | |
| 1427 | |
| 1428 | |
| 1429 | |
| 1430 | |
| 1431 | |
| 1432 | /// The same track when the sound is Opus: `A_OPUS`, whose `CodecPrivate` is the |
| 1433 | /// 19-byte `OpusHead` identification header of RFC 7845 §5.1 -- the very bytes |
| 1434 | /// an Ogg Opus file opens with, which is why one writer serves both containers |
| 1435 | /// and why this project's own reader configures itself from it unchanged |
| 1436 | /// (`audio::opus_pre_skip` and `audio::opus_layout` parse exactly this). |
| 1437 | /// |
| 1438 | /// Mapping family 0: mono or stereo, no channel-mapping table, which is the only |
| 1439 | /// shape [`crate::export::encode_opus`] writes. The rate field is what the |
| 1440 | /// *input* was, not what the stream is coded at -- every Opus decoder runs at |
| 1441 | /// 48 kHz whatever it says -- and the output gain is 0 because the mix is |
| 1442 | /// already at the level the timeline asked for. |
| 1443 | /// |
| 1444 | /// Two elements no AAC track needs, and both are the difference between a file |
| 1445 | /// that plays in sync and one that does not: |
| 1446 | /// * `CodecDelay`, the pre-skip in nanoseconds. Matroska times an Opus block for |
| 1447 | /// the *audible* stream while the decoder hands back the pre-skip in front of |
| 1448 | /// it, so a reader that ignores this starts 2.5 ms early -- measured the other |
| 1449 | /// way round on a real film remux (`audio::Track::samples_at`). |
| 1450 | /// * `SeekPreRoll`, fixed at 80 ms for Opus by the Matroska spec: how much has |
| 1451 | /// to be decoded and thrown away before a seek target for the decoder to be |
| 1452 | /// warm. It is a constant of the codec, not of the file. |
| 1453 | |
| 1454 | |
| 1455 | |
| 1456 | |
| 1457 | |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | |
| 1464 | |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | |
| 1469 | |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | |
| 1474 | |
| 1475 | |
| 1476 | |
| 1477 | |
| 1478 | |
| 1479 | |
| 1480 | |
| 1481 | |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | |
| 1493 | /// Which track the *first* subtitle block names, the picture's 1 and the sound's |
| 1494 | /// 2 being fixed: a file with no audio track still writes its first text track |
| 1495 | /// on 3, so nothing has to count the tracks before it to read a block. Each |
| 1496 | /// further subtitle track is the next number up. |
| 1497 | const SUB_TRACK_FIRST: u8 = 3; |
| 1498 | |
| 1499 | /// How many subtitle tracks one file may carry. A block writes its track number |
| 1500 | /// as a one-byte EBML integer (`0x80 | track`, [`MkvMuxer::block`]), and 127 is |
| 1501 | /// one number too far: its byte is `0xFF`, the all-ones variable-length integer |
| 1502 | /// EBML spells *unknown* with, which this project's own reader hands back as |
| 1503 | /// `u64::MAX` (`demux`'s `vint`) -- so track 127's blocks would match no track, |
| 1504 | /// its cues would vanish on the way back in, and the file would be one edith |
| 1505 | /// wrote and cannot read. The numbers therefore run `3..=126` and the count is |
| 1506 | /// what is left of them -- derived from the encoding, so it cannot drift from |
| 1507 | /// it. A file asking for more is refused by name in [`MkvMuxer::open`] rather |
| 1508 | /// than written with a byte that means another track, or none. |
| 1509 | pub const MAX_SUB_TRACKS: usize = 0x7F - SUB_TRACK_FIRST as usize; |
| 1510 | |
| 1511 | /// The `TrackEntry` of the subtitle track: type 0x11 (subtitles) and |
| 1512 | /// `S_TEXT/UTF8`, whose blocks are the cue's own UTF-8 text and whose timing is |
| 1513 | /// the block's -- the codec every player draws and the one this project's own |
| 1514 | /// reader parses back (`subtitle::cues_of`). |
| 1515 | /// |
| 1516 | /// The two names a track has are written as the two fields Matroska has for |
| 1517 | /// them: `Language` is what a player's subtitle menu offers and what a "play |
| 1518 | /// French" setting matches on, `Name` is the title beside it (`Signs`). Both |
| 1519 | /// where the source has both -- a track carrying only a name is an *English* |
| 1520 | /// track to every reader, that being the spec's default, which is how a |
| 1521 | /// multi-language film used to export as several English ones. Either is left |
| 1522 | /// out where it is empty, and [`crate::subtitle::of_matroska`] reads exactly |
| 1523 | /// this back, so a track exported and re-imported keeps what it had. |
| 1524 | |
| 1525 | |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | |
| 1530 | |
| 1531 | |
| 1532 | |
| 1533 | |
| 1534 | |
| 1535 | |
| 1536 | |
| 1537 | |
| 1538 | |
| 1539 | |
| 1540 | /// The sequence header OBU of a coded temporal unit, for the track's |
| 1541 | /// `CodecPrivate`. `None` when the unit carries none, which the first keyframe |
| 1542 | /// of a stream never may -- no decoder can start without it. |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | |
| 1547 | |
| 1548 | |
| 1549 | |
| 1550 | |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | |
| 1555 | |
| 1556 | |
| 1557 | |
| 1558 | |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | |
| 1563 | |
| 1564 | |
| 1565 | |
| 1566 | |
| 1567 | /// An unsigned LEB128 as AV1 writes its OBU sizes: `(value, bytes read)`. |
| 1568 | |
| 1569 | |
| 1570 | |
| 1571 | |
| 1572 | |
| 1573 | |
| 1574 | |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | |
| 1579 | /// An element id, written as the bytes it is spelled with -- the leading zeros |
| 1580 | /// of the constant are not part of it. |
| 1581 | |
| 1582 | |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | |
| 1587 | /// An element size as an EBML variable-length integer, in the fewest bytes that |
| 1588 | /// hold it. A value of all ones means *unknown* length, so a size that would |
| 1589 | /// land on one takes a byte more. |
| 1590 | |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | |
| 1597 | |
| 1598 | |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | |
| 1603 | |
| 1604 | |
| 1605 | /// An unsigned integer element, big-endian in as few bytes as it takes (one at |
| 1606 | /// the least: a zero is a byte, not an absence). |
| 1607 | |
| 1608 | |
| 1609 | |
| 1610 | |
| 1611 | |
| 1612 | |
| 1613 | /// How many bytes an element's id and size take, which is what an offset inside |
| 1614 | /// a payload has to be moved by to become an offset in the file. |
| 1615 | |
| 1616 | |
| 1617 | |
| 1618 | |
| 1619 | |
| 1620 | |
| 1621 | |
| 1622 | /// `(timescale, ticks per frame)` for `fps`, chosen so one frame is a *whole* |
| 1623 | /// number of ticks: 90 kHz wherever it divides exactly (every integer rate, so |
| 1624 | /// those exports stay byte for byte what they were), and `round(fps * 1001)` |
| 1625 | /// over [`NTSC_TICKS`] otherwise, which is exact for the whole `n/1001` family. |
| 1626 | /// A fixed 90 kHz clock leaves 24000/1001 a quarter tick short *per frame* -- |
| 1627 | /// half a second of drift against the audio track by the end of a two-hour |
| 1628 | /// export, which is this bug's own truncation reborn at the writing end. |
| 1629 | pub |
| 1630 | |
| 1631 | |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | |
| 1637 | |
| 1638 | |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | /// SPS and PPS of an Annex-B access unit, for the `avcC` box. `None` when the |
| 1643 | /// unit does not carry both, which the first exported unit always must. |
| 1644 | |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | |
| 1650 | |
| 1651 | /// The `HEVCDecoderConfigurationRecord` an HEVC track declares, built out of the |
| 1652 | /// parameter sets the encoder put in its first access unit -- the exact record |
| 1653 | /// `demux::parse_hvcc` reads back, which is what makes an export of this |
| 1654 | /// project's own something it can re-open. |
| 1655 | /// |
| 1656 | /// The 22 fixed bytes before the arrays: the 12-byte `profile_tier_level` is |
| 1657 | /// copied straight out of the SPS (its first 12 bytes after the two-byte NAL |
| 1658 | /// header and the four `sps_video_parameter_set_id`/`sps_max_sub_layers_minus1` |
| 1659 | /// /`sps_temporal_id_nesting_flag` bits -- §7.3.2.2 puts the PTL there and the |
| 1660 | /// hvcC header states the same fields in the same order), and the rest is what |
| 1661 | /// this encoder is: 4:2:0, 8-bit, one temporal layer, 4-byte NAL lengths. Only |
| 1662 | /// the *arrays* are read by anything here, but a record whose header lied about |
| 1663 | /// the profile would be a file `ffprobe` disagrees with. |
| 1664 | /// |
| 1665 | /// `None` where the unit carries no VPS, SPS or PPS -- the first coded intra AU |
| 1666 | /// always carries all three. |
| 1667 | |
| 1668 | |
| 1669 | |
| 1670 | |
| 1671 | |
| 1672 | |
| 1673 | |
| 1674 | |
| 1675 | |
| 1676 | |
| 1677 | |
| 1678 | |
| 1679 | |
| 1680 | |
| 1681 | |
| 1682 | |
| 1683 | |
| 1684 | |
| 1685 | |
| 1686 | |
| 1687 | |
| 1688 | |
| 1689 | |
| 1690 | |
| 1691 | |
| 1692 | |
| 1693 | |
| 1694 | |
| 1695 | |
| 1696 | /// One HEVC access unit as a sample of both containers: 4-byte length prefixes, |
| 1697 | /// parameter sets dropped (they are in the `hvcC`, which is what `hvc1` and a |
| 1698 | /// Matroska `CodecPrivate` both promise). `None` where the unit holds no coded |
| 1699 | /// slice at all. |
| 1700 | pub |
| 1701 | |
| 1702 | |
| 1703 | |
| 1704 | |
| 1705 | |
| 1706 | |
| 1707 | |
| 1708 | |
| 1709 | |
| 1710 | |
| 1711 | |
| 1712 | |
| 1713 | |
| 1714 | /// §7.3.1.2 `nal_unit_type`, the six bits after the forbidden_zero_bit. |
| 1715 | |
| 1716 | |
| 1717 | |
| 1718 | |
| 1719 | const HEVC_VPS: u8 = 32; |
| 1720 | const HEVC_SPS: u8 = 33; |
| 1721 | const HEVC_PPS: u8 = 34; |
| 1722 | |
| 1723 | /// A coded NAL payload back to its RBSP: every `00 00 03` loses the `03` |
| 1724 | /// (§7.3.1.1). Only ever asked of an SPS, which is short. |
| 1725 | |
| 1726 | |
| 1727 | |
| 1728 | |
| 1729 | |
| 1730 | |
| 1731 | |
| 1732 | |
| 1733 | |
| 1734 | |
| 1735 | |
| 1736 | /// Whether the unit carries a coded picture (NAL types 1..=5). An encoder that |
| 1737 | /// buffered instead of coding hands back an empty buffer, and one that emitted |
| 1738 | /// only parameter sets has no sample to write -- both are for the caller to skip |
| 1739 | /// rather than for [`Mp4Muxer::write_video_au`] to reject. |
| 1740 | pub |
| 1741 | |
| 1742 | |
| 1743 | |
| 1744 | |
| 1745 | |
| 1746 | /// Exact inverse of `demux::append_annex_b`: 4-byte length prefixes (the only |
| 1747 | /// prefix size `mp4` writes, avc1.rs hardcodes `length_size_minus_one = 3`). |
| 1748 | /// Parameter sets, access unit delimiters and SEI are stripped — the first two |
| 1749 | /// are redundant with `avcC`, SEI is not worth carrying. Returns the sample |
| 1750 | /// bytes and whether the unit is an IDR. |
| 1751 | |
| 1752 | |
| 1753 | |
| 1754 | |
| 1755 | |
| 1756 | |
| 1757 | |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | |
| 1762 | |
| 1763 | |
| 1764 | |
| 1765 | |
| 1766 | |
| 1767 | |
| 1768 | |
| 1769 | /// NAL payloads of an Annex-B buffer, both 3- and 4-byte start codes, trailing |
| 1770 | /// zero bytes trimmed (they belong to the next start code, or are padding). |
| 1771 | |
| 1772 | |
| 1773 | |
| 1774 | |
| 1775 | |
| 1776 | |
| 1777 | |
| 1778 | |
| 1779 | |
| 1780 | |
| 1781 | |
| 1782 | |
| 1783 | |
| 1784 | |
| 1785 | |
| 1786 | |
| 1787 | |
| 1788 | |
| 1789 | |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | |
| 1808 | |
| 1809 | |
| 1810 | |
| 1811 | |
| 1812 | |
| 1813 | |
| 1814 | |
| 1815 | |
| 1816 | |
| 1817 | |
| 1818 | |
| 1819 | |
| 1820 | |
| 1821 | |
| 1822 | |
| 1823 | |
| 1824 | |
| 1825 | |
| 1826 | |
| 1827 | |
| 1828 | |
| 1829 | |
| 1830 | |
| 1831 | |
| 1832 | |
| 1833 | |
| 1834 | |
| 1835 | |
| 1836 | |
| 1837 | |
| 1838 | |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | |
| 1846 | |
| 1847 | |
| 1848 | |
| 1849 | |
| 1850 | |
| 1851 | |
| 1852 | |
| 1853 | |
| 1854 | |
| 1855 | |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | |
| 1862 | |
| 1863 | |
| 1864 | |
| 1865 | |
| 1866 | |
| 1867 | |
| 1868 | |
| 1869 | |
| 1870 | |
| 1871 | |
| 1872 | |
| 1873 | |
| 1874 | |
| 1875 | |
| 1876 | |
| 1877 | |
| 1878 | |
| 1879 | |
| 1880 | |
| 1881 | |
| 1882 | |
| 1883 | |
| 1884 | |
| 1885 | |
| 1886 | |
| 1887 | |
| 1888 | |
| 1889 | |
| 1890 | |
| 1891 | |
| 1892 | |
| 1893 | |
| 1894 | |
| 1895 | |
| 1896 | |
| 1897 | |
| 1898 | |
| 1899 | |
| 1900 | |
| 1901 | |
| 1902 | |
| 1903 | |
| 1904 | |
| 1905 | |
| 1906 | |
| 1907 | |
| 1908 | |
| 1909 | |
| 1910 | |
| 1911 | |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | |
| 1917 | |
| 1918 | |
| 1919 | |
| 1920 | |
| 1921 | |
| 1922 | |
| 1923 | |
| 1924 | |
| 1925 | |
| 1926 | |
| 1927 | |
| 1928 | |
| 1929 | |
| 1930 | |
| 1931 | |
| 1932 | |
| 1933 | |
| 1934 | |
| 1935 | |
| 1936 | |
| 1937 | |
| 1938 | |
| 1939 | |
| 1940 | |
| 1941 | |
| 1942 | |
| 1943 | |
| 1944 | |
| 1945 | |
| 1946 | |
| 1947 | |
| 1948 | |
| 1949 | |
| 1950 | |
| 1951 | |
| 1952 | |
| 1953 | |
| 1954 | |
| 1955 | |
| 1956 | |
| 1957 | |
| 1958 | |
| 1959 | |
| 1960 | |
| 1961 | |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | |
| 1966 | |
| 1967 | |
| 1968 | |
| 1969 | |
| 1970 | |
| 1971 | |
| 1972 | |
| 1973 | |
| 1974 | |
| 1975 | |
| 1976 | |
| 1977 | |
| 1978 | |
| 1979 | |
| 1980 | |
| 1981 | |
| 1982 | |
| 1983 | |
| 1984 | |
| 1985 | |
| 1986 | |
| 1987 | |
| 1988 | |
| 1989 | |
| 1990 | |
| 1991 | |
| 1992 | |
| 1993 | |
| 1994 | |
| 1995 | |
| 1996 | |
| 1997 | |
| 1998 | |
| 1999 | |
| 2000 | |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | |
| 2005 | |
| 2006 | |
| 2007 | |
| 2008 | |
| 2009 | |
| 2010 | |
| 2011 | |
| 2012 | |
| 2013 | |
| 2014 | |
| 2015 | |
| 2016 | |
| 2017 | |
| 2018 | |
| 2019 | |
| 2020 | |
| 2021 | |
| 2022 | |
| 2023 | |
| 2024 | |
| 2025 | |
| 2026 | |
| 2027 | |
| 2028 | |
| 2029 | |
| 2030 | |
| 2031 | |
| 2032 | |
| 2033 | |
| 2034 | |
| 2035 | |
| 2036 | |
| 2037 | |
| 2038 | |
| 2039 | |
| 2040 | |
| 2041 | |
| 2042 | |
| 2043 | |
| 2044 | |
| 2045 | |
| 2046 | |
| 2047 | |
| 2048 | |
| 2049 | |
| 2050 | |
| 2051 | |
| 2052 | |
| 2053 | |
| 2054 | |
| 2055 | |
| 2056 | |
| 2057 | |
| 2058 | |
| 2059 | |
| 2060 | |
| 2061 | |
| 2062 | |
| 2063 | |
| 2064 | |
| 2065 | |
| 2066 | |
| 2067 | |
| 2068 | |
| 2069 | |
| 2070 | |
| 2071 | |
| 2072 | |
| 2073 | |
| 2074 | |
| 2075 | |
| 2076 | |
| 2077 | |
| 2078 | |
| 2079 | |
| 2080 | |
| 2081 | |
| 2082 | |
| 2083 | |
| 2084 | |
| 2085 | |
| 2086 | |
| 2087 | |
| 2088 | |
| 2089 | |
| 2090 | |
| 2091 | |
| 2092 | |
| 2093 | |
| 2094 | |
| 2095 | |
| 2096 | |
| 2097 | |
| 2098 | |
| 2099 | |
| 2100 | |
| 2101 | |
| 2102 | |
| 2103 | |
| 2104 | |
| 2105 | |
| 2106 | |
| 2107 | |
| 2108 | |
| 2109 | |
| 2110 | |
| 2111 | |
| 2112 | |
| 2113 | |
| 2114 | |
| 2115 | |
| 2116 | |
| 2117 | |
| 2118 | |
| 2119 | |
| 2120 | |
| 2121 | |
| 2122 | |
| 2123 | |
| 2124 | |
| 2125 | |
| 2126 | |
| 2127 | |
| 2128 | |
| 2129 | |
| 2130 | |
| 2131 | |
| 2132 | |
| 2133 | |
| 2134 | |
| 2135 | |
| 2136 | |
| 2137 | |
| 2138 | |
| 2139 | |
| 2140 | |
| 2141 | |
| 2142 | |
| 2143 | |
| 2144 | |
| 2145 | |
| 2146 | |
| 2147 | |
| 2148 | |
| 2149 | |
| 2150 | |
| 2151 | |
| 2152 | |
| 2153 | |
| 2154 | |
| 2155 | |
| 2156 | |
| 2157 | |
| 2158 | |
| 2159 | |
| 2160 | |
| 2161 | |
| 2162 | |
| 2163 | |
| 2164 | |
| 2165 | |
| 2166 | |
| 2167 | |
| 2168 | |
| 2169 | |
| 2170 | |
| 2171 | |
| 2172 | |
| 2173 | |
| 2174 | |
| 2175 | |
| 2176 | |
| 2177 | |
| 2178 | |
| 2179 | |
| 2180 | |
| 2181 | |
| 2182 | |
| 2183 | |
| 2184 | |
| 2185 | |
| 2186 | |
| 2187 | |
| 2188 | |
| 2189 | |
| 2190 | |
| 2191 | |
| 2192 | |
| 2193 | |
| 2194 | |
| 2195 | |
| 2196 | |
| 2197 | |
| 2198 | |
| 2199 | |
| 2200 | |
| 2201 | |
| 2202 | |
| 2203 | |
| 2204 | |
| 2205 | |
| 2206 | |
| 2207 | |
| 2208 | |
| 2209 | |
| 2210 | |
| 2211 | |
| 2212 | |
| 2213 | |
| 2214 | |
| 2215 | |
| 2216 | |
| 2217 | |
| 2218 | |
| 2219 | |
| 2220 | |
| 2221 | |
| 2222 | |
| 2223 | |
| 2224 | |
| 2225 | |
| 2226 | |
| 2227 | |
| 2228 | |
| 2229 | |
| 2230 | |
| 2231 | |
| 2232 | |
| 2233 | |
| 2234 | |
| 2235 | |
| 2236 | |
| 2237 | |
| 2238 | |
| 2239 | |
| 2240 | |
| 2241 | |
| 2242 | |
| 2243 | |
| 2244 | |
| 2245 | |
| 2246 | |
| 2247 | |
| 2248 | |
| 2249 | |
| 2250 | |
| 2251 | |
| 2252 | |
| 2253 | |
| 2254 | |
| 2255 | |
| 2256 | |
| 2257 | |
| 2258 | |
| 2259 | |
| 2260 | |
| 2261 | |
| 2262 | |
| 2263 | |
| 2264 | |
| 2265 | |
| 2266 | |
| 2267 | |
| 2268 | |
| 2269 | |
| 2270 | |
| 2271 | |
| 2272 | |
| 2273 | |
| 2274 | |
| 2275 | |
| 2276 | |
| 2277 | |
| 2278 | |
| 2279 | |
| 2280 | |
| 2281 | |
| 2282 | |
| 2283 | |
| 2284 | |
| 2285 | |
| 2286 | |
| 2287 | |
| 2288 | |
| 2289 | |
| 2290 | |
| 2291 | |
| 2292 | |
| 2293 | |
| 2294 | |
| 2295 | |
| 2296 | |
| 2297 | |
| 2298 | |
| 2299 | |
| 2300 | |
| 2301 | |
| 2302 | |
| 2303 | |
| 2304 | |
| 2305 | |
| 2306 | |
| 2307 | |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | |
| 2312 | |
| 2313 | |
| 2314 | |
| 2315 | |
| 2316 | |
| 2317 | |
| 2318 | |
| 2319 | |
| 2320 | |
| 2321 | |
| 2322 | |
| 2323 | |
| 2324 | |
| 2325 | |
| 2326 | |
| 2327 | |
| 2328 | |
| 2329 | |
| 2330 | |
| 2331 | |
| 2332 | |
| 2333 | |
| 2334 | |
| 2335 | |
| 2336 | |
| 2337 | |
| 2338 | |
| 2339 | |
| 2340 | |
| 2341 | |
| 2342 | |
| 2343 | |
| 2344 | |
| 2345 | |
| 2346 | |
| 2347 | |
| 2348 | |
| 2349 | |
| 2350 | |
| 2351 | |
| 2352 | |
| 2353 | |
| 2354 | |
| 2355 | |
| 2356 | |
| 2357 | |
| 2358 | |
| 2359 | |
| 2360 | |
| 2361 | |
| 2362 | |
| 2363 | |
| 2364 | |
| 2365 | |
| 2366 | |
| 2367 | |
| 2368 | |
| 2369 | |
| 2370 | |
| 2371 | |
| 2372 | |
| 2373 | |
| 2374 | |
| 2375 | |
| 2376 | |
| 2377 | |
| 2378 | |
| 2379 | |
| 2380 | |
| 2381 | |
| 2382 | |
| 2383 | |
| 2384 |