diff --git a/examples/mp4copy.rs b/examples/mp4copy.rs index aa55fb3..c5a6c4d 100644 --- a/examples/mp4copy.rs +++ b/examples/mp4copy.rs @@ -70,8 +70,8 @@ fn copy>(src_filename: &P, dst_filename: &P) -> Result<()> { let track_id = track_idx as u32 + 1; let sample_count = mp4_reader.sample_count(track_id)?; - for six in 0..sample_count { - let sample_id = six + 1; + for sample_idx in 0..sample_count { + let sample_id = sample_idx + 1; let sample = mp4_reader.read_sample(track_id, sample_id)?.unwrap(); mp4_writer.write_sample(track_id, &sample)?; // println!("copy {}:({})", sample_id, sample); diff --git a/examples/mp4info.rs b/examples/mp4info.rs index 62ca2d0..f3ef4bd 100644 --- a/examples/mp4info.rs +++ b/examples/mp4info.rs @@ -35,11 +35,7 @@ fn info>(filename: &P) -> Result<()> { compatible_brands.push_str(","); } println!(" compatible_brands: {}", compatible_brands); - println!( - "Duration: {}, timescale: {}", - mp4.duration(), - mp4.timescale() - ); + println!("Duration: {:?}", mp4.duration()); for track in mp4.tracks().iter() { let media_info = match track.track_type()? { diff --git a/src/reader.rs b/src/reader.rs index fbb9191..bf1f7aa 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1,4 +1,5 @@ use std::io::{Read, Seek, SeekFrom}; +use std::time::Duration; use crate::mp4box::*; use crate::*; @@ -95,8 +96,8 @@ impl Mp4Reader { &self.ftyp.compatible_brands } - pub fn duration(&self) -> u64 { - self.moov.mvhd.duration + pub fn duration(&self) -> Duration { + Duration::from_millis(self.moov.mvhd.duration * 1000 / self.moov.mvhd.timescale as u64) } pub fn timescale(&self) -> u32 { diff --git a/tests/lib.rs b/tests/lib.rs index 9c34180..1cc8a48 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,6 +1,7 @@ use mp4::{AudioObjectType, AvcProfile, ChannelConfig, MediaType, SampleFreqIndex, TrackType}; use std::fs::File; use std::io::BufReader; +use std::time::Duration; #[test] fn test_read_mp4() { @@ -29,7 +30,7 @@ fn test_read_mp4() { assert_eq!(t, true); } - assert_eq!(mp4.duration(), 62); + assert_eq!(mp4.duration(), Duration::from_millis(62)); assert_eq!(mp4.timescale(), 1000); assert_eq!(mp4.tracks().len(), 2);