|
35 | 35 | // file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
36 | 36 |
|
37 | 37 | use byteorder::WriteBytesExt;
|
| 38 | +use mp4parse::unstable::rational_scale; |
38 | 39 | use std::convert::TryFrom;
|
39 | 40 | use std::convert::TryInto;
|
40 | 41 |
|
@@ -628,15 +629,21 @@ pub unsafe extern "C" fn mp4parse_get_track_info(
|
628 | 629 |
|
629 | 630 | let track = &context.tracks[track_index];
|
630 | 631 |
|
631 |
| - if let (Some(timescale), Some(_)) = (track.timescale, context.timescale) { |
| 632 | + if let (Some(timescale), Some(context_timescale)) = (track.timescale, context.timescale) { |
632 | 633 | info.time_scale = timescale.0 as u32;
|
633 | 634 | let media_time: CheckedInteger<u64> = track
|
634 | 635 | .media_time
|
635 | 636 | .map_or(0.into(), |media_time| media_time.0.into());
|
636 | 637 |
|
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 | + }; |
640 | 647 |
|
641 | 648 | info.media_time = match media_time - empty_duration {
|
642 | 649 | Some(difference) => difference,
|
|
0 commit comments