edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB25a6b5fTahinli2 months ago3171 commits
| 1 | //! MP4/ISOBMFF (`.mp4`, `.m4v`, `.m4a`) and QuickTime (`.mov`), both directions. |
| 2 | //! |
| 3 | //! [`Mp4Demuxer`] reads a container into [`ec_core::Packet`]s and [`Mp4Muxer`] |
| 4 | //! writes them back out; both speak the [`ec_core::Demuxer`] and |
| 5 | //! [`ec_core::Muxer`] contracts, so nothing above them knows which container it |
| 6 | //! is holding. |
| 7 | //! |
| 8 | //! Contracts worth knowing before implementing against this crate: |
| 9 | //! |
| 10 | //! - **The frame rate is a rational read off `stts`, never a rounded field.** |
| 11 | //! Whole track over whole track, so a constant table gives exactly |
| 12 | //! `timescale/delta` and a 90 kHz table spreading 3753/3754 ticks a frame |
| 13 | //! gives exactly `24000/1001`. An NTSC film that arrives as 23.976 leaves as |
| 14 | //! 23.976, which is the one bug this crate was written to not have. |
| 15 | //! - **A sample entry is read for what it says it is.** An `mp4a` holding MP3 is |
| 16 | //! an MP3 track, an `ac-3`/`ec-3`/`alac`/`Opus`/`fLaC` entry is that codec, |
| 17 | //! and an entry this build has no [`ec_core::CodecId`] for leaves its track |
| 18 | //! listed as nothing rather than decoded as something else. |
| 19 | //! - **QuickTime's own sound descriptions are read as such.** A `.mov` out of |
| 20 | //! Resolve, Final Cut or `ffmpeg -f mov` states `mp4a` as a version-1 or |
| 21 | //! version-2 SoundDescription — the second one carrying its sample rate as a |
| 22 | //! double and its channel count as a 32-bit field — and keeps the `esds` |
| 23 | //! inside a `wave` box rather than directly under the entry. Both shapes give |
| 24 | //! the same codec, rate, channels and `AudioSpecificConfig` as the ISO |
| 25 | //! branding of the same stream; a reader that walks past `wave` has a silent |
| 26 | //! sound track instead. |
| 27 | //! - **`esds` hands back bytes.** [`Esds::decoder_specific`] is the raw |
| 28 | //! `DecoderSpecificInfo` — an AAC track's `AudioSpecificConfig` verbatim, not |
| 29 | //! a triplet of parsed fields a caller has to reassemble. |
| 30 | //! - **The edit list shifts, it never trims.** An initial empty edit is a delay |
| 31 | //! and the first real edit's `media_time` is where the media starts; no sample |
| 32 | //! is ever dropped for either, because a muxer writes `media_time` equal to |
| 33 | //! the first composition offset and reading *that* as a trim throws away real |
| 34 | //! pictures. |
| 35 | //! - **Malformed input is an error, never a panic.** Box sizes are checked |
| 36 | //! against their parent, table entry counts against the box that holds them |
| 37 | //! and the sample count against the length of the file, so a crafted header |
| 38 | //! cannot allocate the machine. `forbid(unsafe_code)`, and no arithmetic on a |
| 39 | //! parsed number that is not checked or saturating. |
| 40 | //! - **The muxer writes `mdat` first and `moov` last**, in one pass; see |
| 41 | //! [`Mp4Muxer`] for what that costs and what it buys. |
| 42 | //! |
| 43 | //! What this crate deliberately does *not* do: convert between Annex-B and |
| 44 | //! length-prefixed samples. An mp4 sample is the codec's own bytes and this |
| 45 | //! writes what it is given — the bitstream-format question belongs to the codec |
| 46 | //! crates, not to the container. |
| 47 | //! |
| 48 | //! No async, no unsafe, no external dependencies. |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | pub use ; |
| 59 | pub use ; |
| 60 | pub use Mp4Muxer; |
| 61 | |
| 62 | /// True when `head` looks like an ISOBMFF file: the second word of its first box |
| 63 | /// is one of the types an mp4 or a `.mov` starts with. |
| 64 | /// |
| 65 | /// `ftyp` is what every file written this century begins with; the rest are what |
| 66 | /// a QuickTime file from before it does, and `styp`/`moof` are a fragment handed |
| 67 | /// over on its own. |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 |