1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2024-12-22 03:56:28 +00:00

Writer: Set mvhd/tkhd/mdhd version to 1 if duration is greater than u32::MAX (#76)

This commit is contained in:
nemosupremo 2022-06-14 21:44:59 -07:00 committed by GitHub
parent cc9bf192fa
commit 00385bad0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -724,8 +724,14 @@ impl Mp4TrackWriter {
fn update_durations(&mut self, dur: u32, movie_timescale: u32) { fn update_durations(&mut self, dur: u32, movie_timescale: u32) {
self.trak.mdia.mdhd.duration += dur as u64; self.trak.mdia.mdhd.duration += dur as u64;
if self.trak.mdia.mdhd.duration > (u32::MAX as u64) {
self.trak.mdia.mdhd.version = 1
}
self.trak.tkhd.duration += self.trak.tkhd.duration +=
dur as u64 * movie_timescale as u64 / self.trak.mdia.mdhd.timescale as u64; dur as u64 * movie_timescale as u64 / self.trak.mdia.mdhd.timescale as u64;
if self.trak.tkhd.duration > (u32::MAX as u64) {
self.trak.tkhd.version = 1
}
} }
pub(crate) fn write_sample<W: Write + Seek>( pub(crate) fn write_sample<W: Write + Seek>(

View file

@ -135,6 +135,9 @@ impl<W: Write + Seek> Mp4Writer<W> {
moov.mvhd.timescale = self.timescale; moov.mvhd.timescale = self.timescale;
moov.mvhd.duration = self.duration; moov.mvhd.duration = self.duration;
if moov.mvhd.duration > (u32::MAX as u64) {
moov.mvhd.version = 1
}
moov.write_box(&mut self.writer)?; moov.write_box(&mut self.writer)?;
Ok(()) Ok(())
} }