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-21 16:11:15 +11:00
parent 3236012cb0
commit 8b47da93c6
2 changed files with 5 additions and 9 deletions

View file

@ -932,15 +932,12 @@ impl Mp4TrackWriter {
}
pub(crate) fn update_edit_list(&mut self, offset: u64, duration: u64) -> Result<()> {
self.offset = offset ;
self.offset = offset;
self.duration = duration;
Ok(())
}
pub(crate) fn write_end<W: Write + Seek>(
&mut self,
writer: &mut W,
) -> Result<TrakBox> {
pub(crate) fn write_end<W: Write + Seek>(&mut self, writer: &mut W) -> Result<TrakBox> {
self.write_chunk(writer)?;
let max_sample_size = self.max_sample_size();

View file

@ -1,4 +1,5 @@
use byteorder::{BigEndian, WriteBytesExt};
use std::cmp;
use std::io::{Seek, SeekFrom, Write};
use crate::mp4box::*;
@ -20,7 +21,6 @@ pub struct Mp4Writer<W> {
mdat_pos: u64,
timescale: u32,
duration: u64,
offsets: Vec<u64>,
}
impl<W> Mp4Writer<W> {
@ -75,7 +75,6 @@ impl<W: Write + Seek> Mp4Writer<W> {
BoxHeader::new(BoxType::WideBox, HEADER_SIZE).write(&mut writer)?;
let tracks = Vec::new();
let offsets = Vec::new();
let timescale = config.timescale;
let duration = 0;
Ok(Self {
@ -84,7 +83,6 @@ impl<W: Write + Seek> Mp4Writer<W> {
mdat_pos,
timescale,
duration,
offsets,
})
}
@ -99,7 +97,8 @@ impl<W: Write + Seek> Mp4Writer<W> {
if let Some(track) = self.tracks.get_mut(track_index as usize) {
//convert duration to mvhd timescale
let duration = duration_us * self.timescale as u64 / 1_000_000;
track.update_edit_list(offset,duration)?
track.update_edit_list(offset, cmp::min(duration, self.duration))?
} else {
return Err(Error::TrakNotFound(track_index));
}