mirror of
https://github.com/alfg/mp4-rust.git
synced 2025-01-03 08:58:40 +00:00
Add better handling of sample sizes for fragmented media
This commit is contained in:
parent
35560e94f5
commit
6301a7b0fe
2 changed files with 15 additions and 12 deletions
|
@ -98,9 +98,11 @@ impl<R: Read + Seek> Mp4Reader<R> {
|
|||
// Update tracks if any fragmented (moof) boxes are found.
|
||||
if !moofs.is_empty() {
|
||||
let mut default_sample_duration = 0;
|
||||
let mut default_sample_size = 0;
|
||||
if let Some(ref moov) = moov {
|
||||
if let Some(ref mvex) = &moov.mvex {
|
||||
default_sample_duration = mvex.trex.default_sample_duration
|
||||
default_sample_duration = mvex.trex.default_sample_duration;
|
||||
default_sample_size = mvex.trex.default_sample_size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,6 +111,7 @@ impl<R: Read + Seek> Mp4Reader<R> {
|
|||
let track_id = traf.tfhd.track_id;
|
||||
if let Some(track) = tracks.get_mut(&track_id) {
|
||||
track.default_sample_duration = default_sample_duration;
|
||||
track.default_sample_size = default_sample_size;
|
||||
track.moof_offsets.push(moof_offset);
|
||||
track.trafs.push(traf.clone())
|
||||
} else {
|
||||
|
|
22
src/track.rs
22
src/track.rs
|
@ -97,6 +97,7 @@ pub struct Mp4Track {
|
|||
|
||||
// Fragmented Tracks Defaults.
|
||||
pub default_sample_duration: u32,
|
||||
pub default_sample_size: u32,
|
||||
}
|
||||
|
||||
impl Mp4Track {
|
||||
|
@ -107,6 +108,7 @@ impl Mp4Track {
|
|||
trafs: Vec::new(),
|
||||
moof_offsets: Vec::new(),
|
||||
default_sample_duration: 0,
|
||||
default_sample_size: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,21 +391,19 @@ impl Mp4Track {
|
|||
fn sample_size(&self, sample_id: u32) -> Result<u32> {
|
||||
if !self.trafs.is_empty() {
|
||||
if let Some((traf_idx, sample_idx)) = self.find_traf_idx_and_sample_idx(sample_id) {
|
||||
if let Some(size) = self.trafs[traf_idx]
|
||||
let mut default_sample_size = self.default_sample_size;
|
||||
let traf = &self.trafs[traf_idx];
|
||||
if let Some(size) = traf.tfhd.default_sample_size {
|
||||
default_sample_size = size;
|
||||
}
|
||||
if let Some(size) = traf
|
||||
.trun
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.sample_sizes
|
||||
.get(sample_idx)
|
||||
.and_then(|trun| trun.sample_sizes.get(sample_idx))
|
||||
{
|
||||
Ok(*size)
|
||||
} else {
|
||||
Err(Error::EntryInTrunNotFound(
|
||||
self.track_id(),
|
||||
BoxType::TrunBox,
|
||||
sample_id,
|
||||
))
|
||||
default_sample_size = *size;
|
||||
}
|
||||
Ok(default_sample_size)
|
||||
} else {
|
||||
Err(Error::BoxInTrafNotFound(self.track_id(), BoxType::TrafBox))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue