edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
Lane mp4edittrim: audio edit duration in Mp4Muxer
Goal
Mp4Muxer::set_audio_delay writes only the priming media_time; the edit runs to the end of
the samples. edith copies AAC into an export and needs the audio edit trimmed to the picture's
length, as ffmpeg and old edith did (the copied sound ran about 0.017 s past the picture).
Base: f5eb855b (main). Branch lane/mp4edittrim.
API edith should call
muxer.set_edit(audio_stream, priming_samples, picture_samples)?;
audio_stream: theu32returned byadd_streamfor the AAC track.priming_samples: u32: the encoder priming in the track's own timescale (the sample rate, 1024 for AAC-LC). This is the same valueset_audio_delaytakes.picture_samples: u32: the picture's length in the same timescale, that isround(picture_seconds * sample_rate). No conversion inside the muxer.- Both values are track ticks. The muxer rounds the segment up to the 1000 Hz movie clock.
set_editreplacesset_audio_delayfor that stream. Call one or the other, not both. Itsmedia_timeis the shift, so pass the priming there.
Changes
crates/ec-mp4/src/mux.rsTrack.edit: Option<(u32, u32)>holds(media_time, duration).pub fn set_edit(&mut self, stream: u32, media_time: u32, duration: u32) -> Result<()>.- At
finish, a set edit writes oneedts/elstentry:segment_durationin the movie timescale (rounded up),media_timein the track timescale, rate 1.0. tkhdduration and the moviemvhdduration use the edited span.mvhdis the maximum of every track's presentation length, so an unedited track is unchanged.- Without a call nothing changes. Only the new branches are taken, and the default path still runs the same code.
crates/ec-mp4/tests/edit_trim.rs(new)default_aac_priming_output_is_byte_identical: MD5 of the AAC priming output (set_audio_delay(1024), 47 frames), pinned as2ba0fd44a7dfa3b69cb60d7aceb71753. The value was captured on the unchanged tree beforeset_editwas written, and matches after.set_edit_trims_the_audio_edit_to_its_stated_length: priming 1024, picture 40000 samples against 48128 samples of media. Checkstkhdandmvhdboth equal 834 ms,mvhdtimescale 1000, the crate's demuxer reads one edit withmedia_time1024 andsegment_duration834, and ffprobestart_timeis 0 with stream duration within one AAC frame of the picture.
No changes to demux.rs. No changes to the ec-core API. cargo fmt was run on the crate and
its unrelated reformatting was reverted, so the diff is limited to mux.rs and the new test.
Verify (server, scripts/remote-run.sh mp4edittrim --host auto, host c)
- Baseline MD5 on unchanged code:
2ba0fd44a7dfa3b69cb60d7aceb71753. After the change: same. cargo test --release -p ec-mp4: all green.- lib 26 passed
- edit_trim 2 passed
- edith_parity 2 passed
- fuzz_regressions 1 passed
- mp4 16 passed, 1 ignored (
the_real_library_demuxes_to_eof, pre-existing) - mux_entries 10 passed
- rotation 3 passed
cargo clippy -p ec-mp4 --all-targets -- -D warnings: clean, exit 0.- ffprobe on the new test output:
start_time 0,duration 0.834for a0.8333s picture. The movie clock rounds the segment up to 834 ms.
Notes and what is left
- Not wired in edith. That is the edith call site above.
set_editoverrides a reorder-delay or Opus pre-skip shift on the same track. It is meant for audio tracks. Video edits are not covered by a test.- The 1000 Hz movie clock gives up to 1 ms of rounding on
segment_duration. The sample- accurate value is still in the track'smedia_time. - No test on a multi-track file (edited audio next to video). The
mvhdmaximum rule is implemented but only the audio-only case is tested.