TechSmith / mp4v2

Fork of mp4v2: https://code.google.com/archive/p/mp4v2/
Other
284 stars 135 forks source link

Fix sample time calculation for times >= 2^32. #24

Open enzo1982 opened 6 years ago

enzo1982 commented 6 years ago

An issue handling long MP4 files containing audio books with hundreds of chapters was reported by a fre:ac user. Turned out the issue is with MP4v2.

In MP4Track::GetSampleTimes and MP4Track::GetSampleIdFromTime, sampleCount is a 32 bit value that is later multiplied by sampleDelta in 32 bit math. We need this multiplication to happen in 64 bit math to handle long tracks, so promote sampleCount to a 64 bit variable.

An alternative solution would be to add casts to uint64_t where the multiplications happen, but changing the value type seemed more elegant to me. If you prefer it the other way, I can change this PR accordingly.