mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-11-14 11:11:16 +00:00
6ec013b7b9
* Add trun box. * Adding Movie Extends Box and subboxes (mvex, mehd, trex). * Adding more support for parsing fragmented tracks. Add mp4sample example. * cleanup * Set default_sample_duration from moov.mvex.trex for getting fragmented samples. * fix trex box parsing/writing.
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
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 <track_id> <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(())
|
|
}
|