edith_codecs
Clone
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
lane mp4mux: ec-mp4 writes every sample entry edith's MP4 export needs
Goal: DONE.md wave 2, the mp4 crate to ec-mp4 swap. ec-mp4's muxer must write the
sample entries edith's MP4 export uses, verified against ffprobe, ffmpeg's decode and
ec-mp4's own demuxer.
Base: main at d271a92b. Branch lane/mp4mux, worktree ~/.cache/wt/mp4mux.
What edith's MP4 export writes (read-only survey of edith)
From crates/engine/src/mux.rs and the vendored mp4 crate:
- video:
avc1+avcC(H.264);av01+av1C(create_av1, patched into anavc1placeholder);hvc1+hvcC(create_hevc, same patch). - audio:
mp4a+esds(AAC) withedts/elstpriming. - subtitles:
tx3g, withtrak/udta/name. - boxes:
colr(nclx),mdcv,clli,pasp,moov/udta/name. - ftyp:
isom,iso2, the codec's own brand,mp41. - Opus is refused for MP4 (
mux.rsline 389: "this writer declaresmp4aonly"). edith has no AC-3, E-AC-3 or ALAC path into MP4 at all.
So for edith's current export, the entries that matter are avc1, hvc1, av01, mp4a and tx3g. The brief's ac-3, ec-3, alac and Opus entries are covered at the ec-mp4 level (they are the codec-general entries ec-mp4 advertises), not because edith needs them today.
What already existed in ec-mp4
mux.rs already writes avc1, hvc1, av01, vp09, vp08, mp4a, ac-3/dac3,
ec-3/dec3, Opus/dOps, alac, fLaC, sowt, twos, raw , tx3g, colr,
mdcv, clli, pasp, edts/elst priming, and the ftyp brands. Every entry was
checked end to end rather than assumed.
What changed
crates/ec-mp4/src/mux.rs,track_ticks: the track span is now the latest end of any sample in presentation or decode time (max(dts+dur, cts+dur) - first), not the last sample's decode end. A reordered (B-frame) stream's last picture is shown a reorder delay after its decode time, so theelstthat starts the picture at its priming was 1 reorder delay too short. Symptom before the fix: an ffmpeg H.264 or HEVC source of 1.000 s remuxed to 0.920 s (avc1,hvc1cases failed). No-reorder tracks compute the same value as before.crates/ec-mp4/src/mux.rs,opus_pre_skip: an Opus track's priming is now at least itsOpusHeadpre-skip (ordOpspre-skip), written as theelstmedia_time, per the Opus-in-ISOBMFF convention. Without it a caller that carries no edit list gets packets shifted by the pre-skip (first pts 0 instead of -312 at 48 kHz). Verified: the new test fails with this line disabled and passes with it.crates/ec-mp4/src/mux.rs, ALAC: a bare magic cookie (noalacbox header) is now wrapped in analacbox. Before, it fell through to thedOpsbox name, which is wrong for ALAC.crates/ec-mp4/tests/mux_entries.rs(new): one test per entry, each muxing an ffmpeg-made source through ec-mp4 and checking (a) ffprobe stderr empty and the same codec, channels, rate and duration as the source; (b) ffmpeg decode MD5 of the stream equal to the source's; (c) ec-mp4's demuxer reads the same packet count, streams, stream index, pts, dts, duration, keyframe flag and bytes. Plusopus_pre_skip_is_written_without_a_caller_askingandalac_bare_cookie_is_written_inside_an_alac_box. Skips when ffmpeg, ffprobe or the needed encoder is missing. Each test works in its own directory.
Not changed: demux.rs, esds.rs (the parallel mp4demux lane's files). boxes.rs
unchanged.
Verify
Run through scripts/remote-run.sh mp4mux (hosts a and c were both used across runs).
| command | result |
|---|---|
cargo clippy -p ec-mp4 --all-targets -- -D warnings |
exit 0, no warnings |
cargo test -p ec-mp4 --release --no-fail-fast |
lib 19 pass; mp4.rs 16 pass, 1 ignored (the_real_library_demuxes_to_eof, pre-existing); mux_entries.rs 10 pass; rotation.rs 3 pass |
cargo test -p ec-alac --release --test encode (mp4 muxer dependent) |
8 pass |
cargo test -p ec-aac --release --test sbr_real_library (mp4 muxer dependent) |
16 pass |
cargo check in crates/ec-mp4/fuzz |
builds |
rustfmt --check on mux_entries.rs |
clean |
Fuzz: crates/ec-mp4/fuzz has demux_mp4, esds_parse and is_mp4. None links the
muxer, so there is no mux roundtrip target to run for 60 s. The fuzz crate builds, and
nothing was run.
Entry table (mux_entries.rs, all from ffmpeg-made sources):
| entry | codec | ffprobe-clean | decode equal (MD5) | roundtrip (packets, pts, dts, keyframes, bytes) |
|---|---|---|---|---|
avc1 |
H.264 | yes | yes | yes |
hvc1 |
HEVC | yes | yes | yes |
av01 |
AV1 | yes | yes | yes |
mp4a |
AAC | yes | yes | yes |
ac-3 |
AC-3, 5.1 | yes | yes | yes |
ec-3 |
E-AC-3, 5.1 | yes | yes | yes |
alac |
ALAC | yes | yes | yes; bare-cookie variant passes |
Opus |
Opus | yes | yes | yes; no-caller-shift variant passes |
Each entry passes all three checks. Not checked: edith's own export through the new
ec-mp4 muxer (the swap is a later step), or the tx3g, colr/HDR and udta paths
beyond the existing tests.
Flake seen, not fixed here
mp4.rs::a_fragmented_file_demuxes_to_the_same_packets_as_a_plain_one failed once in a
full parallel run. Two tests both write the shared derived_fixtures() files at the same
time (mp4.rs work()), so one reads a half-written file. It passes alone and on rerun.
This is pre-existing and predates this lane. A fix would give each test its own work
directory, as mux_entries.rs now does.
Left
- The demux side of the
dOps/elstpre-skip path is indemux.rs, which this lane does not touch. The round trip relies on it as it stands. vp09/vp08have no ec-mp4 test here beyond the existing ones.- The edith side of the swap (switching
crates/enginefrommp4to ec-mp4) is out of scope for this lane.