forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 8c7bf808ae19e1655737ac07a94de22b5002565fFiltered to crates/engine/src/mux.rsClear filter

2026-08-10

🐛 fix(engine): NTSC frame rates survive the sample tableAhmet Kaan Gümüş · 3f81ef8
🐛 fix(engine): NTSC frame rates survive the sample table

`mp4 0.14`'s `Mp4Track::frame_rate` divides the sample count by whole
milliseconds before the float cast, so 24000/1001 read back as a flat
23.0: the picture the audio-sample master clock asked for was 4 % out and
the drift grew with the film — five minutes of it by the end of a
two-hour one. The frame rate now comes off the stts totals in f64, which
is exactly `timescale / delta` for a constant table and an average for a
spread one.

The same truncation lived at the writing end (a 90 kHz clock cannot count
23.976 fps in whole ticks), so the muxer picks a timescale that can:
90 kHz wherever it divides exactly — every integer rate, so those exports
are byte for byte what they were — and `round(fps * 1001)` over 1001
ticks otherwise, which is exact for the whole NTSC family. The hardware
encoder gets that same rational instead of a rounded `fps * 1000`.

The video edit list is honoured now too, the way the audio one always
was — but only what it really trims: a `media_time` equal to the first
`ctts` offset is the B-frame composition delay, not a cut, and reading it
as one throws two real frames away.

A file whose audio we cannot decode at all (an AC-3 remux) played silent
with the reason on stderr; the session carries it now and the window says
NO AUDIO in its notice bar.
✨ feat(engine): real silent AAC for export gaps, link + overflow guardsAhmet Kaan Gümüş · 301e29b
✨ feat(engine): real silent AAC for export gaps, link + overflow guards

Grafts the losing candidate's hand-written AAC-LC silence into the
offset-placed lanes: a gap in the audio lane is copied as max_sfb=0
access units (4 bytes mono, 7 stereo, verified against our own decoder)
instead of being spent as stts duration on the packet in front of it.
That retires the 23 ms leading-gap misplacement, so every packet is one
1024-frame sample table entry again and the muxer takes no duration.

from_parts becomes the release-active untrusted door it claims to be:
per-cause errors, an end-overflow bound, and the grouping rules -- a
link id names at most one clip per lane, and a pair covers one span.
The parser bounds the same overflow by line number, `place` strips the
incoming group id, and the two lane surgeries (`clear`, `open_room`)
drop the id from what they cut, which is where duplicates came from.
✨ feat(engine): video+audio lanes with offset-placed clips, gaps, .edith v2Ahmet Kaan Gümüş · 59eb78e
✨ feat(engine): video+audio lanes with offset-placed clips, gaps, .edith v2

Project gains two lanes; a Clip now carries `start` (its timeline
placement) and `link` (group id), so a gap is simply the absence of a
placement rather than an object anyone has to keep in sync. Moves and
trims become arithmetic on start/in_frame; the lane invariant (sorted,
non-overlapping) is checked in from_parts, at the .edith parser, and
asserted after every mutation.

split cuts every lane and hands the two sides fresh group ids; regroup
is its exact inverse. delete still ripples both lanes (the app keeps its
behaviour), lift removes one placement and leaves a hole, place is the
per-lane overwrite that can make one.

A video gap plays as black frames from a worker that opens no file --
same channel, backpressure, cancel and retire path as a decoder -- and
exports as encoded black. An audio gap is synthesised zero chunks, real
ones, so the master clock keeps counting through it; on the export side
it is spent as stts duration on the packet beside it, since there is no
AAC encoder to make silence with.

.edith v2 writes one line per placement per lane; v1 files still load,
as fully-grouped gapless lanes, and save as v2.

2026-08-09

✨ feat(engine): export — edit list to mp4, HW encode with SW fallbackAhmet Kaan Gümüş · 86d5c15
✨ feat(engine): export — edit list to mp4, HW encode with SW fallback

Worker thread per export: decodes each clip straight to I420 (never through
DecodeSession, which only speaks BGRA), feeds one encoder chosen once --
VA-API plugin unless VE_SW_ENC=1 or the plugin is unavailable, rusty_h264
Fast/CBR otherwise -- and muxes the access units as they come. Audio is
copied packet for packet, so the file has to be opened before the first
video sample is written.

Cancel and every error path delete the partial file; progress is a permille
atomic a render loop can read without a lock.

mux: the movie timescale moves to 90 kHz. mp4 0.14 converts each sample
duration into the movie timescale with its own integer division, so 1 kHz
lost 0.33 ms per frame and made a 4.000 s export announce 3.960 s.
✨ feat(engine): export lane 1 — mux module, AAC packet copyAhmet Kaan Gümüş · 5ce68fe
✨ feat(engine): export lane 1 — mux module, AAC packet copy

mux.rs is the write side of demux.rs: split_annex_b/nal_type feed a
repack to 4-byte-length-prefixed samples (mp4 0.14 hardcodes
length_size_minus_one=3), SPS/PPS/AUD/SEI stripped out of the sample
bytes, is_sync taken from an actual NAL type 5 rather than GOP
arithmetic. Mp4Muxer::create wants the parameter sets up front, so
mux::parameter_sets pulls them out of a buffered first access unit
before the muxer exists. Timescales are 90000 video / sample_rate audio
/ 1000 movie, per-frame duration (90000/fps).round(), and mp4 0.14
ignores Mp4Sample::start_time on write -- timing is duration
accumulation only. An SPS shorter than 4 bytes panics inside the crate
(avc1.rs indexes sps[1..3]), so create rejects that and the other
degenerate shapes up front instead.

Audio is copied, not re-encoded: there is no pure-Rust AAC encoder and
mp4 0.14 has no PCM MediaConfig, so the only honest option is to hand
the source packets back through verbatim.
AudioSession::copy_segments does that -- stts walk to packet ids, no
decode, bytes straight from read_sample. Cut points do not land on
1024-sample boundaries (23.2 ms packets vs 33.3 ms frames), so a
bresenham accumulator picks the packet run per segment and keeps the
cumulative A/V offset under 512 samples, proven by induction over the
carry and measured over 200 random join lists. The first segment starts
one packet early to feed the 1024-sample priming drop; interior
segments do not, because an extra head packet there is 23 ms of
pre-cut audio at every join and it would not fix the missing MDCT
predecessor anyway. That artifact is documented at the seam.