mirror of
https://github.com/alfg/mp4-rust.git
synced 2025-04-15 08:14:15 +00:00
.
This commit is contained in:
parent
8b47da93c6
commit
f085d794f1
3 changed files with 35 additions and 1 deletions
|
@ -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)
|
||||
|
|
17
src/track.rs
17
src/track.rs
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue