forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on ddf43e86ffb3d750efc0cd9c77848fd97ff0bf3dFiltered to crates/ec-mp4/src/lib.rsClear filter

2026-09-06

fix(mp4): a QuickTime .mov kept its esds inside wave and demuxed silentAhmet Kaan Gümüş · 25da208
fix(mp4): a QuickTime .mov kept its esds inside wave and demuxed silent

QuickTime-brand files (Resolve, Final Cut, `ffmpeg -f mov`) state `mp4a` as
a SoundDescription, not an ISO sample entry: the codec configuration sits in
a `wave` box beside the `frma` restating the format, and the entry itself
carries a version-1 tail or a version-2 block before its children. The
reader skipped `wave` outright, so it never found the `esds`, handed the
decoder no AudioSpecificConfig and the sound track played as nothing.

`wave` is now walked for the configuration box the sample entry's own
fourcc names (`esds`, `dac3`, `dec3`, `alac`, `dfLa`, `dOps`), stopping at
the zero terminator. The version-2 block's sample rate, a double, is read
instead of dropped for an `mdhd` timescale nothing applied -- a v2 entry
reported 0 Hz.

The ISO path is untouched: the corpus gains a QuickTime-branded copy of the
AAC fixture, checked against ffprobe for codec, rate, channels and
extradata, and a synthetic v2 entry pins the shape no ffmpeg-written
fixture has.

2026-08-14

feat(mp4): the index, random access and late-declared streams a host needsAhmet Kaan Gümüş · d7dca0c
feat(mp4): the index, random access and late-declared streams a host needs

The replica's engine reads and writes mp4 through this crate now, and five
things it needs were not reachable through the two traits alone:

- `Sample` is public, and `samples(stream)` hands the whole resolved table
  over. That table *is* the index an mp4 carries of itself -- a caller that
  counts frames, builds a display-order seek table or asks what a track spends
  reads it here instead of walking the file again.
- `read_sample(stream, index)` reads one sample of one stream without moving
  the packet cursor: random access beside the sequential `next_packet`, for a
  caller holding an index of its own.
- `tracks()` lists every track the container declares, in file order, with its
  `tkhd` id, its handler, its sample entry fourcc, its language and its edit
  list's `media_time`. Two things ride on it: a track whose codec this build
  has no id for is still listed (a picker greys such a row out rather than
  pretending the file has fewer tracks than it has), and `avc3` can be told
  from `avc1` by a host that re-injects parameter sets out of the `avcC`.
- `duration_secs()` is the `mvhd`'s own length, which is what a file's byte
  rate is measured over -- not any one track's.
- The muxer takes `add_stream` at any point before `finish`, and `set_color`
  after the stream is declared. Samples are written where they arrive and the
  sample entries are built at the end, so a track declared after the picture
  is already in the `mdat` costs nothing -- which is what lets an export mix
  and encode its sound while it writes the picture, and add its subtitles once
  the film's length is known.

cargo test -p ec-mp4: 10 passed.
feat(mp4): the writer, with the boxes edith wrote by hand in-crateAhmet Kaan Gümüş · 7336903
feat(mp4): the writer, with the boxes edith wrote by hand in-crate

One pass: ftyp, then an mdat the samples stream into, then the moov built
from what was written (a faststart layout would have to copy the whole
mdat a second time). Sample tables are generated from the packets --
run-length stts, ctts only where something is reordered, stss only where
some sample is not a sync one, co64 where the file is big enough to need
it -- and an elst is written where the first picture is not the first
decoded one, so a reordered track does not start late.

The four boxes edith patched into the incumbent's output are written here
instead: av01+av1C, hvc1+hvcC, colr nclx (with mdcv/clli beside it, so an
HDR grade survives a remux) and udta/name for the movie and each track,
plus a tx3g entry with its style and font table.
feat(mp4): ISOBMFF box model, esds descriptors and the demuxerAhmet Kaan Gümüş · 49be010
feat(mp4): ISOBMFF box model, esds descriptors and the demuxer

The box walk checks every size against its parent and every table entry
count against the box that holds it, so a crafted header is an error and
never an allocation. The moov walk resolves the sample tables into
offset/size/dts/cts/sync per sample, reads fragments (moof/traf/trun)
into the same tables, and takes the frame rate off stts as an exact
rational -- whole track over whole track, so NTSC film stays 24000/1001
instead of decaying into 23.

A sample entry is read for what it says it is: an mp4a holding MP3 is an
MP3 track rather than a dropped one, ac-3/ec-3/alac/Opus/fLaC and the
QuickTime PCM entries are their own codecs, and an entry with no CodecId
leaves its track listed rather than decoded as something else. The esds
parser hands back the DecoderSpecificInfo as bytes, which is the field
callers previously had to rebuild from parsed fields.