mirror of
https://github.com/alfg/mp4-rust.git
synced 2025-01-03 00:48:40 +00:00
add top level public function mp4::read_mp4 for using the Mp4Reader with a file path. Added simple example.
This commit is contained in:
parent
71f0f78ae6
commit
b016ac3b47
2 changed files with 37 additions and 0 deletions
27
examples/simple.rs
Normal file
27
examples/simple.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
use mp4;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() < 2 {
|
||||
println!("Usage: mp4dump <filename>");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let filename = &args[1];
|
||||
let f = File::open(filename).unwrap();
|
||||
let mp4 = mp4::read_mp4(f).unwrap();
|
||||
|
||||
println!("Major Brand: {}", mp4.major_brand());
|
||||
|
||||
for track in mp4.tracks().iter() {
|
||||
println!("Track: #{}({}) {} {}",
|
||||
track.track_id(),
|
||||
track.language(),
|
||||
track.track_type().unwrap(),
|
||||
track.box_type().unwrap(),
|
||||
);
|
||||
}
|
||||
}
|
10
src/lib.rs
10
src/lib.rs
|
@ -1,3 +1,6 @@
|
|||
use std::io::{BufReader};
|
||||
use std::fs::File;
|
||||
|
||||
mod error;
|
||||
pub use error::Error;
|
||||
|
||||
|
@ -17,3 +20,10 @@ pub use reader::Mp4Reader;
|
|||
|
||||
mod writer;
|
||||
pub use writer::{Mp4Config, Mp4Writer};
|
||||
|
||||
pub fn read_mp4(f: File) -> Result<Mp4Reader<BufReader<File>>> {
|
||||
let size = f.metadata()?.len();
|
||||
let reader = BufReader::new(f);
|
||||
let mp4 = reader::Mp4Reader::read_header(reader, size)?;
|
||||
Ok(mp4)
|
||||
}
|
Loading…
Reference in a new issue