mozilla / mp4parse-rust

Parser for ISO Base Media Format aka video/mp4 written in Rust.
Mozilla Public License 2.0
404 stars 62 forks source link

Get correct media duration for files produced using `afconvert` #404

Open padenot opened 1 year ago

padenot commented 1 year ago

https://user-images.githubusercontent.com/270485/236244141-be70cc83-e36c-4ff6-ac30-49d51227b339.mp4

Here's a file that is supposed to be exactly 0.5s long.

It has been produced by taking a wav file that's 0.5s long exactly and running this on a mac:

afconvert -s 3 -f mp4f -d aac half-a-second-44110-1ch.wav

It's got an elst saying the file has a start time of 2112 (typical for macOS AAC encoder), and a segment duration of 22050 (which is correct).

mp4parse-rust reports a duration of 24576, because it uses the duration of the track. mp4parse_get_fragment_info doesn't work because it doesn't look into the right box.

karlt commented 12 months ago

24576 is the duration indicated in the mdhd box. The single edts entry indicates to edit to a duration of 22050, which is read into Track::edited_duration, but this does not find its way into the Mp4parseTrackInfo.