From: Kostya Shishkov Date: Sat, 17 Dec 2022 10:44:48 +0000 (+0100) Subject: mov: improve seeking in audio-only files X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=de82c8216a0244cc7df9c39bcb392724fc920528;p=nihav.git mov: improve seeking in audio-only files --- diff --git a/nihav-commonfmt/src/demuxers/mov.rs b/nihav-commonfmt/src/demuxers/mov.rs index 7ac68bd..9cf82a9 100644 --- a/nihav-commonfmt/src/demuxers/mov.rs +++ b/nihav-commonfmt/src/demuxers/mov.rs @@ -1480,6 +1480,25 @@ impl Track { } else if self.chunk_offsets.len() == self.chunk_sizes.len() { self.cur_chunk = self.cur_sample; } else { + if !self.time_to_sample.is_empty() { + let mut remaining = exp_pts; + let mut abs_csamp = 0; + for &(count, scount) in self.time_to_sample.iter() { + let count = u64::from(count); + let scount = u64::from(scount); + let nblk = remaining / scount; + if nblk < count { + abs_csamp += nblk; + break; + } + remaining -= count * scount; + abs_csamp += count; + } + self.cur_sample = abs_csamp as usize; + } else { + self.cur_sample = exp_pts as usize; + } + let tgt_sample = self.cur_sample; let mut csamp = 0; self.cur_chunk = 0; let mut cmap = self.sample_map.iter(); @@ -1508,6 +1527,15 @@ impl Track { self.samples_left = cur_samps; self.last_offset = self.chunk_offsets[self.cur_chunk]; self.cur_chunk += 1; + + // try to refine sample position + if self.chunk_sizes.len() > self.chunk_offsets.len() { + for i in self.cur_sample..tgt_sample { + self.cur_sample += 1; + self.samples_left -= 1; + self.last_offset += u64::from(self.chunk_sizes[i]); + } + } } } else { self.cur_chunk = self.cur_sample; @@ -1693,7 +1721,7 @@ impl<'a> DemuxCore<'a> for MOVDemuxer<'a> { if let NATimePoint::Milliseconds(_) = time { let mut aonly = true; for track in self.tracks.iter() { - if track.stream_type != StreamType::Audio || !track.raw_audio { + if track.stream_type != StreamType::Audio { aonly = false; break; }