edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
| 1 | //! MPEG-2 Transport Stream demuxer (and, in [`PsDemuxer`], MPEG-1 system / MPEG-2 |
| 2 | //! program streams and raw MPEG-1/2 video): `.ts`/`.mpg`-style 188-byte streams and the |
| 3 | //! 192-byte BDAV (`.m2ts`, `.mts`) files AVCHD camcorders and Blu-ray write. |
| 4 | //! |
| 5 | //! [`TsDemuxer`] speaks [`ec_core::Demuxer`]. Contracts worth knowing before |
| 6 | //! integrating: |
| 7 | //! |
| 8 | //! - **Packet size and resync.** 188, 192 (4-byte `TP_extra_header`) and 204 |
| 9 | //! (Reed-Solomon) are told apart by the sync-byte stride. A lost sync byte is |
| 10 | //! searched for again (four confirming strides) and the PES in flight is flagged |
| 11 | //! `corrupt`; nothing panics on any input. |
| 12 | //! - **Streams.** The first program is read (`with_program` picks another; |
| 13 | //! [`TsDemuxer::programs`] lists all). Streams the family can decode are in |
| 14 | //! `streams()` (MPEG audio layers I, II and III as `Mp1`, `Mp2`, `Mp3`); the rest (LATM, odd-channel |
| 15 | //! LPCM, DVB subtitles, DTS, ...) are in [`TsDemuxer::tracks`] with a |
| 16 | //! refusal that names the codec. A PMT change mid-stream keeps the indices of |
| 17 | //! streams that stay and appends new ones. |
| 18 | //! - **Timing.** Every packet is in a `1/90000` time base. 33-bit PTS/DTS are |
| 19 | //! unwrapped into monotonic `i64`; `StreamInfo::start_time` is the first PTS. |
| 20 | //! - **Video** is delivered as Annex-B access units (split on PES boundaries, and on |
| 21 | //! access unit delimiters inside a PES for progressive H.264 and HEVC), with the |
| 22 | //! keyframe flag from IDR/IRAP NAL types, recovery-point SEI or the PES |
| 23 | //! `random_access_indicator`. `extradata` carries an `avcC`/`hvcC` built from the |
| 24 | //! in-band parameter sets; [`VideoFraming::LengthPrefixed`] converts packets to |
| 25 | //! the matching length-prefixed form. |
| 26 | //! - **MPEG-1/2 video** (stream types 0x01, 0x02) is exposed as |
| 27 | //! `CodecId::Mpeg2Video`, one packet per coded picture with the sequence/GOP |
| 28 | //! headers in front of it (a PES holding several pictures is cut at picture start |
| 29 | //! codes; a picture split over several timestamped PES is not re-joined). Keyframe |
| 30 | //! = an I picture or a sequence header. Size, frame rate, aspect and chroma come |
| 31 | //! from the sequence header and sequence_extension, which are also the extradata. |
| 32 | //! - **Audio** is split into frames (ADTS, AC-3/E-AC-3 syncframes, MPEG audio); |
| 33 | //! ADTS frames keep their headers and `extradata` is the derived |
| 34 | //! AudioSpecificConfig. HDMV LPCM loses its 4-byte header. |
| 35 | //! - **TrueHD** (stream type 0x83, Blu-ray) is exposed as `CodecId::TrueHd`, one |
| 36 | //! packet per access unit: the 4-byte access-unit header (length word, input |
| 37 | //! timing) and everything after it, the form `ec_truehd::TrueHdDecoder` decodes |
| 38 | //! (and the form the MP4 and Matroska demuxers hand over). Blu-ray interleaves an |
| 39 | //! AC-3 core (0x0B77 syncframes) in the same PID; those frames are dropped, not |
| 40 | //! exposed, since the TrueHD access units carry the same audio losslessly and |
| 41 | //! they take no time on the timeline. Timestamps come from the first access unit |
| 42 | //! that starts in a PES and advance by 40 << n samples per access unit (n from the |
| 43 | //! major sync's rate code), so the AC-3 frames do not shift them. |
| 44 | //! - **Seeking** bisects the byte range on the video track's timestamps, then scans |
| 45 | //! forward to the keyframe at or before the target. It is exact: the packets read |
| 46 | //! after a seek are those a sequential read yields from |
| 47 | //! [`TsDemuxer::last_packet_offset`] on. |
| 48 | //! |
| 49 | //! No async, no unsafe. |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | pub use |
| 68 | |
| 69 | |
| 70 | ; |
| 71 | pub use ; |
| 72 | pub use ; |
| 73 | pub use ; |
| 74 | |
| 75 | /// True when `head` (the first few KiB of a file) is a transport stream at one of |
| 76 | /// the three packet sizes. A probe hands the file to [`TsDemuxer`] on this. |
| 77 | |
| 78 | |
| 79 |