Files
craft-libs/crates/media/tests/mpegts_mux
.CooCoo 7aaa2f8010 craft-media: mpegts::mux writes MPEG-2 transport streams frame by frame to any io::Write (#1998)
* craft-media: mpegts::mux writes MPEG-2 transport streams frame by frame to any io::Write

The mpegts feature gains a transport stream writer (ITU-T H.222.0 |
ISO/IEC 13818-1) next to the demuxer:

- PAT and PMT with the CRC-32 the demuxer checks (ts::crc32_mpeg), at
  the start, every psi_interval, directly before video keyframes, and
  after replace_writer and discontinuity; a PMT longer than one packet
  spans packets.
- One PES packet per frame for H.264, HEVC, MPEG-1, MPEG-2 and MPEG-4
  Part 2 video, AV1 (Carriage of AV1 in MPEG-2 TS), AAC (ADTS, or raw
  frames given an ADTS header), Opus (Opus transport draft V0.1.3,
  including explicit channel mappings and trims), AC-3, E-AC-3 and MPEG
  audio, with PTS and DTS modulo 2^33.
- The PCR on a stream's PID or its own, at most pcr_interval apart
  (100 ms at most), PCR-only packets in gaps, advance() for idle live
  outputs, continuity counters, random access and discontinuity
  indicators.
- Packets go out in batches of batch_packets (7 by default) built in
  fixed buffers; replace_writer returns per-segment facts.
- Frames are checked before anything is written; video frames are
  limited to MAX_UNIT_BYTES so the demuxer reads every one back.

Tests read every codec back with the demuxer (bytes, PTS, DTS, keyframes,
PCR range, no continuity or CRC warnings), check the PES header bits and
the refusals, and fuzz programs, timelines, idle gaps and output swaps.

* craft-media: mpegts::mux leaves out zero-ended AV1 padding and refuses 960-sample AAC configs

An AV1 padding OBU that ends with a zero byte, an empty one included, is
now left out like a temporal delimiter instead of failing the whole
temporal unit. Decoders ignore padding, and the trailing zero would
otherwise form a forbidden sequence with the next start code.

Codec::aac_from_asc refuses an AudioSpecificConfig with frameLengthFlag 1:
an ADTS header has no field for 960-sample frames, so decoders would read
the stream as 1024-sample frames.

* craft-media: the transport stream packet checker refuses a PCR flag in an adaptation field shorter than seven bytes

* craft-media: README states the multistream layout for 3 to 8 channel Opus

An Opus { channels } access unit is one Opus packet for 1 or 2 channels.
For 3 to 8 channels it holds the mapping family 1 streams in the order
of table 4-3 of the Opus transport draft, every stream but the last
self-delimited (RFC 6716 Appendix B). The README now says so, matching
the Codec::Opus doc comment.
2026-11-18 23:26:00 -05:00
..