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

Update examples (#16)

* Add ReadBox trait

* Add boxtype macro

* Remove offset in BoxHeader

* Fix parsing error when box has largesize

* Remove duplicated codes reading version and flags

* Update examples

* Fix test failure

Co-authored-by: Byungwan Jun <unipro.kr@gmail.com>
This commit is contained in:
Ian Jun 2020-08-06 15:00:53 +09:00 committed by GitHub
parent 3104a2d95b
commit b5367032a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 10 deletions

View file

@ -70,8 +70,8 @@ fn copy<P: AsRef<Path>>(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);

View file

@ -35,11 +35,7 @@ fn info<P: AsRef<Path>>(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()? {

View file

@ -1,4 +1,5 @@
use std::io::{Read, Seek, SeekFrom};
use std::time::Duration;
use crate::mp4box::*;
use crate::*;
@ -95,8 +96,8 @@ impl<R: Read + Seek> Mp4Reader<R> {
&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 {

View file

@ -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);