diff options
Diffstat (limited to 'remuxer/mp4/src')
| -rw-r--r-- | remuxer/mp4/src/boxes.rs | 37 | ||||
| -rw-r--r-- | remuxer/mp4/src/lib.rs | 3 |
2 files changed, 36 insertions, 4 deletions
diff --git a/remuxer/mp4/src/boxes.rs b/remuxer/mp4/src/boxes.rs index 5a4e108..3a1b188 100644 --- a/remuxer/mp4/src/boxes.rs +++ b/remuxer/mp4/src/boxes.rs @@ -25,8 +25,8 @@ container_box!(Media, b"mdia"); container_box!(MediaInformation, b"minf"); container_box!(DataInformation, b"dinf"); container_box!(SampleTable, b"stbl"); -container_box!(MovieFragment, b"stbl"); -container_box!(TrackFragment, b"stbl"); +container_box!(MovieFragment, b"moof"); +container_box!(TrackFragment, b"traf"); container_box!(MovieExtends, b"mvex"); pub struct FileType<'a> { @@ -306,14 +306,35 @@ impl WriteBox for TrackFragmentBaseMediaDecodeTime { } } -pub struct TrackRun { +pub struct TrackRun<'a> { pub data_offset: i32, + pub samples: &'a [TrackRunSample], } -impl WriteBox for TrackRun { +pub struct TrackRunSample { + pub duration: u32, + pub size: u32, + pub flags: u32, + pub composition_time_offset: i32, +} +impl WriteBox for TrackRun<'_> { const BOXTYPE: [u8; 4] = *b"trun"; const VERSION: Option<u8> = Some(1); fn write(&self, buf: &mut Vec<u8>) { + buf.extend((self.samples.len() as u32).to_be_bytes()); buf.extend(self.data_offset.to_be_bytes()); + for s in self.samples { + buf.extend(s.duration.to_be_bytes()); + buf.extend(s.size.to_be_bytes()); + buf.extend(s.flags.to_be_bytes()); + buf.extend(s.composition_time_offset.to_be_bytes()); + } + } + fn flags(&self) -> u32 { + 0x000001 // data-offset-present + | 0x000100 // sample-duration-present + | 0x000200 // sample-size-present + | 0x000400 // sample-flags-present + | 0x000800 // sample-composition-time-offsets-present } } @@ -570,3 +591,11 @@ impl WriteBox for TrackExtends { buf.extend(self.default_sample_flags.to_be_bytes()); } } + +pub struct MediaData<'a>(pub &'a [u8]); +impl WriteBox for MediaData<'_> { + const BOXTYPE: [u8; 4] = *b"mdat"; + fn write(&self, buf: &mut Vec<u8>) { + buf.extend(self.0); + } +} diff --git a/remuxer/mp4/src/lib.rs b/remuxer/mp4/src/lib.rs index 7af8417..2098e1b 100644 --- a/remuxer/mp4/src/lib.rs +++ b/remuxer/mp4/src/lib.rs @@ -12,6 +12,9 @@ impl<'a> BoxW<'a> { pub fn new(buffer: &'a mut Vec<u8>) -> Self { Self(buffer) } + pub fn buffer_mut(&mut self) -> &mut Vec<u8> { + self.0 + } pub fn write<T: WriteBox>(&mut self, b: T) { let start = self.0.len(); self.0.extend(0u32.to_be_bytes()); |