1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2025-04-15 08:14:15 +00:00
This commit is contained in:
damitha 2025-03-22 14:59:56 +11:00
parent 8b47da93c6
commit f085d794f1
3 changed files with 35 additions and 1 deletions

View file

@ -261,7 +261,7 @@ impl<R: Read + Seek> Mp4Reader<R> {
Err(Error::TrakNotFound(track_id))
}
}
//Mp4SampleMetadata
pub fn read_sample(&mut self, track_id: u32, sample_id: u32) -> Result<Option<Mp4Sample>> {
if let Some(track) = self.tracks.get(&track_id) {
track.read_sample(&mut self.reader, sample_id)
@ -270,6 +270,15 @@ impl<R: Read + Seek> Mp4Reader<R> {
}
}
pub fn read_sample_metadata(&mut self, track_id: u32, sample_id: u32) -> Result<Option<Mp4SampleMetadata>> {
if let Some(track) = self.tracks.get(&track_id) {
track.read_sample_metadata(&mut self.reader, sample_id)
} else {
Err(Error::TrakNotFound(track_id))
}
}
pub fn sample_offset(&mut self, track_id: u32, sample_id: u32) -> Result<u64> {
if let Some(track) = self.tracks.get(&track_id) {
track.sample_offset(sample_id)

View file

@ -619,6 +619,23 @@ impl Mp4Track {
}
}
pub(crate) fn read_sample_metadata<R: Read + Seek>(
&self,
reader: &mut R,
sample_id: u32,
) -> Result<Option<Mp4SampleMetadata>> {
let (start_time, duration) = self.sample_time(sample_id).unwrap();
let rendering_offset = self.sample_rendering_offset(sample_id);
let is_sync = self.is_sync_sample(sample_id);
Ok(Some(Mp4SampleMetadata {
start_time,
duration,
rendering_offset,
is_sync,
}))
}
pub(crate) fn read_sample<R: Read + Seek>(
&self,
reader: &mut R,

View file

@ -671,6 +671,14 @@ pub struct Mp4Sample {
pub bytes: Bytes,
}
#[derive(Debug)]
pub struct Mp4SampleMetadata {
pub start_time: u64,
pub duration: u32,
pub rendering_offset: i32,
pub is_sync: bool,
}
impl PartialEq for Mp4Sample {
fn eq(&self, other: &Self) -> bool {
self.start_time == other.start_time