mirror of
https://github.com/alfg/mp4-rust.git
synced 2025-03-30 08:45:26 +00:00
Mp4Reader and update README example (#21)
* Make ftyp and moov on Mp4Reader public. Also update README.md with working example. * update readme
This commit is contained in:
parent
4f417f885d
commit
6cd4f72d28
2 changed files with 33 additions and 8 deletions
37
README.md
37
README.md
|
@ -10,22 +10,47 @@ ISO/IEC 14496-12 - ISO Base Media File Format (QuickTime, MPEG-4, etc)
|
|||
|
||||
#### Example
|
||||
```rust
|
||||
use mp4;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use mp4::{Result};
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<()> {
|
||||
let f = File::open("example.mp4").unwrap();
|
||||
let size = f.metadata()?.len();
|
||||
let reader = BufReader::new(f);
|
||||
|
||||
let mut mp4 = Mp4Reader::new(reader);
|
||||
mp4.read(size)?;
|
||||
let mp4 = mp4::Mp4Reader::read_header(reader, size)?;
|
||||
|
||||
// Print boxes.
|
||||
println!("major brand: {}", mp4.ftyp.major_brand);
|
||||
println!("timescale: {}", mp4.moov.mvhd.timescale);
|
||||
|
||||
// Use available methods.
|
||||
println!("size: {}", mp4.size());
|
||||
println!("brands: {:?} {:?}\n", mp4.ftyp.major_brand, mp4.ftyp.compatible_brands);
|
||||
|
||||
let mut compatible_brands = String::new();
|
||||
for brand in mp4.compatible_brands().iter() {
|
||||
compatible_brands.push_str(&brand.to_string());
|
||||
compatible_brands.push_str(",");
|
||||
}
|
||||
println!("compatible brands: {}", compatible_brands);
|
||||
println!("duration: {:?}", mp4.duration());
|
||||
|
||||
// Track info.
|
||||
for track in mp4.tracks().iter() {
|
||||
println!(
|
||||
"track: #{}({}) {} : {}",
|
||||
track.track_id(),
|
||||
track.language(),
|
||||
track.track_type()?,
|
||||
track.box_type()?,
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
See [examples/](examples/) for a full example.
|
||||
See [examples/](examples/) for more examples.
|
||||
|
||||
#### Documentation
|
||||
* https://docs.rs/mp4/
|
||||
|
|
|
@ -7,8 +7,8 @@ use crate::*;
|
|||
#[derive(Debug)]
|
||||
pub struct Mp4Reader<R> {
|
||||
reader: R,
|
||||
ftyp: FtypBox,
|
||||
moov: MoovBox,
|
||||
pub ftyp: FtypBox,
|
||||
pub moov: MoovBox,
|
||||
|
||||
tracks: Vec<Mp4Track>,
|
||||
size: u64,
|
||||
|
|
Loading…
Reference in a new issue