edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiB86e9455Tahinli3 months ago398 commits
| 1 | //! Export: the edit list rendered back out as one mp4 (H.264, AV1 or HEVC) or |
| 2 | //! one Matroska file (AV1 or HEVC) — or, picture left behind, as one WAV, FLAC, |
| 3 | //! MP3 or Ogg Vorbis of the timeline's audio alone. |
| 4 | //! |
| 5 | //! The HEVC pair is **intra-only**, and says so wherever it is offered: every |
| 6 | //! frame is a self-contained IDR from the vendored `oxideav-h265`, which is the |
| 7 | //! only shape of a pure-Rust HEVC encode fast enough to wait for (its inter |
| 8 | //! modes code 1080p at 0.81 fps across 12 cores against the intra path's 4.30). |
| 9 | //! That makes it an intraframe master in the family of ProRes and DNxHD — large |
| 10 | //! files, every frame a cut point — and not a delivery codec. |
| 11 | //! |
| 12 | //! Picture and sound are both **copied wherever a copy says exactly what the |
| 13 | //! timeline says** — a copy is exact, free and never a generation of loss. For |
| 14 | //! the sound that is packet for packet ([`copy_audio`]); for the picture it is |
| 15 | //! block for block out of a Matroska source into a Matroska file ([`CopyPlan`]), |
| 16 | //! which is what makes a cut in a two-hour film cost the reading of it rather |
| 17 | //! than the re-encoding of it. The picture's copy is all-or-nothing per export, |
| 18 | //! because a copied span and an encoded one cannot share one track: what it |
| 19 | //! needs of a cut is that it lands on a sync point, and everything else — a |
| 20 | //! grade, a speed, a gap, a source of another size or codec, an mp4 — goes |
| 21 | //! through the encoder exactly as it always did. Where the *sound* cannot be |
| 22 | //! copied — a second audio lane to mix in, a speeded clip, an |
| 23 | //! equalized one, a source that is not AAC inside an mp4's own sample table — |
| 24 | //! the sound is decoded, mixed and encoded again with `rusty_aac` |
| 25 | //! ([`encode_audio`]). The audio-only formats have no such split: `hound` writes |
| 26 | //! PCM, `flacenc` encodes FLAC, `rusty_mp3` encodes MP3 and `rusty_vorbis` |
| 27 | //! encodes Vorbis, so those are always *decoded* out of the timeline. The worker owns everything: the caller gets an |
| 28 | //! [`ExportHandle`] and polls it from its render loop. |
| 29 | //! |
| 30 | //! **Every video format here carries the timeline's sound**, in whichever |
| 31 | //! container: the mp4 muxer writes an AAC track and so does the Matroska one. |
| 32 | //! Nothing is written picture-only and nothing is left silent without saying so |
| 33 | //! — the only sound that does not come out is sound this engine cannot decode at |
| 34 | //! all (Opus and AC-3 inside a Matroska file), and that is an error by name. |
| 35 | //! |
| 36 | //! A **speeded** clip splits along the same line, and for the same reason. The |
| 37 | //! picture is re-encoded, so the frame walk honours a rate: it takes the source |
| 38 | //! frame each timeline frame shows ([`crate::project::Speed::source_at`], the |
| 39 | //! very frame preview holds there) and encodes a held one again rather than |
| 40 | //! decoding it twice. A clip whose *file* was shot at another rate than the |
| 41 | //! timeline goes through the same walk with one more conversion on the end |
| 42 | //! ([`crate::project::Rate`]), so it is encoded at the speed it was shot at. |
| 43 | //! The sound is *copied* unless something forces a decode, and a packet carries |
| 44 | //! no rate — so a speeded lane is one of the things that forces one |
| 45 | //! ([`copy_audio`]) rather than being written out at 1.00x under a re-timed |
| 46 | //! picture. The audio-only formats are decoded and resampled, so they honour a |
| 47 | //! rate like the picture does. |
| 48 | //! |
| 49 | //! Nothing partial survives a failure: the worker writes to `<out>.part` and |
| 50 | //! renames it onto `out` only once the file is closed and complete, so the |
| 51 | //! output either does not exist or is finished — there is no window where a |
| 52 | //! half-written `.export.mp4` is sitting there looking playable. Cancel and |
| 53 | //! every error path delete the `.part`. A killed *process* leaves the `.part` |
| 54 | //! behind (only in-process cleanup is promised), which is an orphan a user can |
| 55 | //! delete rather than a file that plays for two seconds and stops. |
| 56 | |
| 57 | use File; |
| 58 | use ; |
| 59 | use ; |
| 60 | use ; |
| 61 | use ; |
| 62 | use ; |
| 63 | use thread; |
| 64 | |
| 65 | use ; |
| 66 | |
| 67 | use BitRepr; |
| 68 | use Verify; |
| 69 | // The trait the Ogg muxer's `write_header` / `write_packet` / `write_trailer` |
| 70 | // live on -- `oxideav_ogg::mux::open_concrete` hands back the concrete muxer |
| 71 | // (the only way to reach `set_page_target_bytes`), so the trait has to be here. |
| 72 | use Muxer as _; |
| 73 | |
| 74 | use crate; |
| 75 | use crate; |
| 76 | use crate; |
| 77 | use crate; |
| 78 | use crate |
| 79 | |
| 80 | ; |
| 81 | use crate; |
| 82 | use crateComposer; |
| 83 | use crate; |
| 84 | use crate; |
| 85 | |
| 86 | /// Progress is reported in permille: an atomic integer the render loop can read |
| 87 | /// without a lock, fine enough for any progress bar. |
| 88 | const PROGRESS_SCALE: u32 = 1_000; |
| 89 | |
| 90 | /// The head of the bar the *sound* owns, before a picture is written at all. |
| 91 | /// The mix is decoded, encoded and measured before the muxer exists ([`run`] |
| 92 | /// says why), and on a feature film that is a minute or two in which a bar |
| 93 | /// pinned at zero is the only thing on screen -- which reads as an export that |
| 94 | /// has hung. Small, because the picture is still nearly all of the work. |
| 95 | const AUDIO_BAND: u32 = PROGRESS_SCALE / 20; |
| 96 | |
| 97 | /// Where the bar stands with `done` of `total` pictures written: the sound's |
| 98 | /// band is already behind it ([`AUDIO_BAND`]), so the picture fills what is |
| 99 | /// left rather than starting again from zero. |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | /// D2 rate control: bits per pixel per second, then a sane range. 720p30 lands |
| 105 | /// at 2.76 Mbps, which S1 measured the software encoder hitting within 1%. |
| 106 | const BITS_PER_PIXEL: f64 = 0.1; |
| 107 | const MIN_BITRATE: u64 = 1_000_000; |
| 108 | const MAX_BITRATE: u64 = 20_000_000; |
| 109 | |
| 110 | /// The ceiling on a bitrate somebody *asked* for, which is a different question |
| 111 | /// from where the derived one stops: [`MAX_BITRATE`] is the top of the automatic |
| 112 | /// figure's sane range, and a rate a person typed is not that program's guess to |
| 113 | /// bound. Nothing in either encoder objects to it -- the VA-API seat takes a |
| 114 | /// `u64` and the software ones a `u32`/`i32`, all of which hold this with room |
| 115 | /// -- so the old shared ceiling was only ever the auto range wearing two hats. |
| 116 | const MAX_EXPLICIT_BITRATE: u64 = 50_000_000; |
| 117 | |
| 118 | /// The rates the sound may be coded at, smallest first -- what a front-end |
| 119 | /// offers and what [`ExportSettings::audio_kbps`] is clamped into. Every one of |
| 120 | /// them is a legal MPEG-1 Layer III value, so the MP3 path writes the figure it |
| 121 | /// was given rather than the nearest one `rusty_mp3` snaps to. |
| 122 | pub const AUDIO_KBPS: = ; |
| 123 | |
| 124 | /// What the sound is coded at when nobody picked: the rate this project wrote |
| 125 | /// before the choice existed. 256 and not the encoders' own 128, because an |
| 126 | /// export is a master a person edits from again and this is a second lossy |
| 127 | /// generation over sources that may already have been one -- measured on the |
| 128 | /// suite's fixtures, an untouched clip re-encoded moves 0.15 dB here against |
| 129 | /// 0.46 dB at 128, and 32 KB/s beside a 2.76 Mbps picture is not a size anyone |
| 130 | /// is counting. |
| 131 | pub const DEFAULT_AUDIO_KBPS: u32 = 256; |
| 132 | |
| 133 | /// `rav1e`'s fastest preset. Anything slower is minutes per second of timeline |
| 134 | /// on a build with no assembly, which is what this one is. |
| 135 | const AV1_SPEED: u8 = 10; |
| 136 | |
| 137 | /// The HEVC coding tree block this encoder is fixed at: the coded picture is a |
| 138 | /// whole number of them, which is what the conformance window crops back. |
| 139 | const CTB: usize = 16; |
| 140 | /// How many frames the intra HEVC encoder codes at once. Twelve is where the |
| 141 | /// 2026-08-11 bench stopped scaling on this box (4.30 fps at 1080p); more lanes |
| 142 | /// only holds more decoded frames in memory. |
| 143 | const HEVC_LANES: usize = 12; |
| 144 | /// Bits per pixel the intra encoder spends at QP 27, measured on the same bench: |
| 145 | /// 0.607 at 720p and 0.586 at 1080p. What [`hevc_qp`] maps a bitrate row through. |
| 146 | const HEVC_BPP_AT_27: f64 = 0.6; |
| 147 | /// The band [`hevc_qp`] is clamped into, for the reason stated there. |
| 148 | const HEVC_QP_MIN: i32 = 22; |
| 149 | const HEVC_QP_MAX: i32 = 40; |
| 150 | |
| 151 | /// What an export writes. H.264-in-mp4, AV1 and HEVC -- each of the last two in |
| 152 | /// Matroska or in mp4, the user's pick of container -- are the *video* pairs |
| 153 | /// with both an encoder and a decoder under this project's no-install rule, and |
| 154 | /// WAV, FLAC, MP3 and Ogg Vorbis are the standalone audio formats with a |
| 155 | /// pure-Rust encoder: `hound`, `flacenc`, `rusty_mp3` and `rusty_vorbis`. Opus |
| 156 | /// still has none -- `oxideav-opus` encodes CELT alone, which is half a codec. |
| 157 | /// (AAC has one too -- `rusty_aac`, which is what a re-encoded video track's |
| 158 | /// sound leaves through -- but AAC is a container's own audio, never a file of |
| 159 | /// its own here.) VP9 is the |
| 160 | /// one codec left that comes in through the plugin and stops there, HEVC having |
| 161 | /// gained an encoder (an intra-only one, which the rows say). A front-end says |
| 162 | /// so rather than hiding the row. |
| 163 | /// |
| 164 | /// **Every video format carries sound.** Which way it carries it is the only |
| 165 | /// difference: copied packet for packet where a copy can say what the timeline |
| 166 | /// says, decoded and encoded again ([`encode_audio`]) where it cannot. |
| 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 | /// What the caller gets to decide about the output. The codec is not among it: |
| 267 | /// [`Format`] names a container *and* what goes in it, because every pair we |
| 268 | /// can write is a pair we can also read back. |
| 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 | /// A running export. Poll [`is_finished`](ExportHandle::is_finished) once per |
| 317 | /// rendered frame and take the [`result`](ExportHandle::result) when it flips; |
| 318 | /// dropping the handle does *not* stop the worker, [`cancel`](ExportHandle::cancel) |
| 319 | /// does. |
| 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 | /// Starts the worker. Failures are reported through the handle rather than |
| 357 | /// returned, so a caller has exactly one place to look. The files to read are |
| 358 | /// the project's own [`sources`](Project::sources) -- every clip names one -- |
| 359 | /// so nothing but the edit list decides what is decoded. |
| 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 | /// Whether any video lane holds anything at all -- what tells an audio-only |
| 427 | /// timeline from one that merely opens on a gap. Asked of the *lanes* rather |
| 428 | /// than of the sources, because a project may name a video file no clip plays |
| 429 | /// from any more. |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | /// Whether any audio lane holds anything, [`has_picture`]'s pair: what tells a |
| 438 | /// timeline whose export will carry sound from one whose file has none. |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | /// Whether any equalizer on the sound is doing something -- the one edit a |
| 447 | /// packet copy cannot carry, so an mp4 whose lane has one is decoded and |
| 448 | /// re-encoded ([`encode_audio`]) instead of copied. Asked of every audio lane: |
| 449 | /// the copy path has exactly one by the time it asks, and [`planned_audio`] is |
| 450 | /// asked before that is settled. |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | /// Whether the *mix* is doing something -- a lane turned off unity, or a |
| 459 | /// limiter in circuit. [`equalized`]'s pair, and a copy cannot carry either of |
| 460 | /// them: both live where the lanes are summed |
| 461 | /// ([`AudioSession::open_mixed_streams_master`]), and a copied packet was never |
| 462 | /// summed at all. An mp4 whose timeline is mixed is decoded and re-encoded. |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | /// The bitrate an export codes at: the caller's number clamped into what an |
| 468 | /// asked-for rate may be ([`MAX_EXPLICIT_BITRATE`]), the derived one where there |
| 469 | /// was none. Clamped rather than refused, for the reason [`Enc::open`] states. |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | /// The rate the sound codes at: the caller's pick clamped into the offered |
| 478 | /// range, [`DEFAULT_AUDIO_KBPS`] where there was none. Clamped and not refused, |
| 479 | /// for [`bitrate_of`]'s reason -- a number out of range is a caller's slip and |
| 480 | /// not a file worth failing. |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | /// The hardware seat for these settings, opened exactly as the export opens it |
| 488 | /// -- the same pins, the same AV1 opt-in, the same dimensions a driver may |
| 489 | /// refuse -- or `None` where the software encoder takes the file. The single |
| 490 | /// place that choice is made, which is what lets [`planned_video`] *measure* it |
| 491 | /// instead of promising it. |
| 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 | /// How a front-end names a video seat: which of the two encoders has the file, |
| 523 | /// and which library that is. Not the codec -- a caller shows this beside the |
| 524 | /// format it picked, and `rav1e` names AV1 as `rusty_h264` names H.264. One |
| 525 | /// place, so what a card says before an export and what its progress line says |
| 526 | /// during one cannot drift apart. |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | /// The cheap half of "does this timeline's sound have to be re-encoded": what |
| 537 | /// the *edit* says, with no file opened. Two lanes are a mix and a mix is not a |
| 538 | /// copy; a speeded lane is resampled; an equalizer is sample math. The other |
| 539 | /// half -- whether the sources can be copied out of at all -- costs a file open |
| 540 | /// each and belongs to [`copy_audio`], which may re-encode where this says copy. |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | /// What the sound is written by. Every audio encoder here is software -- there |
| 556 | /// is no hardware AAC, PCM, FLAC or MP3 seat -- so this names *which* one, and |
| 557 | /// whether a container escapes encoding altogether by copying the packets it was |
| 558 | /// given. Both AV1 formats are in it like the mp4: an AV1 export carries the |
| 559 | /// timeline's sound too, so leaving it unnamed would be the old lie. |
| 560 | /// |
| 561 | /// A prediction, and it says so: `copied` is what [`copy_audio`] *did*, which a |
| 562 | /// card asking before the export has no way to know (a source that cannot be |
| 563 | /// copied out of is only found by opening it). `None` predicts from the edit |
| 564 | /// alone. |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | /// What the export *did* to the sound, for the line it publishes while it runs: |
| 601 | /// [`audio_label`]'s words with the one thing no prediction can know filled in |
| 602 | /// -- whether the Opus seat took the track or handed it back |
| 603 | /// ([`encode_opus`]'s gate). |
| 604 | /// |
| 605 | /// `sound` is `Some(copied)` for a track and `None` for a file with no sound. |
| 606 | /// Naming Opus for *every* Matroska encode is what made that fallback |
| 607 | /// invisible: a track the gate refused was written as AAC and the line still |
| 608 | /// said Opus, on the one path where the difference is audible. |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | /// What [`start`] would write this timeline's sound with, before one is |
| 626 | /// started. Pure: no probe and no file opened, so a card may ask it per repaint. |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | /// Why the sound's rate is nothing this timeline can be asked about in this |
| 632 | /// format, or `None` where it is a real choice: there is no sound to write, the |
| 633 | /// format codes the samples themselves, or the packets are the source's own and |
| 634 | /// carry the rate *it* was coded at. Pure, like [`planned_audio`], and a |
| 635 | /// prediction in the same way -- a copy that turns out impossible (a source no |
| 636 | /// mp4 sample table holds) falls through to [`encode_audio`], which codes at |
| 637 | /// [`ExportSettings::audio_kbps`] like every other encode. So the value travels |
| 638 | /// even where this refuses; what it cannot do is silently write a rate nobody |
| 639 | /// picked. |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | /// The tracks an export carries, in the order they were picked, and empty where |
| 658 | /// it carries none: no pick, a pick nothing answers, a track that could not be |
| 659 | /// read, one with no cue left on the exported timeline -- and every format that |
| 660 | /// is the sound alone, which has nowhere to put them. Filtered *per track*, so |
| 661 | /// one unusable pick costs its own row and not the others. |
| 662 | /// |
| 663 | /// Both containers, since the mp4 muxer gained its `tx3g` track: what the two |
| 664 | /// do with the very same [`SubParams`] is theirs to say |
| 665 | /// ([`crate::mux::Mp4Muxer::write_subtitles`], [`MkvMuxer`]), and nothing here |
| 666 | /// asks which one is being written. |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | /// The track's cues where the *exported* timeline puts them, which is the only |
| 702 | /// clock the file has: the export writes timeline frame 0 onwards and nothing |
| 703 | /// else, exactly as the sound is mixed from frame 0 and resized to the |
| 704 | /// timeline's own length ([`encode_audio`]). |
| 705 | /// |
| 706 | /// Which clock the cues arrive in is what the track itself says: |
| 707 | /// |
| 708 | /// * a track out of a *file* (`SubtitleTrack::track`) is timed against that |
| 709 | /// file, so each cue is carried through the spans that play it -- a cue over |
| 710 | /// a stretch that was cut out is gone, one straddling a cut keeps the half |
| 711 | /// that is still there, and one after a rippled delete moves back with the |
| 712 | /// picture it belongs to. The *edges* a cut clips to are frames -- that is |
| 713 | /// what a cut is -- but a cue nothing clipped keeps its own microseconds, so |
| 714 | /// an untouched timeline exports the times the source states. |
| 715 | /// * a *standalone* file (`subs.srt`) is timed against nothing else -- there is |
| 716 | /// no clip to hang it on and no offset in the project to shift it by -- so it |
| 717 | /// is the timeline's own clock, which is where it was drawn while editing |
| 718 | /// (`Player::subtitle_overlay`). Clipped to the exported length and no more. |
| 719 | /// |
| 720 | /// This is also what the *preview* draws: the plate over the picture and the |
| 721 | /// timeline strip both ask it through |
| 722 | /// [`PlaybackSession::timeline_cues`](crate::PlaybackSession::timeline_cues), so |
| 723 | /// what a rippled timeline shows and what its export writes are one answer by |
| 724 | /// construction rather than two maps kept in step by hand. |
| 725 | /// |
| 726 | /// Pure and cheap enough to ask per repaint (a walk of the spans and of the |
| 727 | /// cues, no file opened), which is how a front-end asks it. |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | |
| 742 | |
| 743 | |
| 744 | |
| 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | |
| 751 | |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | /// What [`start`] would do about the subtitles, in the words a card shows: what |
| 793 | /// travels, and the reason beside every pick that does not. Pure, like |
| 794 | /// [`planned_audio`]: no file is opened, so it may be asked per repaint. |
| 795 | /// |
| 796 | /// `picks` is any run of indices into [`Project::subtitles`] -- an |
| 797 | /// [`ExportSettings::subtitles`] list (`picks.iter().copied()`) as much as a |
| 798 | /// single `Some(row)`, which is what a front-end holding one row still hands it. |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | /// What [`start`] would encode the picture with, probed the way the export |
| 856 | /// probes it -- the very encoder is opened and closed again -- so this is a |
| 857 | /// measurement and not a promise. `None` for a format that carries no picture. |
| 858 | /// |
| 859 | /// Costs that open (~100 ms here): ask it off a render thread and keep the |
| 860 | /// answer until the format, the resolution or the bitrate changes. |
| 861 | |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | |
| 868 | /// What [`start`] would open for *this* timeline: the picture's seat -- or the |
| 869 | /// copy that means there is no encoder at all -- and the sound's, asked of the |
| 870 | /// very gates the export asks ([`CopyPlan::of`] and [`copy_audio`]'s) rather |
| 871 | /// than of the format alone. |
| 872 | /// |
| 873 | /// This exists because the card and the running export used to disagree in both |
| 874 | /// directions on the same file: the card named a software HEVC encode for a cut |
| 875 | /// the engine copied, and named an AAC copy for a Matroska source whose sound |
| 876 | /// no sample table holds and which therefore always re-encodes. A prediction |
| 877 | /// that is not the decision is worse than no prediction, because a person plans |
| 878 | /// their evening around it. |
| 879 | /// |
| 880 | /// Costs what [`planned_video`] costs (an encoder opened and closed) plus a |
| 881 | /// header read per source and, once per file, its cluster walk: ask it off a |
| 882 | /// render thread and keep the answer until the timeline or the settings change. |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | |
| 890 | |
| 891 | |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | /// The audio track an export writes, and how it was made -- a copy is the |
| 917 | /// source's own packets, bit for bit, and anything else is this project's |
| 918 | /// encoder over the decoded mix. [`run`] publishes which of the two really |
| 919 | /// happened, so the encoder line a user reads is measured and not promised. |
| 920 | pub |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 | |
| 931 | |
| 932 | /// The timeline's audio track for a file that carries picture: copied packet for |
| 933 | /// packet where a copy says exactly what the timeline says, and decoded, mixed |
| 934 | /// and encoded again ([`encode_audio`]) where it cannot -- a second audio lane, |
| 935 | /// a speeded clip, an equalizer, a source that is not AAC inside an mp4 sample |
| 936 | /// table. Nothing is refused for being uncopyable any more; the only refusals |
| 937 | /// left below the copy are about sound this engine cannot *decode* either, and |
| 938 | /// those come out of the decode path by name. |
| 939 | /// |
| 940 | /// The copy is still the default and still bit-exact: a timeline nobody has |
| 941 | /// touched leaves as the very packets its source holds. |
| 942 | /// |
| 943 | /// corner-cut: this holds the whole exported AAC track in memory (~3 kB per |
| 944 | /// 23 ms packet, so ~500 MB for an hour). Upgrade path is a streaming |
| 945 | /// `copy_segments` that yields packets instead of collecting them. |
| 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 | /// The picture's half of [`copy_audio`]: a Matroska export whose every span is |
| 1039 | /// its source's own coded blocks, written back out without a decoder or an |
| 1040 | /// encoder anywhere in the path. |
| 1041 | /// |
| 1042 | /// **When.** A copy is entered only where it says *exactly* what the timeline |
| 1043 | /// says, which is the audio gate's rule and not a looser one: the file this |
| 1044 | /// export writes is Matroska, the source's codec is the one that file would |
| 1045 | /// carry ([`Format::Hevc`] over HEVC, [`Format::Av1`] over AV1), and nothing on |
| 1046 | /// the way has touched a sample -- no grade, no speed, no rate conversion, no |
| 1047 | /// gap to fill with black, no source of another size to place on the canvas, |
| 1048 | /// no `ContentEncodings` packing to undo. Anything else re-encodes exactly as |
| 1049 | /// it always did; there is no half-copied file. |
| 1050 | /// |
| 1051 | /// **All or nothing, per export.** A copied span and an encoded one cannot |
| 1052 | /// share one track: this project's encoders write 8-bit SDR streams whose |
| 1053 | /// parameter sets are their own, so splicing them into (say) a Main 10 HDR |
| 1054 | /// source would change bit depth and colour mid-track, and a container states |
| 1055 | /// its configuration record once. So the head and tail fragments of a cut that |
| 1056 | /// lands mid-GOP are *not* re-encoded into the copy -- they are what makes the |
| 1057 | /// whole export fall back to the encoder. What a copy needs instead is that |
| 1058 | /// every span begins on a sync point and ends where the next one begins, which |
| 1059 | /// is what a cut placed on a keyframe gives it. |
| 1060 | /// |
| 1061 | /// **What a cut costs.** An open-GOP source (x265's default) writes leading |
| 1062 | /// pictures after a sync point that are shown *before* it and reference the |
| 1063 | /// group before it. At the start of a copied region those references are not in |
| 1064 | /// the file, so they are dropped -- the picture before the cut is held for those |
| 1065 | /// few frames (four at this film's B-depth, a sixth of a second) rather than |
| 1066 | /// being written as pictures that cannot decode. The region still starts at the |
| 1067 | /// timeline frame it owns, so the sound never drifts. |
| 1068 | /// |
| 1069 | /// corner-cut: mp4 is not copied (its `hvc1` sample entry forbids in-band |
| 1070 | /// parameter sets, and the mp4 muxer here writes its sample table from a frame |
| 1071 | /// counter), and neither is H.264, which this project only writes into mp4. The |
| 1072 | /// upgrade path for both is a sample-table writer that takes explicit |
| 1073 | /// timestamps, which is what [`MkvMuxer::write_block`] already is for Matroska. |
| 1074 | |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | /// A run of source blocks copied in one piece: what a cut leaves behind, and |
| 1090 | /// what two spans that continue each other in the same file merge back into. |
| 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 | /// The same lane, *decoded*: what a packet copy cannot carry comes out here as |
| 1267 | /// AAC written by this project's own encoder. |
| 1268 | /// |
| 1269 | /// The samples are the very ones [`run_audio`] would put in a WAV -- the same |
| 1270 | /// opener with the same equalizers, the same rates and the same resize onto the |
| 1271 | /// timeline's own length -- so an mp4 and a WAV of one timeline are one mix, |
| 1272 | /// not two that could disagree. |
| 1273 | /// |
| 1274 | /// AAC-LC's encoder delay is one 1024-frame block, which is exactly the priming |
| 1275 | /// a reader drops when the file carries no edit list (`audio::DEFAULT_PRIMING`, |
| 1276 | /// and [`crate::mux::Mp4Muxer`] writes none): the first packet is that delay, so |
| 1277 | /// the sound starts at timeline frame 0 as a copied track's does. |
| 1278 | /// |
| 1279 | /// corner-cut: the mix sits in memory as f32 before it is encoded (~46 MB a |
| 1280 | /// minute of 48 kHz stereo), for [`run_audio`]'s reason -- `rusty_aac` buffers |
| 1281 | /// the whole stream anyway, since it encodes its frames in parallel. Upgrade |
| 1282 | /// path is a chunked push once that encoder streams. |
| 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 | |
| 1387 | |
| 1388 | |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | |
| 1393 | |
| 1394 | |
| 1395 | |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | /// The one rate Opus codes at. The container may state another one in its |
| 1404 | /// `OpusHead` and every decoder still runs at 48 kHz (RFC 7845 §5.1), so a |
| 1405 | /// timeline at any other rate is not "encoded at its own rate" here -- it is |
| 1406 | /// resampled or it is not Opus, and [`encode_audio`] picks the second. |
| 1407 | pub const OPUS_RATE: u32 = 48_000; |
| 1408 | |
| 1409 | /// 20 ms at [`OPUS_RATE`], the frame every Opus muxer in the wild writes: |
| 1410 | /// long enough that the per-packet overhead is nothing, short enough that a |
| 1411 | /// Matroska block timestamp in whole milliseconds is exact. |
| 1412 | const OPUS_FRAME: usize = 960; |
| 1413 | |
| 1414 | /// The most this project asks of `opus-rs`, in kbps, and why it is a cap rather |
| 1415 | /// than the four rates the Sound row offers: this encoder falls off a cliff at a |
| 1416 | /// rate that depends on the *content*, and above it a conformant decoder gets |
| 1417 | /// noise back. Measured on three one-second spans of a real 5.1 Opus film, |
| 1418 | /// encoded here and decoded with `ruopus` -- which is not the suspect, since it |
| 1419 | /// decodes ffmpeg's own libopus at 256 kbps to correlation 1.00000 on the same |
| 1420 | /// material: |
| 1421 | /// |
| 1422 | /// ```text |
| 1423 | /// kbps 120 128 136 144 152 160 |
| 1424 | /// span A 0.945 0.937 0.452 0.206 0.223 0.163 |
| 1425 | /// span B 0.986 0.989 0.697 0.153 0.114 0.149 |
| 1426 | /// span C 0.999 0.994 0.951 0.335 0.266 0.326 |
| 1427 | /// libopus 0.997 0.998 -- -- -- 0.996 (same spans, control) |
| 1428 | /// ``` |
| 1429 | /// |
| 1430 | /// So: usable to 128, ruined by 136 on real film sound, and the pure-tone |
| 1431 | /// fixtures that first suggested a 165 kbps ceiling were simply easy material. |
| 1432 | /// 128 kbps stereo Opus is around transparency anyway (libopus scores 0.998 |
| 1433 | /// there on the worst of those spans), so the cap costs nothing a listener has. |
| 1434 | /// It is still not *trusted*: every track is decoded again and measured before |
| 1435 | /// it is written ([`opus_fidelity`]), because a cliff whose edge moves with the |
| 1436 | /// material is not something a constant can be safe against on its own. |
| 1437 | /// |
| 1438 | /// corner-cut: the ceiling is this encoder's, not the format's. Upgrade path is a |
| 1439 | /// released `opus-rs` that survives its own high rates -- the unit test pins the |
| 1440 | /// failure, so it fails the day the bug is fixed and this can be raised. |
| 1441 | pub const OPUS_MAX_KBPS: u32 = 128; |
| 1442 | |
| 1443 | /// How well a track has to survive its own round trip to be written as Opus: |
| 1444 | /// the correlation between the mix and the decode of what was encoded from it. |
| 1445 | /// A good encoder scores 0.98-0.999 on this material (libopus, measured above); |
| 1446 | /// the failure mode is not subtle at all, scoring 0.1-0.7. 0.95 sits in the gap |
| 1447 | /// with room on both sides, and what fails it is written as AAC -- the export's |
| 1448 | /// own encoder line then says AAC, so the fallback is visible rather than |
| 1449 | /// silent. |
| 1450 | const OPUS_MIN_FIDELITY: f64 = 0.95; |
| 1451 | |
| 1452 | /// The encoder's lookahead at [`OPUS_RATE`] in the mode this envelope always |
| 1453 | /// selects (CELT-only: 2.5 ms). The pre-skip a file states is this *plus* the |
| 1454 | /// warm-up frame [`encode_opus`] throws away. Measured by |
| 1455 | /// cross-correlating the decode against the source, not taken from the crate -- |
| 1456 | /// it exposes no lookahead getter -- and asserted at both ends of the rate band |
| 1457 | /// in `tests/opus_export.rs`, which is what catches a version that changes it. |
| 1458 | const OPUS_PRE_SKIP: u16 = 120; |
| 1459 | |
| 1460 | /// The mix as Opus packets, one per [`OPUS_FRAME`], plus the pre-skip that has |
| 1461 | /// to be declared in front of them. Stereo and [`OPUS_RATE`] only -- the caller |
| 1462 | /// checks both, because outside that pair this encoder is not one this project |
| 1463 | /// is willing to write files with ([`OPUS_MAX_KBPS`]). |
| 1464 | /// |
| 1465 | /// The tail frame is padded with silence rather than dropped: Opus codes whole |
| 1466 | /// frames and a track a few milliseconds short under a picture that is not is |
| 1467 | /// the drift every other path here is written to avoid. The pre-skip trims the |
| 1468 | /// front; the container's duration trims the back. |
| 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 | |
| 1494 | |
| 1495 | |
| 1496 | |
| 1497 | |
| 1498 | |
| 1499 | |
| 1500 | |
| 1501 | |
| 1502 | |
| 1503 | |
| 1504 | |
| 1505 | |
| 1506 | |
| 1507 | |
| 1508 | |
| 1509 | |
| 1510 | |
| 1511 | |
| 1512 | |
| 1513 | |
| 1514 | |
| 1515 | |
| 1516 | |
| 1517 | |
| 1518 | |
| 1519 | |
| 1520 | |
| 1521 | |
| 1522 | |
| 1523 | |
| 1524 | |
| 1525 | |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | /// Packets one sampled window listens to: 5 s at [`OPUS_FRAME`]. |
| 1530 | const FIDELITY_WINDOW: usize = 250; |
| 1531 | |
| 1532 | /// How many of them a long track is judged on -- a minute of sound, wherever |
| 1533 | /// the track's length puts them, and a constant cost rather than one that grows |
| 1534 | /// with the film ([`opus_fidelity`]). |
| 1535 | const FIDELITY_WINDOWS: usize = 12; |
| 1536 | |
| 1537 | /// Packets decoded into a window and thrown away before it is measured. CELT |
| 1538 | /// predicts across frames, so a decoder started cold mid-stream is behind its |
| 1539 | /// own history for a few frames; 100 ms is far more than it needs and is not |
| 1540 | /// worth counting. |
| 1541 | const FIDELITY_WARMUP: usize = 5; |
| 1542 | |
| 1543 | /// How much sound a window must carry before its correlation means anything: |
| 1544 | /// mean square per sample. A window of digital silence -- the head of a film, |
| 1545 | /// the gap between a feature and its credits -- correlates with nothing, and |
| 1546 | /// failing a track for it would send perfectly good sound to AAC. |
| 1547 | const FIDELITY_FLOOR: f64 = 1e-9; |
| 1548 | |
| 1549 | /// The correlation between `samples` and the decode of `packets` with the first |
| 1550 | /// `pre_skip` frames dropped: 1.0 is the same waveform, and this codec's failure |
| 1551 | /// mode lands near 0.1. Streamed packet by packet -- the decode is never held, |
| 1552 | /// only three running sums -- because the mix behind it is already the biggest |
| 1553 | /// thing in an export ([`encode_audio`]'s corner-cut). |
| 1554 | /// |
| 1555 | /// A packet the decoder refuses is 0.0 and no argument: a track this project |
| 1556 | /// cannot read is exactly what this is here to catch. |
| 1557 | /// |
| 1558 | /// **Sampled above a minute of sound, and the median window is the answer.** |
| 1559 | /// This decode is the whole cost of exporting a feature film: `ruopus` runs its |
| 1560 | /// inverse MDCT at 0.2x real time here (measured, 24.2 s for 121.5 s of stereo), |
| 1561 | /// so judging every packet of a two-and-a-half-hour film costs half an hour |
| 1562 | /// before a byte of picture is written -- which is what it did, and what made a |
| 1563 | /// copy export that has no encoding to do at all sit at zero for twenty minutes. |
| 1564 | /// [`FIDELITY_WINDOWS`] windows spread evenly across the track cost the same |
| 1565 | /// minute of decode whatever the film's length, and what they are looking for |
| 1566 | /// survives sampling: [`OPUS_MAX_KBPS`]'s cliff is a *rate* the encoder falls |
| 1567 | /// off everywhere that rate is used, not a defect of one bar of music. |
| 1568 | /// |
| 1569 | /// The **median** and not the worst, and that is measured rather than cautious. |
| 1570 | /// Forty five-second windows of a real 5.1 film's mix, encoded here at 128 kbps |
| 1571 | /// and decoded back, in order: |
| 1572 | /// |
| 1573 | /// ```text |
| 1574 | /// 0.803 0.835 0.938 0.940 0.960 0.987 0.994 ... median 0.998 ... 0.999 |
| 1575 | /// ``` |
| 1576 | /// |
| 1577 | /// Five of the thirty-nine that carried sound sit under [`OPUS_MIN_FIDELITY`] on |
| 1578 | /// a track that is *good* -- which is the same thing the table in |
| 1579 | /// [`OPUS_MAX_KBPS`] shows, where a span scoring 0.937 at 128 kbps is inside the |
| 1580 | /// usable band. A worst-window rule at 0.95 therefore refuses films this encoder |
| 1581 | /// handles perfectly well, while the failure it exists for is the opposite |
| 1582 | /// shape: at 136 kbps the same three measured spans read 0.452, 0.697, 0.951, |
| 1583 | /// and at 256 kbps the whole track correlates 0.06. Half a track cannot be |
| 1584 | /// ruined without the middle of the list moving, so the median separates the two |
| 1585 | /// by a margin no single window can (0.998 against under 0.7) -- and a track |
| 1586 | /// under a minute is one window, where median and whole-track correlation are |
| 1587 | /// the same number the gate always used. |
| 1588 | |
| 1589 | |
| 1590 | |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | |
| 1597 | |
| 1598 | |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | |
| 1603 | |
| 1604 | |
| 1605 | |
| 1606 | |
| 1607 | |
| 1608 | |
| 1609 | |
| 1610 | |
| 1611 | |
| 1612 | |
| 1613 | |
| 1614 | |
| 1615 | |
| 1616 | |
| 1617 | |
| 1618 | /// [`opus_fidelity`] over `packets[measure..to]`, with `packets[from..measure]` |
| 1619 | /// -- the warm-up -- decoded for its state and thrown away. `None` where the |
| 1620 | /// source window carries no sound worth correlating ([`FIDELITY_FLOOR`]). |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | |
| 1626 | |
| 1627 | |
| 1628 | |
| 1629 | |
| 1630 | |
| 1631 | |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | |
| 1637 | |
| 1638 | |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | |
| 1643 | |
| 1644 | |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | |
| 1650 | |
| 1651 | |
| 1652 | |
| 1653 | |
| 1654 | |
| 1655 | |
| 1656 | |
| 1657 | |
| 1658 | |
| 1659 | |
| 1660 | |
| 1661 | |
| 1662 | |
| 1663 | |
| 1664 | |
| 1665 | |
| 1666 | |
| 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 | |
| 1697 | |
| 1698 | |
| 1699 | |
| 1700 | |
| 1701 | |
| 1702 | |
| 1703 | |
| 1704 | |
| 1705 | |
| 1706 | |
| 1707 | |
| 1708 | |
| 1709 | |
| 1710 | |
| 1711 | |
| 1712 | |
| 1713 | |
| 1714 | |
| 1715 | |
| 1716 | |
| 1717 | |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | |
| 1723 | |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | |
| 1728 | |
| 1729 | |
| 1730 | |
| 1731 | |
| 1732 | |
| 1733 | |
| 1734 | |
| 1735 | |
| 1736 | |
| 1737 | |
| 1738 | |
| 1739 | |
| 1740 | |
| 1741 | |
| 1742 | |
| 1743 | |
| 1744 | |
| 1745 | |
| 1746 | |
| 1747 | |
| 1748 | |
| 1749 | |
| 1750 | |
| 1751 | |
| 1752 | |
| 1753 | |
| 1754 | |
| 1755 | |
| 1756 | |
| 1757 | |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | |
| 1762 | |
| 1763 | |
| 1764 | |
| 1765 | |
| 1766 | |
| 1767 | |
| 1768 | |
| 1769 | |
| 1770 | |
| 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 | /// Which matrix pair a span's samples are rewritten by on the way into a file |
| 2003 | /// whose own matrix is `out` -- `None` when they are already coded against it, |
| 2004 | /// and for a gap, whose 16/128/128 black is black in every matrix here. |
| 2005 | /// |
| 2006 | /// `toned` says the tone map ran on this span: it hands back BT.709 SDR whatever |
| 2007 | /// the source was coded as, so an HDR clip is never *also* given the matrix |
| 2008 | /// treatment its BT.2020 tag would ask for -- one conversion or the other, never |
| 2009 | /// both on one frame -- while a tone-mapped clip on a canvas below 720 lines |
| 2010 | /// still takes its 709 -> 601 step. |
| 2011 | |
| 2012 | |
| 2013 | |
| 2014 | |
| 2015 | |
| 2016 | |
| 2017 | |
| 2018 | |
| 2019 | |
| 2020 | |
| 2021 | |
| 2022 | |
| 2023 | /// What rate `path` was shot at against a timeline at `timeline_fps` |
| 2024 | /// ([`Rate`]). [`Rate::REAL_TIME`] for the files that have no rate of their own |
| 2025 | /// -- a still, a song -- and for one that will not open here: the decoder is |
| 2026 | /// opened a few lines later and fails the export by name, which is a better |
| 2027 | /// error than this one could raise. |
| 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 | /// The audio lanes alone, summed, as a WAV or a FLAC. |
| 2055 | /// |
| 2056 | /// Nothing here re-derives the edit: the play lists are |
| 2057 | /// [`Project::audio_segments_from`] and they are handed to the very |
| 2058 | /// [`AudioSession::open_mixed_streams`] playback feeds from, so what is written |
| 2059 | /// is what was heard -- every lane, mixed the same way, gaps included, which |
| 2060 | /// arrive as real silence from that choke point rather than as a hole this would |
| 2061 | /// have to invent. |
| 2062 | /// |
| 2063 | /// The length is the *timeline's*: each segment resolves its window to whole |
| 2064 | /// samples on its own, so the sum can miss the timeline by a sample or two, and |
| 2065 | /// a source that runs out early would leave the file short. Both are settled by |
| 2066 | /// one `resize` at the end -- padding with silence, trimming what overshot -- |
| 2067 | /// so an exported file is exactly as long as what was edited. |
| 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 | /// 16-bit PCM at the timeline's own rate and layout: no resampling anywhere in |
| 2147 | /// this engine, so what the decoder handed over is what the header says. |
| 2148 | |
| 2149 | |
| 2150 | |
| 2151 | |
| 2152 | |
| 2153 | |
| 2154 | |
| 2155 | |
| 2156 | |
| 2157 | |
| 2158 | |
| 2159 | |
| 2160 | |
| 2161 | |
| 2162 | |
| 2163 | |
| 2164 | |
| 2165 | |
| 2166 | |
| 2167 | /// The same samples as MPEG-1 Layer III, `rusty_mp3` doing the encoding -- pure |
| 2168 | /// Rust like every other encoder here, and the reason this format is a row at |
| 2169 | /// all: the LGPL `shine-rs` was the only one when it was not. |
| 2170 | /// |
| 2171 | /// CBR at the caller's rate, [`DEFAULT_AUDIO_KBPS`] where there was none. Every |
| 2172 | /// offered rate is already a legal Layer III value, so the encoder's snap is a |
| 2173 | /// backstop and not a silent substitution; a sample rate MPEG has no frame for |
| 2174 | /// (anything but 8-48 kHz) is refused there by name rather than written as |
| 2175 | /// something else. |
| 2176 | /// |
| 2177 | /// corner-cut: CBR only -- the card offers rates and not a quality index. Upgrade |
| 2178 | /// path is `Mp3EncoderConfig::vbr_quality` behind a setting of its own. |
| 2179 | |
| 2180 | |
| 2181 | |
| 2182 | |
| 2183 | |
| 2184 | |
| 2185 | |
| 2186 | |
| 2187 | |
| 2188 | |
| 2189 | |
| 2190 | |
| 2191 | |
| 2192 | |
| 2193 | |
| 2194 | |
| 2195 | |
| 2196 | |
| 2197 | |
| 2198 | |
| 2199 | |
| 2200 | |
| 2201 | |
| 2202 | /// The Vorbis quality every `.ogg` this program writes is coded at, on |
| 2203 | /// `rusty_vorbis`'s normalised `[0, 1]` scale -- about `-q 8.35` on the scale |
| 2204 | /// Vorbis itself is spoken in (`quality01_from_vorbis_q`). |
| 2205 | /// |
| 2206 | /// A measured number, not a taste. The 2026-08-11 bench encoded three of this |
| 2207 | /// suite's fixtures (`test_tone_48k.wav`, `test_av.mp4`, `test_tone.mp3`) at |
| 2208 | /// every quality from 0.40 to 0.95 and decoded each back with **symphonia** -- |
| 2209 | /// an independent decoder, and the very one [`crate::audio`] reopens an export |
| 2210 | /// with. Two things came out of it: |
| 2211 | /// |
| 2212 | /// * **Below 0.50 the encoder is quiet, not just coarse.** The decoded RMS |
| 2213 | /// against the source's runs 0.83-0.94 at quality 0.40 (a 1 to 1.6 dB level |
| 2214 | /// error), and at 0.10 and below the file decodes to near-silence -- the same |
| 2215 | /// class of failure the AC-3 mono downmix has in `crate::audio`. From 0.55 up |
| 2216 | /// the level sits at 1.000-1.009, which is what a lossy codec should do. |
| 2217 | /// * **The band tops out well under the rates the Sound row offers.** Quality |
| 2218 | /// 0.85 measured 176, 144 and 148 kbps on the three fixtures; 0.95 only |
| 2219 | /// reaches ~200. That is why [`audio_rate_refusal`] takes the row away rather |
| 2220 | /// than mapping 128/192/256/320 onto quality steps: the top two are numbers |
| 2221 | /// this encoder cannot produce, and a card that printed them would be lying. |
| 2222 | /// |
| 2223 | /// 0.85 is the top of the band where every fixture still decoded to *exactly* |
| 2224 | /// its own length (0.95 overshot one by 820 samples), which is the property |
| 2225 | /// [`write_ogg`] is built around. |
| 2226 | const VORBIS_QUALITY: f32 = 0.85; |
| 2227 | |
| 2228 | /// The Vorbis block hop, and the size of the pre-roll [`write_ogg`] feeds the |
| 2229 | /// encoder. `rusty_vorbis` emits long blocks only (`N = 2048`, hop `N/2`). |
| 2230 | const VORBIS_HOP: usize = 1024; |
| 2231 | |
| 2232 | /// The same samples as Vorbis I in an Ogg container: `rusty_vorbis` encodes, |
| 2233 | /// `oxideav-ogg` pages. Pure Rust on both halves, like every other encoder here. |
| 2234 | /// |
| 2235 | /// Two corrections stand between that library pair and a file this project would |
| 2236 | /// ship, and both are measured rather than guessed (2026-08-11, decoded back |
| 2237 | /// with symphonia every time): |
| 2238 | /// |
| 2239 | /// 1. **One hop of pre-roll.** `rusty_vorbis` advances the granule by a full hop |
| 2240 | /// on its *first* audio packet, which its own doc comment says decodes to |
| 2241 | /// zero samples. Written straight through, every sample lands ~1024 early: |
| 2242 | /// a marker signal whose only energy was its first and last 1024 samples came |
| 2243 | /// back with the head at 36% of its amplitude and a full-scale burst 1500 |
| 2244 | /// samples *before* the real one, in what should have been silence. Feeding |
| 2245 | /// [`VORBIS_HOP`] samples of silence ahead of the mix and subtracting the same |
| 2246 | /// from every granule puts it back: head 0.86 against an input peak of 0.80, |
| 2247 | /// the phantom burst down to 0.04, the real burst at its own place. The |
| 2248 | /// decoder drops the pre-roll itself -- a first page whose granule is under |
| 2249 | /// what its packets decode to is exactly how Ogg says "skip this much". |
| 2250 | /// 2. **The tail is declared, not encoded.** The block grid overshoots the last |
| 2251 | /// sample, so the stream is padded out and the *last* page's granule is set |
| 2252 | /// to the timeline's own frame count. A decoder trims to it, which is what |
| 2253 | /// makes an `.ogg` here exactly as long as the WAV of the same timeline -- |
| 2254 | /// the promise [`run_audio`] makes for every other audio format. |
| 2255 | /// |
| 2256 | /// **Stereo, always.** The embedded setup header `rusty_vorbis` ships is a |
| 2257 | /// stereo profile: a mono push is refused outright ("bad coupling channels"), |
| 2258 | /// and so is anything wider. A mono mix is therefore written as dual mono, both |
| 2259 | /// channels bit-identical (measured: `max|L-R|` is exactly 0, and Vorbis's own |
| 2260 | /// channel coupling codes the empty side channel for almost nothing). Wider than |
| 2261 | /// stereo cannot reach here -- [`crate::audio`] folds 5.1 to stereo when the |
| 2262 | /// source is opened -- but it is refused by name rather than left to the |
| 2263 | /// library's own message. |
| 2264 | /// |
| 2265 | /// corner-cut: one quality, [`VORBIS_QUALITY`], with no user control -- the Sound |
| 2266 | /// row is refused for this format because the rates it offers are not rates |
| 2267 | /// Vorbis reaches. Upgrade path is a quality picker of its own, worth building |
| 2268 | /// the day the card has a control that speaks in quality rather than kbps. |
| 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 | /// The page size [`write_ogg`] asks the Ogg muxer to aim at, in bytes. RFC 3533 |
| 2363 | /// describes pages as "usually 4-8 kB", which is also the muxer's own suggested |
| 2364 | /// general-purpose value. |
| 2365 | const OGG_PAGE_BYTES: usize = 4096; |
| 2366 | |
| 2367 | /// The same samples, losslessly compressed. `flacenc`'s errors are flattened to |
| 2368 | /// text: they are not `Send + Sync`, and every one of them fails the export the |
| 2369 | /// same way. |
| 2370 | |
| 2371 | |
| 2372 | |
| 2373 | |
| 2374 | |
| 2375 | |
| 2376 | |
| 2377 | |
| 2378 | |
| 2379 | |
| 2380 | |
| 2381 | |
| 2382 | |
| 2383 | |
| 2384 | |
| 2385 | |
| 2386 | |
| 2387 | |
| 2388 | |
| 2389 | |
| 2390 | |
| 2391 | |
| 2392 | |
| 2393 | |
| 2394 | |
| 2395 | |
| 2396 | |
| 2397 | |
| 2398 | |
| 2399 | |
| 2400 | |
| 2401 | |
| 2402 | |
| 2403 | /// The I420 planes of one black picture, allocated once for a whole export: a |
| 2404 | /// gap in the video lane is encoded, not skipped, or every frame after it would |
| 2405 | /// arrive early. Limited-range black is `Y=16, U=V=128`, the same convention |
| 2406 | /// [`crate::convert`] decodes with. |
| 2407 | |
| 2408 | |
| 2409 | |
| 2410 | |
| 2411 | |
| 2412 | |
| 2413 | |
| 2414 | |
| 2415 | |
| 2416 | |
| 2417 | |
| 2418 | |
| 2419 | |
| 2420 | |
| 2421 | |
| 2422 | |
| 2423 | |
| 2424 | |
| 2425 | |
| 2426 | |
| 2427 | |
| 2428 | |
| 2429 | |
| 2430 | /// `Err` once a cancel has been asked for. Called at every point where the work |
| 2431 | /// left is more than an instant, so an `esc` at 99.9% still stops the export |
| 2432 | /// instead of quietly completing it. |
| 2433 | |
| 2434 | |
| 2435 | |
| 2436 | |
| 2437 | |
| 2438 | |
| 2439 | |
| 2440 | /// The two containers an export writes, so the picture loop above is one loop: |
| 2441 | /// H.264 goes into mp4, AV1 into Matroska, and nothing else is offered. |
| 2442 | |
| 2443 | |
| 2444 | |
| 2445 | |
| 2446 | |
| 2447 | |
| 2448 | |
| 2449 | |
| 2450 | |
| 2451 | |
| 2452 | |
| 2453 | |
| 2454 | |
| 2455 | |
| 2456 | /// Writes one access unit, creating the file on the first one -- the parameter |
| 2457 | /// sets for `avcC` (and the sequence header for `CodecPrivate`) only exist once |
| 2458 | /// the encoder has coded something. Units with no coded slice are skipped: a |
| 2459 | /// software encoder may hand back an empty buffer while it buffers, and the |
| 2460 | /// muxer rejects a sample that would carry no picture. |
| 2461 | |
| 2462 | |
| 2463 | |
| 2464 | |
| 2465 | |
| 2466 | |
| 2467 | |
| 2468 | |
| 2469 | |
| 2470 | |
| 2471 | |
| 2472 | |
| 2473 | |
| 2474 | |
| 2475 | |
| 2476 | |
| 2477 | |
| 2478 | |
| 2479 | |
| 2480 | |
| 2481 | |
| 2482 | |
| 2483 | |
| 2484 | |
| 2485 | |
| 2486 | |
| 2487 | |
| 2488 | |
| 2489 | |
| 2490 | |
| 2491 | |
| 2492 | |
| 2493 | |
| 2494 | |
| 2495 | |
| 2496 | |
| 2497 | |
| 2498 | |
| 2499 | |
| 2500 | |
| 2501 | |
| 2502 | |
| 2503 | |
| 2504 | |
| 2505 | |
| 2506 | |
| 2507 | |
| 2508 | |
| 2509 | |
| 2510 | |
| 2511 | |
| 2512 | |
| 2513 | |
| 2514 | |
| 2515 | |
| 2516 | |
| 2517 | |
| 2518 | |
| 2519 | |
| 2520 | |
| 2521 | |
| 2522 | |
| 2523 | |
| 2524 | |
| 2525 | |
| 2526 | |
| 2527 | |
| 2528 | |
| 2529 | |
| 2530 | |
| 2531 | |
| 2532 | |
| 2533 | |
| 2534 | |
| 2535 | |
| 2536 | |
| 2537 | |
| 2538 | |
| 2539 | |
| 2540 | |
| 2541 | |
| 2542 | |
| 2543 | |
| 2544 | |
| 2545 | |
| 2546 | |
| 2547 | |
| 2548 | |
| 2549 | |
| 2550 | |
| 2551 | |
| 2552 | |
| 2553 | |
| 2554 | |
| 2555 | |
| 2556 | |
| 2557 | |
| 2558 | |
| 2559 | |
| 2560 | |
| 2561 | |
| 2562 | |
| 2563 | |
| 2564 | |
| 2565 | |
| 2566 | |
| 2567 | |
| 2568 | |
| 2569 | |
| 2570 | |
| 2571 | |
| 2572 | |
| 2573 | |
| 2574 | |
| 2575 | |
| 2576 | |
| 2577 | |
| 2578 | |
| 2579 | |
| 2580 | |
| 2581 | |
| 2582 | |
| 2583 | |
| 2584 | |
| 2585 | |
| 2586 | |
| 2587 | |
| 2588 | |
| 2589 | |
| 2590 | |
| 2591 | |
| 2592 | |
| 2593 | |
| 2594 | |
| 2595 | |
| 2596 | |
| 2597 | |
| 2598 | |
| 2599 | |
| 2600 | |
| 2601 | |
| 2602 | |
| 2603 | |
| 2604 | |
| 2605 | |
| 2606 | /// The `hvcC` record of the first coded unit, or the refusal by name. Split out |
| 2607 | /// because both HEVC containers ask it in the same words. |
| 2608 | |
| 2609 | |
| 2610 | |
| 2611 | |
| 2612 | |
| 2613 | |
| 2614 | |
| 2615 | |
| 2616 | |
| 2617 | |
| 2618 | |
| 2619 | |
| 2620 | |
| 2621 | |
| 2622 | /// Hardware where it is available, software everywhere else -- chosen once for |
| 2623 | /// the whole export, so the stream never changes encoder mid-file. Both codecs |
| 2624 | /// have both seats: an AV1 export runs on the plugin's VA-API encoder where the |
| 2625 | /// GPU has one and on `rav1e` where it has not, which is the same pair H.264 has |
| 2626 | /// had and the same silent fallback. |
| 2627 | |
| 2628 | |
| 2629 | |
| 2630 | |
| 2631 | |
| 2632 | |
| 2633 | |
| 2634 | |
| 2635 | |
| 2636 | |
| 2637 | |
| 2638 | |
| 2639 | |
| 2640 | |
| 2641 | |
| 2642 | |
| 2643 | |
| 2644 | |
| 2645 | |
| 2646 | |
| 2647 | |
| 2648 | |
| 2649 | |
| 2650 | |
| 2651 | |
| 2652 | |
| 2653 | |
| 2654 | |
| 2655 | |
| 2656 | |
| 2657 | |
| 2658 | /// The intra HEVC seat. Frames arrive one at a time (the export walk is one |
| 2659 | /// picture per timeline frame) and are held until there are [`lanes`] of them, |
| 2660 | /// then coded in parallel and queued in **display order** -- fanning out is the |
| 2661 | /// only thing that makes a pure-Rust HEVC export bearable (4.30 fps at 1080p on |
| 2662 | /// 12 lanes against 0.55 fps on one, measured 2026-08-11), and an export whose |
| 2663 | /// frames came back shuffled would be no export at all. |
| 2664 | /// |
| 2665 | /// corner-cut: a batch of padded planes sits in memory (~3 MB a frame at 1080p, |
| 2666 | /// so ~37 MB at 12 lanes) and the tail of a timeline is coded on fewer lanes |
| 2667 | /// than the middle. Upgrade path is a pipeline that keeps every lane fed from a |
| 2668 | /// decoder running ahead of the encoder rather than a batch barrier. |
| 2669 | |
| 2670 | |
| 2671 | |
| 2672 | |
| 2673 | |
| 2674 | |
| 2675 | |
| 2676 | |
| 2677 | |
| 2678 | |
| 2679 | |
| 2680 | |
| 2681 | |
| 2682 | |
| 2683 | |
| 2684 | |
| 2685 | |
| 2686 | |
| 2687 | |
| 2688 | |
| 2689 | |
| 2690 | |
| 2691 | |
| 2692 | |
| 2693 | |
| 2694 | |
| 2695 | |
| 2696 | |
| 2697 | |
| 2698 | |
| 2699 | |
| 2700 | |
| 2701 | |
| 2702 | |
| 2703 | |
| 2704 | |
| 2705 | |
| 2706 | |
| 2707 | |
| 2708 | |
| 2709 | |
| 2710 | |
| 2711 | |
| 2712 | |
| 2713 | |
| 2714 | |
| 2715 | |
| 2716 | |
| 2717 | |
| 2718 | |
| 2719 | |
| 2720 | |
| 2721 | |
| 2722 | |
| 2723 | |
| 2724 | |
| 2725 | |
| 2726 | |
| 2727 | |
| 2728 | |
| 2729 | |
| 2730 | |
| 2731 | |
| 2732 | |
| 2733 | |
| 2734 | |
| 2735 | |
| 2736 | |
| 2737 | |
| 2738 | |
| 2739 | |
| 2740 | |
| 2741 | |
| 2742 | |
| 2743 | |
| 2744 | |
| 2745 | |
| 2746 | |
| 2747 | |
| 2748 | |
| 2749 | |
| 2750 | |
| 2751 | |
| 2752 | |
| 2753 | |
| 2754 | |
| 2755 | |
| 2756 | |
| 2757 | |
| 2758 | |
| 2759 | |
| 2760 | |
| 2761 | |
| 2762 | |
| 2763 | |
| 2764 | |
| 2765 | |
| 2766 | |
| 2767 | |
| 2768 | |
| 2769 | |
| 2770 | |
| 2771 | |
| 2772 | |
| 2773 | |
| 2774 | |
| 2775 | |
| 2776 | |
| 2777 | |
| 2778 | |
| 2779 | |
| 2780 | |
| 2781 | |
| 2782 | |
| 2783 | |
| 2784 | |
| 2785 | |
| 2786 | |
| 2787 | |
| 2788 | |
| 2789 | |
| 2790 | |
| 2791 | |
| 2792 | |
| 2793 | |
| 2794 | |
| 2795 | |
| 2796 | |
| 2797 | |
| 2798 | |
| 2799 | |
| 2800 | |
| 2801 | |
| 2802 | |
| 2803 | |
| 2804 | |
| 2805 | |
| 2806 | |
| 2807 | |
| 2808 | |
| 2809 | |
| 2810 | |
| 2811 | |
| 2812 | |
| 2813 | |
| 2814 | |
| 2815 | |
| 2816 | |
| 2817 | |
| 2818 | |
| 2819 | |
| 2820 | |
| 2821 | |
| 2822 | |
| 2823 | |
| 2824 | |
| 2825 | |
| 2826 | |
| 2827 | |
| 2828 | |
| 2829 | |
| 2830 | |
| 2831 | |
| 2832 | |
| 2833 | |
| 2834 | |
| 2835 | |
| 2836 | |
| 2837 | |
| 2838 | |
| 2839 | |
| 2840 | |
| 2841 | |
| 2842 | |
| 2843 | |
| 2844 | |
| 2845 | |
| 2846 | |
| 2847 | |
| 2848 | |
| 2849 | |
| 2850 | |
| 2851 | |
| 2852 | |
| 2853 | |
| 2854 | |
| 2855 | |
| 2856 | |
| 2857 | |
| 2858 | |
| 2859 | |
| 2860 | |
| 2861 | |
| 2862 | |
| 2863 | |
| 2864 | |
| 2865 | |
| 2866 | |
| 2867 | |
| 2868 | |
| 2869 | |
| 2870 | |
| 2871 | |
| 2872 | |
| 2873 | |
| 2874 | |
| 2875 | |
| 2876 | |
| 2877 | |
| 2878 | |
| 2879 | |
| 2880 | |
| 2881 | |
| 2882 | |
| 2883 | |
| 2884 | |
| 2885 | |
| 2886 | |
| 2887 | |
| 2888 | |
| 2889 | |
| 2890 | |
| 2891 | |
| 2892 | |
| 2893 | |
| 2894 | |
| 2895 | |
| 2896 | |
| 2897 | |
| 2898 | |
| 2899 | |
| 2900 | |
| 2901 | |
| 2902 | |
| 2903 | |
| 2904 | |
| 2905 | |
| 2906 | |
| 2907 | |
| 2908 | |
| 2909 | |
| 2910 | |
| 2911 | |
| 2912 | |
| 2913 | |
| 2914 | |
| 2915 | |
| 2916 | |
| 2917 | |
| 2918 | |
| 2919 | |
| 2920 | |
| 2921 | |
| 2922 | |
| 2923 | |
| 2924 | |
| 2925 | |
| 2926 | |
| 2927 | |
| 2928 | |
| 2929 | |
| 2930 | |
| 2931 | |
| 2932 | |
| 2933 | |
| 2934 | |
| 2935 | |
| 2936 | |
| 2937 | |
| 2938 | |
| 2939 | |
| 2940 | |
| 2941 | |
| 2942 | |
| 2943 | |
| 2944 | |
| 2945 | |
| 2946 | |
| 2947 | |
| 2948 | |
| 2949 | |
| 2950 | |
| 2951 | |
| 2952 | |
| 2953 | |
| 2954 | |
| 2955 | |
| 2956 | |
| 2957 | |
| 2958 | |
| 2959 | |
| 2960 | |
| 2961 | |
| 2962 | |
| 2963 | |
| 2964 | |
| 2965 | |
| 2966 | |
| 2967 | |
| 2968 | |
| 2969 | |
| 2970 | |
| 2971 | |
| 2972 | |
| 2973 | |
| 2974 | |
| 2975 | |
| 2976 | |
| 2977 | |
| 2978 | |
| 2979 | |
| 2980 | |
| 2981 | |
| 2982 | |
| 2983 | |
| 2984 | |
| 2985 | |
| 2986 | |
| 2987 | |
| 2988 | |
| 2989 | |
| 2990 | |
| 2991 | |
| 2992 | |
| 2993 | |
| 2994 | |
| 2995 | |
| 2996 | |
| 2997 | |
| 2998 | |
| 2999 | |
| 3000 | |
| 3001 | |
| 3002 | |
| 3003 | |
| 3004 | |
| 3005 | |
| 3006 | |
| 3007 | |
| 3008 | |
| 3009 | |
| 3010 | |
| 3011 | |
| 3012 | |
| 3013 | |
| 3014 | |
| 3015 | |
| 3016 | |
| 3017 | |
| 3018 | |
| 3019 | |
| 3020 | |
| 3021 | |
| 3022 | |
| 3023 | |
| 3024 | |
| 3025 | |
| 3026 | |
| 3027 | |
| 3028 | |
| 3029 | |
| 3030 | |
| 3031 | |
| 3032 | |
| 3033 | |
| 3034 | |
| 3035 | |
| 3036 | |
| 3037 | |
| 3038 | |
| 3039 | |
| 3040 | |
| 3041 | |
| 3042 | |
| 3043 | |
| 3044 | |
| 3045 | |
| 3046 | |
| 3047 | |
| 3048 | |
| 3049 | |
| 3050 | |
| 3051 | |
| 3052 | |
| 3053 | |
| 3054 | |
| 3055 | |
| 3056 | |
| 3057 | |
| 3058 | /// The oldest coded intra AU, lent out under the same "valid until the next |
| 3059 | /// call" contract [`pop_av1`] has. Every one of them is an IDR, so the key flag |
| 3060 | /// is not a guess. |
| 3061 | |
| 3062 | |
| 3063 | |
| 3064 | |
| 3065 | |
| 3066 | /// One I420 picture copied onto the padded plane sizes the CTB grid needs, the |
| 3067 | /// added rows and columns filled by **replicating the edge** rather than with |
| 3068 | /// black: the padding is coded and then cropped away, and a black border would |
| 3069 | /// bleed into the last real column through the intra prediction and the |
| 3070 | /// transform that straddles it. |
| 3071 | |
| 3072 | |
| 3073 | |
| 3074 | |
| 3075 | |
| 3076 | |
| 3077 | |
| 3078 | |
| 3079 | |
| 3080 | |
| 3081 | |
| 3082 | |
| 3083 | |
| 3084 | |
| 3085 | |
| 3086 | |
| 3087 | |
| 3088 | |
| 3089 | |
| 3090 | |
| 3091 | |
| 3092 | |
| 3093 | |
| 3094 | |
| 3095 | |
| 3096 | |
| 3097 | /// The quantiser an intra HEVC export codes at, mapped from the *bitrate* row a |
| 3098 | /// user picked -- the card has no QP control and this codec has no rate control, |
| 3099 | /// so the two are joined by measurement rather than promised to each other. |
| 3100 | /// |
| 3101 | /// The encoder codes ~0.6 bits per pixel at QP 27 ([`HEVC_BPP_AT_27`], measured |
| 3102 | /// on the 720p and 1080p benches to within 4% of each other), and a step of 6 QP |
| 3103 | /// is a factor of two in rate, which is the classic HEVC relation. So the QP |
| 3104 | /// that would land on a target is `27 + 6 * log2(0.6 / target)` -- and it is |
| 3105 | /// clamped, because this is a *quality* dial and not a rate controller: below QP |
| 3106 | /// 22 the file grows without a picture to show for it, and past QP 40 an |
| 3107 | /// intra-only frame goes blocky in a way no bitrate row asked for. A 1080p30 |
| 3108 | /// timeline at the automatic 6.2 Mbps therefore codes at QP 40 and comes out |
| 3109 | /// bigger than that, which is what "intra-only, large files" on the format row |
| 3110 | /// means: the row buys quality, not a size. |
| 3111 | |
| 3112 | |
| 3113 | |
| 3114 | |
| 3115 | |
| 3116 | |
| 3117 | |
| 3118 | /// What the *bitstream* says the samples mean, in the words a sequence header |
| 3119 | /// spells them -- the same H.273 code points [`crate::mux`] writes into the |
| 3120 | /// container, from the same [`ColorDescription::output`] rule, so the two halves |
| 3121 | /// of a file cannot drift apart. |
| 3122 | /// |
| 3123 | /// This exists because a container tag is not enough: libavcodec takes the |
| 3124 | /// bitstream's answer first, and a stream that says nothing is "unspecified", |
| 3125 | /// which renders BT.601 -- a visible shift on a 709 export that a player reads |
| 3126 | /// from the wrong matrix. Every export is limited range, which is what |
| 3127 | /// `video_full_range_flag = false` says here. |
| 3128 | |
| 3129 | |
| 3130 | |
| 3131 | |
| 3132 | |
| 3133 | |
| 3134 | |
| 3135 | |
| 3136 | |
| 3137 | |
| 3138 | |
| 3139 | |
| 3140 | |
| 3141 | |
| 3142 | |
| 3143 | /// Every temporal unit `rav1e` has finished, moved into the queue in display |
| 3144 | /// order. `NeedMoreData` (send another picture) and `LimitReached` (the flush is |
| 3145 | /// through) are the two ways it says there is nothing more; `Encoded` means a |
| 3146 | /// picture was coded but not yet packetised, which is a *keep asking* -- taking |
| 3147 | /// it for an end leaves the tail of the export inside the encoder. |
| 3148 | |
| 3149 | |
| 3150 | |
| 3151 | |
| 3152 | |
| 3153 | |
| 3154 | |
| 3155 | |
| 3156 | |
| 3157 | |
| 3158 | |
| 3159 | |
| 3160 | |
| 3161 | |
| 3162 | |
| 3163 | /// The oldest finished unit, moved into the buffer that is lent out -- the same |
| 3164 | /// "valid until the next call" contract the plugin's slice has. |
| 3165 | |
| 3166 | |
| 3167 | |
| 3168 | |
| 3169 | |
| 3170 | |
| 3171 | |
| 3172 | |
| 3173 | |
| 3174 | /// I420 straight out of the decoder: the export never converts to BGRA and back, |
| 3175 | /// which would cost two conversions and a generation of colour precision. |
| 3176 | /// |
| 3177 | /// This mirrors `decode`'s two worker loops rather than reusing `DecodeSession`, |
| 3178 | /// which only speaks BGRA. Unlike playback there is no mid-clip fallback to |
| 3179 | /// software: a hardware decode that fails after the first picture fails the |
| 3180 | /// export, which then deletes the half-written file. |
| 3181 | |
| 3182 | |
| 3183 | |
| 3184 | |
| 3185 | |
| 3186 | |
| 3187 | |
| 3188 | |
| 3189 | |
| 3190 | |
| 3191 | |
| 3192 | |
| 3193 | |
| 3194 | |
| 3195 | |
| 3196 | |
| 3197 | |
| 3198 | |
| 3199 | |
| 3200 | /// The receiving half of a decode thread, plus the picture it last handed out |
| 3201 | /// -- which is what lets `next` keep lending planes rather than moving them. |
| 3202 | /// |
| 3203 | /// The first two fields are in this order on purpose, and it is the order |
| 3204 | /// [`crate::decode::FrameStream`] states for the same pair: Rust drops fields as |
| 3205 | /// they are declared, so the receiver disconnects *first* -- the only thing that |
| 3206 | /// wakes a decoder parked in a full `send` -- and the join inside |
| 3207 | /// [`DecodeThread::drop`] runs second. The other way round is a hang and not a |
| 3208 | /// slow path. |
| 3209 | |
| 3210 | |
| 3211 | |
| 3212 | |
| 3213 | |
| 3214 | |
| 3215 | |
| 3216 | |
| 3217 | |
| 3218 | |
| 3219 | |
| 3220 | |
| 3221 | |
| 3222 | /// A decode thread, joined when its span's decoder is dropped -- the rule |
| 3223 | /// [`crate::decode::Worker`] is written for: a thread abandoned mid |
| 3224 | /// `vaInitialize` outlives the process, and Mesa's `atexit` handlers then free |
| 3225 | /// the state it is still reading, which is a SIGSEGV at exit long after the |
| 3226 | /// export succeeded. |
| 3227 | >>); |
| 3228 | |
| 3229 | |
| 3230 | |
| 3231 | |
| 3232 | |
| 3233 | |
| 3234 | |
| 3235 | |
| 3236 | |
| 3237 | |
| 3238 | |
| 3239 | |
| 3240 | /// One picture, owned, on its way from a decode thread to the encoder. |
| 3241 | |
| 3242 | |
| 3243 | |
| 3244 | |
| 3245 | |
| 3246 | |
| 3247 | |
| 3248 | |
| 3249 | |
| 3250 | |
| 3251 | |
| 3252 | |
| 3253 | |
| 3254 | |
| 3255 | |
| 3256 | |
| 3257 | |
| 3258 | |
| 3259 | |
| 3260 | |
| 3261 | |
| 3262 | |
| 3263 | |
| 3264 | |
| 3265 | |
| 3266 | |
| 3267 | |
| 3268 | |
| 3269 | |
| 3270 | |
| 3271 | |
| 3272 | |
| 3273 | |
| 3274 | |
| 3275 | |
| 3276 | |
| 3277 | |
| 3278 | |
| 3279 | |
| 3280 | |
| 3281 | |
| 3282 | |
| 3283 | |
| 3284 | |
| 3285 | |
| 3286 | |
| 3287 | |
| 3288 | |
| 3289 | |
| 3290 | |
| 3291 | |
| 3292 | |
| 3293 | |
| 3294 | |
| 3295 | |
| 3296 | |
| 3297 | |
| 3298 | |
| 3299 | |
| 3300 | |
| 3301 | |
| 3302 | |
| 3303 | |
| 3304 | |
| 3305 | |
| 3306 | /// One span's decode, on its own thread: open the file (hardware if the plugin |
| 3307 | /// will have it, software otherwise) and send every picture until the encoder |
| 3308 | /// stops taking them. |
| 3309 | /// |
| 3310 | /// Unlike playback there is no mid-clip fallback to software: a hardware decode |
| 3311 | /// that fails after the first picture fails the export, which then deletes the |
| 3312 | /// half-written file. |
| 3313 | /// |
| 3314 | /// Every way this returns says which way it was, down the channel: a picture, an |
| 3315 | /// error, or the `Ok(None)` that *is* end of stream. Closing the channel is not |
| 3316 | /// one of them -- a silent close is a panicked thread, and the receiver treats |
| 3317 | /// it as the failure it is rather than as a source that ran out. |
| 3318 | |
| 3319 | |
| 3320 | |
| 3321 | |
| 3322 | |
| 3323 | |
| 3324 | |
| 3325 | |
| 3326 | |
| 3327 | |
| 3328 | |
| 3329 | |
| 3330 | |
| 3331 | |
| 3332 | |
| 3333 | |
| 3334 | |
| 3335 | |
| 3336 | |
| 3337 | |
| 3338 | |
| 3339 | |
| 3340 | |
| 3341 | |
| 3342 | |
| 3343 | |
| 3344 | |
| 3345 | |
| 3346 | |
| 3347 | |
| 3348 | |
| 3349 | |
| 3350 | |
| 3351 | |
| 3352 | |
| 3353 | |
| 3354 | |
| 3355 | |
| 3356 | |
| 3357 | |
| 3358 | |
| 3359 | |
| 3360 | |
| 3361 | |
| 3362 | /// The two stream decoders, on the thread that opened them. |
| 3363 | |
| 3364 | |
| 3365 | |
| 3366 | |
| 3367 | |
| 3368 | |
| 3369 | |
| 3370 | |
| 3371 | |
| 3372 | |
| 3373 | |
| 3374 | |
| 3375 | |
| 3376 | |
| 3377 | |
| 3378 | |
| 3379 | |
| 3380 | |
| 3381 | |
| 3382 | |
| 3383 | |
| 3384 | |
| 3385 | |
| 3386 | |
| 3387 | |
| 3388 | |
| 3389 | |
| 3390 | |
| 3391 | |
| 3392 | |
| 3393 | |
| 3394 | |
| 3395 | |
| 3396 | |
| 3397 | |
| 3398 | |
| 3399 | |
| 3400 | |
| 3401 | |
| 3402 | |
| 3403 | |
| 3404 | |
| 3405 | |
| 3406 | |
| 3407 | |
| 3408 | |
| 3409 | |
| 3410 | |
| 3411 | |
| 3412 | |
| 3413 | |
| 3414 | |
| 3415 | |
| 3416 | |
| 3417 | |
| 3418 | |
| 3419 | |
| 3420 | |
| 3421 | |
| 3422 | |
| 3423 | |
| 3424 | |
| 3425 | |
| 3426 | |
| 3427 | |
| 3428 | |
| 3429 | |
| 3430 | |
| 3431 | |
| 3432 | |
| 3433 | |
| 3434 | |
| 3435 | |
| 3436 | |
| 3437 | |
| 3438 | |
| 3439 | |
| 3440 | |
| 3441 | |
| 3442 | |
| 3443 | |
| 3444 | |
| 3445 | |
| 3446 | |
| 3447 | |
| 3448 | |
| 3449 | |
| 3450 | |
| 3451 | |
| 3452 | |
| 3453 | |
| 3454 | |
| 3455 | |
| 3456 | |
| 3457 | |
| 3458 | |
| 3459 | |
| 3460 | |
| 3461 | |
| 3462 | |
| 3463 | |
| 3464 | |
| 3465 | |
| 3466 | |
| 3467 | |
| 3468 | |
| 3469 | |
| 3470 | |
| 3471 | |
| 3472 | |
| 3473 | |
| 3474 | |
| 3475 | |
| 3476 | |
| 3477 | |
| 3478 | |
| 3479 | |
| 3480 | |
| 3481 | |
| 3482 | |
| 3483 | |
| 3484 | |
| 3485 | |
| 3486 | |
| 3487 | |
| 3488 | |
| 3489 | |
| 3490 | |
| 3491 | |
| 3492 | |
| 3493 | |
| 3494 | |
| 3495 | |
| 3496 | |
| 3497 | |
| 3498 | |
| 3499 | |
| 3500 | |
| 3501 | |
| 3502 | |
| 3503 | |
| 3504 | |
| 3505 | |
| 3506 | |
| 3507 | |
| 3508 | |
| 3509 | |
| 3510 | |
| 3511 | |
| 3512 | |
| 3513 | |
| 3514 | |
| 3515 | |
| 3516 | |
| 3517 | |
| 3518 | |
| 3519 | |
| 3520 | |
| 3521 | |
| 3522 | |
| 3523 | |
| 3524 | |
| 3525 | |
| 3526 | |
| 3527 | |
| 3528 | |
| 3529 | |
| 3530 | |
| 3531 | |
| 3532 | |
| 3533 | |
| 3534 | |
| 3535 | |
| 3536 | |
| 3537 | |
| 3538 | |
| 3539 | |
| 3540 | |
| 3541 | |
| 3542 | |
| 3543 | |
| 3544 | |
| 3545 | |
| 3546 | |
| 3547 | |
| 3548 | |
| 3549 | |
| 3550 | |
| 3551 | |
| 3552 | |
| 3553 | |
| 3554 | |
| 3555 | |
| 3556 | |
| 3557 | |
| 3558 | |
| 3559 | |
| 3560 | |
| 3561 | |
| 3562 | |
| 3563 | |
| 3564 | |
| 3565 | |
| 3566 | |
| 3567 | |
| 3568 | |
| 3569 | |
| 3570 | |
| 3571 | |
| 3572 | |
| 3573 | |
| 3574 | |
| 3575 | |
| 3576 | |
| 3577 | |
| 3578 | |
| 3579 | |
| 3580 | |
| 3581 | |
| 3582 | |
| 3583 | |
| 3584 | |
| 3585 | |
| 3586 | |
| 3587 | |
| 3588 | |
| 3589 | |
| 3590 | |
| 3591 | |
| 3592 | |
| 3593 | |
| 3594 | |
| 3595 | |
| 3596 | |
| 3597 | |
| 3598 | |
| 3599 | |
| 3600 | |
| 3601 | |
| 3602 | |
| 3603 | |
| 3604 | |
| 3605 | |
| 3606 | |
| 3607 | |
| 3608 | |
| 3609 | |
| 3610 | |
| 3611 | |
| 3612 | |
| 3613 | |
| 3614 | |
| 3615 | |
| 3616 | |
| 3617 | |
| 3618 | |
| 3619 | |
| 3620 | |
| 3621 | |
| 3622 | |
| 3623 | |
| 3624 | |
| 3625 | |
| 3626 | |
| 3627 | |
| 3628 | |
| 3629 | |
| 3630 | |
| 3631 | |
| 3632 | |
| 3633 | |
| 3634 | |
| 3635 | |
| 3636 | |
| 3637 | |
| 3638 | |
| 3639 | |
| 3640 | |
| 3641 | |
| 3642 | |
| 3643 | |
| 3644 | |
| 3645 | |
| 3646 | |
| 3647 | |
| 3648 | |
| 3649 | |
| 3650 | |
| 3651 | |
| 3652 | |
| 3653 | |
| 3654 | |
| 3655 | |
| 3656 | |
| 3657 | |
| 3658 | |
| 3659 | |
| 3660 | |
| 3661 | |
| 3662 | |
| 3663 | |
| 3664 | |
| 3665 | |
| 3666 | |
| 3667 | |
| 3668 | |
| 3669 | |
| 3670 | |
| 3671 | |
| 3672 | |
| 3673 | |
| 3674 | |
| 3675 | |
| 3676 | |
| 3677 | |
| 3678 | |
| 3679 | |
| 3680 | |
| 3681 | |
| 3682 | |
| 3683 | |
| 3684 | |
| 3685 | |
| 3686 | |
| 3687 | |
| 3688 | |
| 3689 | |
| 3690 | |
| 3691 | |
| 3692 | |
| 3693 | |
| 3694 | |
| 3695 | |
| 3696 | |
| 3697 | |
| 3698 | |
| 3699 | |
| 3700 | |
| 3701 | |
| 3702 | |
| 3703 | |
| 3704 | |
| 3705 | |
| 3706 | |
| 3707 | |
| 3708 | |
| 3709 | |
| 3710 | |
| 3711 | |
| 3712 | |
| 3713 | |
| 3714 | |
| 3715 | |
| 3716 | |
| 3717 | |
| 3718 | |
| 3719 | |
| 3720 | |
| 3721 | |
| 3722 | |
| 3723 | |
| 3724 | |
| 3725 | |
| 3726 | |
| 3727 | |
| 3728 | |
| 3729 | |
| 3730 | |
| 3731 | |
| 3732 | |
| 3733 | |
| 3734 | |
| 3735 | |
| 3736 | |
| 3737 | |
| 3738 | |
| 3739 | |
| 3740 | |
| 3741 | |
| 3742 | |
| 3743 | |
| 3744 | |
| 3745 | |
| 3746 | |
| 3747 | |
| 3748 | |
| 3749 | |
| 3750 | |
| 3751 | |
| 3752 | |
| 3753 | |
| 3754 | |
| 3755 | |
| 3756 | |
| 3757 | |
| 3758 | |
| 3759 | |
| 3760 | |
| 3761 | |
| 3762 | |
| 3763 | |
| 3764 | |
| 3765 | |
| 3766 | |
| 3767 | |
| 3768 | |
| 3769 | |
| 3770 | |
| 3771 | |
| 3772 | |
| 3773 | |
| 3774 | |
| 3775 | |
| 3776 | |
| 3777 | |
| 3778 | |
| 3779 | |
| 3780 | |
| 3781 | |
| 3782 | |
| 3783 | |
| 3784 | |
| 3785 | |
| 3786 | |
| 3787 | |
| 3788 | |
| 3789 | |
| 3790 | |
| 3791 | |
| 3792 | |
| 3793 | |
| 3794 | |
| 3795 | |
| 3796 | |
| 3797 | |
| 3798 | |
| 3799 | |
| 3800 | |
| 3801 | |
| 3802 | |
| 3803 | |
| 3804 | |
| 3805 | |
| 3806 | |
| 3807 | |
| 3808 | |
| 3809 | |
| 3810 | |
| 3811 | |
| 3812 | |
| 3813 | |
| 3814 | |
| 3815 | |
| 3816 | |
| 3817 | |
| 3818 | |
| 3819 | |
| 3820 | |
| 3821 | |
| 3822 | |
| 3823 | |
| 3824 | |
| 3825 | |
| 3826 | |
| 3827 | |
| 3828 | |
| 3829 | |
| 3830 | |
| 3831 | |
| 3832 | |
| 3833 | |
| 3834 | |
| 3835 | |
| 3836 | |
| 3837 | |
| 3838 | |
| 3839 | |
| 3840 | |
| 3841 | |
| 3842 | |
| 3843 | |
| 3844 | |
| 3845 | |
| 3846 | |
| 3847 | |
| 3848 | |
| 3849 | |
| 3850 | |
| 3851 | |
| 3852 | |
| 3853 | |
| 3854 | |
| 3855 | |
| 3856 | |
| 3857 | |
| 3858 | |
| 3859 | |
| 3860 | |
| 3861 | |
| 3862 | |
| 3863 | |
| 3864 | |
| 3865 | |
| 3866 | |
| 3867 | |
| 3868 | |
| 3869 | |
| 3870 | |
| 3871 | |
| 3872 | |
| 3873 | |
| 3874 | |
| 3875 | |
| 3876 | |
| 3877 | |
| 3878 | |
| 3879 | |
| 3880 | |
| 3881 | |
| 3882 | |
| 3883 | |
| 3884 | |
| 3885 | |
| 3886 | |
| 3887 | |
| 3888 | |
| 3889 | |
| 3890 | |
| 3891 | |
| 3892 | |
| 3893 | |
| 3894 | |
| 3895 | |
| 3896 | |
| 3897 | |
| 3898 | |
| 3899 | |
| 3900 | |
| 3901 | |
| 3902 | |
| 3903 | |
| 3904 | |
| 3905 | |
| 3906 | |
| 3907 | |
| 3908 | |
| 3909 | |
| 3910 | |
| 3911 | |
| 3912 | |
| 3913 | |
| 3914 | |
| 3915 | |
| 3916 | |
| 3917 | |
| 3918 | |
| 3919 | |
| 3920 | |
| 3921 | |
| 3922 | |
| 3923 | |
| 3924 | |
| 3925 | |
| 3926 | |
| 3927 | |
| 3928 | |
| 3929 | |
| 3930 | |
| 3931 | |
| 3932 | |
| 3933 | |
| 3934 | |
| 3935 | |
| 3936 | |
| 3937 | |
| 3938 | |
| 3939 | |
| 3940 | |
| 3941 | |
| 3942 | |
| 3943 | |
| 3944 | |
| 3945 | |
| 3946 | |
| 3947 | |
| 3948 | |
| 3949 | |
| 3950 | |
| 3951 | |
| 3952 | |
| 3953 | |
| 3954 | |
| 3955 | |
| 3956 | |
| 3957 | |
| 3958 | |
| 3959 | |
| 3960 | |
| 3961 | |
| 3962 | |
| 3963 | |
| 3964 | |
| 3965 | |
| 3966 | |
| 3967 | |
| 3968 | |
| 3969 | |
| 3970 |