diff --git a/src/muxer/hls/mp4/atoms.rs b/src/muxer/hls/mp4/atoms.rs index fa35ba1..168c190 100644 --- a/src/muxer/hls/mp4/atoms.rs +++ b/src/muxer/hls/mp4/atoms.rs @@ -1057,12 +1057,14 @@ impl MP4Atom for MFHD { struct TRAF { tfhd: TFHD, + tfdt: TFDT, trun: TRUN, } impl MP4Atom for TRAF { fn marshall(&self) -> Vec { let mut content = self.tfhd.marshall(); + content.append(&mut self.tfdt.marshall()); content.append(&mut self.trun.marshall()); make_box(content, *b"traf") } @@ -1097,6 +1099,36 @@ impl Default for TFHD { } } +struct TFDT { + version: u8, + flags: u32, + start_time: u64, +} + +impl MP4Atom for TFDT { + fn marshall(&self) -> Vec { + let mut content = Vec::new(); + content.push(self.version); + content.extend_from_slice(&self.flags.to_be_bytes()[1..]); + if self.version == 1 { + content.extend_from_slice(&self.start_time.to_be_bytes()); + } else { + content.extend_from_slice(&(self.start_time as u32).to_be_bytes()); + } + make_box(content, *b"tfdt") + } +} + +impl Default for TFDT { + fn default() -> Self { + TFDT { + version: 0, + flags: 0, + start_time: 0, + } + } +} + struct TRUN { version: u8, flags: u32, @@ -1160,7 +1192,7 @@ impl MP4Atom for MDAT { } pub fn new_moof(v_samples: &Vec, default_dur_v: u32, a_samples: &Vec, default_dur_a: u32, mdat_v_offset: usize, mdat_a_offset: usize, moof_idx: usize) -> MOOF { - let mdat_data_start = 120 + v_samples.len() * 8 + a_samples.len() * 8 + 8; + let mdat_data_start = 152 + v_samples.len() * 8 + a_samples.len() * 8 + 8; MOOF { mfhd: MFHD { seq_num: moof_idx as u32, ..Default::default() }, trafs: [ TRAF { @@ -1170,6 +1202,10 @@ pub fn new_moof(v_samples: &Vec, default_dur_v: u32, a_samples: ..Default::default() }, trun: new_trun(v_samples, mdat_v_offset + mdat_data_start), + tfdt: TFDT { + start_time: default_dur_v as u64 * (v_samples.len() * (moof_idx - 1)) as u64, + ..Default::default() + }, }, TRAF{ tfhd: TFHD { track_id: 2, @@ -1177,6 +1213,10 @@ pub fn new_moof(v_samples: &Vec, default_dur_v: u32, a_samples: ..Default::default() }, trun: new_trun(a_samples, mdat_a_offset + mdat_data_start), + tfdt: TFDT { + start_time: default_dur_a as u64 * (a_samples.len() * (moof_idx - 1)) as u64, + ..Default::default() + }, } ], } } diff --git a/src/muxer/hls/mp4/mp4muxer.rs b/src/muxer/hls/mp4/mp4muxer.rs index 6a52436..ca7b3ba 100644 --- a/src/muxer/hls/mp4/mp4muxer.rs +++ b/src/muxer/hls/mp4/mp4muxer.rs @@ -54,13 +54,14 @@ impl mp4::MP4Muxer { return } } + i += 1; } }); thread::spawn(move || { loop { match a.recv() { - Ok(x) => {a_queue.push(x.packet_data, 0x01010000);}, + Ok(x) => {a_queue.push(x.packet_data, 0x02000000);}, Err(_) => { util::thread_freeze(err_in2, Box::new(util::MuxerError::AudioEOF)); return diff --git a/src/muxer/hls/segments.rs b/src/muxer/hls/segments.rs index 402ef16..233db87 100644 --- a/src/muxer/hls/segments.rs +++ b/src/muxer/hls/segments.rs @@ -18,7 +18,7 @@ pub struct Segment { impl Segment { pub fn dump(&self) { let mdat = self.new_mdat(); - let moof = atoms::new_moof(&self.segment_video, self.sample_duration_v, &self.segment_audio, self.sample_duration_a, 0, mdat.v_samples.len(), self.idx); + let moof = atoms::new_moof(&self.segment_video, self.sample_duration_v, &self.segment_audio, self.sample_duration_a, 0, mdat.v_samples.len(), self.idx + 1); let mut segment_bytes = moof.marshall(); segment_bytes.append(&mut mdat.marshall());