Skip to content

Commit f28852c

Browse files
committed
empty_duration is in the mvhd's time base
1 parent b363e13 commit f28852c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

mp4parse/src/unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl<'a> SampleToChunkIterator<'a> {
465465
/// (n * s) / d is split into floor(n / d) * s + (n % d) * s / d.
466466
///
467467
/// Return None on overflow or if the denominator is zero.
468-
fn rational_scale<T, S>(numerator: T, denominator: T, scale2: S) -> Option<T>
468+
pub fn rational_scale<T, S>(numerator: T, denominator: T, scale2: S) -> Option<T>
469469
where
470470
T: PrimInt + Zero,
471471
S: PrimInt,

mp4parse_capi/src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
3636

3737
use byteorder::WriteBytesExt;
38+
use mp4parse::unstable::rational_scale;
3839
use std::convert::TryFrom;
3940
use std::convert::TryInto;
4041

@@ -628,15 +629,21 @@ pub unsafe extern "C" fn mp4parse_get_track_info(
628629

629630
let track = &context.tracks[track_index];
630631

631-
if let (Some(timescale), Some(_)) = (track.timescale, context.timescale) {
632+
if let (Some(timescale), Some(context_timescale)) = (track.timescale, context.timescale) {
632633
info.time_scale = timescale.0 as u32;
633634
let media_time: CheckedInteger<u64> = track
634635
.media_time
635636
.map_or(0.into(), |media_time| media_time.0.into());
636637

637-
let empty_duration: CheckedInteger<u64> = track
638-
.empty_duration
639-
.map_or(0.into(), |empty_duration| empty_duration.0.into());
638+
// Empty duration is in the context's timescale, convert it and return it in the track's
639+
// timescale
640+
let empty_duration: CheckedInteger<u64> =
641+
match track.empty_duration.map_or(Some(0), |empty_duration| {
642+
rational_scale(empty_duration.0, context_timescale.0, timescale.0)
643+
}) {
644+
Some(time) => mp4parse::unstable::CheckedInteger(time),
645+
None => return Mp4parseStatus::Invalid,
646+
};
640647

641648
info.media_time = match media_time - empty_duration {
642649
Some(difference) => difference,

0 commit comments

Comments
 (0)