1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2024-06-02 13:39:54 +00:00

Set default_sample_duration from moov.mvex.trex for getting fragmented samples.

This commit is contained in:
Alf 2020-09-13 19:52:52 -07:00
parent 12f3a6211d
commit ca002ce2eb
2 changed files with 20 additions and 8 deletions

View file

@ -75,10 +75,20 @@ impl<R: Read + Seek> Mp4Reader<R> {
};
// Update tracks if any fragmented (moof) boxes are found.
for moof in moofs.iter() {
for traf in moof.trafs.iter() {
let track_id = traf.tfhd.track_id as usize - 1;
tracks[track_id].trafs.push(traf.clone());
if moofs.len() > 0 {
let mut default_sample_duration = 0;
if let Some(ref moov) = moov {
if let Some(ref mvex) = &moov.mvex {
default_sample_duration = mvex.trex.default_sample_duration
}
}
for moof in moofs.iter() {
for traf in moof.trafs.iter() {
let track_id = traf.tfhd.track_id as usize - 1;
tracks[track_id].default_sample_duration = default_sample_duration;
tracks[track_id].trafs.push(traf.clone());
}
}
}

View file

@ -90,12 +90,15 @@ impl From<TtxtConfig> for TrackConfig {
pub struct Mp4Track {
pub trak: TrakBox,
pub trafs: Vec<TrafBox>,
// Fragmented Tracks Defaults.
pub default_sample_duration: u32,
}
impl Mp4Track {
pub(crate) fn from(trak: &TrakBox) -> Self {
let trak = trak.clone();
Self { trak, trafs: Vec::new() }
Self { trak, trafs: Vec::new(), default_sample_duration: 0, }
}
pub fn track_id(&self) -> u32 {
@ -428,9 +431,8 @@ impl Mp4Track {
let mut elapsed = 0;
if self.trafs.len() > 0 {
// TODO: Get default_sample_duration from mvex.trex.
let start_time = ((sample_id - 1) * 1000) as u64;
return Ok((start_time, 1000))
let start_time = ((sample_id - 1) * self.default_sample_duration) as u64;
return Ok((start_time, self.default_sample_duration))
} else {
for entry in stts.entries.iter() {
if sample_id <= sample_count + entry.sample_count - 1 {