forked from alfg/mp4-rust
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mp4sample.rs
50 lines (41 loc) · 1.33 KB
/
mp4sample.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::io::{self, BufReader};
use std::path::Path;
use mp4::{Result};
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
println!("Usage: mp4sample <filename>");
std::process::exit(1);
}
if let Err(err) = samples(&args[1]) {
let _ = writeln!(io::stderr(), "{}", err);
}
}
fn samples<P: AsRef<Path>>(filename: &P) -> Result<()> {
let f = File::open(filename)?;
let size = f.metadata()?.len();
let reader = BufReader::new(f);
let mut mp4 = mp4::Mp4Reader::read_header(reader, size)?;
for track_idx in 0..mp4.tracks().len() {
let track_id = track_idx as u32 + 1;
let sample_count = mp4.sample_count(track_id).unwrap();
for sample_idx in 0..sample_count {
let sample_id = sample_idx + 1;
let sample = mp4.read_sample(track_id, sample_id);
if let Some(ref samp) = sample.unwrap() {
println!("[{}] start_time={} duration={} rendering_offset={} size={} is_sync={}",
sample_id,
samp.start_time,
samp.duration,
samp.rendering_offset,
samp.bytes.len(),
samp.is_sync,
);
}
}
}
Ok(())
}