Skip to content

Commit 6cd4f72

Browse files
authored
Mp4Reader and update README example (#21)
* Make ftyp and moov on Mp4Reader public. Also update README.md with working example. * update readme
1 parent 4f417f8 commit 6cd4f72

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,47 @@ ISO/IEC 14496-12 - ISO Base Media File Format (QuickTime, MPEG-4, etc)
1010

1111
#### Example
1212
```rust
13-
use mp4;
13+
use std::fs::File;
14+
use std::io::{BufReader};
15+
use mp4::{Result};
1416

15-
fn main() {
17+
fn main() -> Result<()> {
1618
let f = File::open("example.mp4").unwrap();
1719
let size = f.metadata()?.len();
1820
let reader = BufReader::new(f);
1921

20-
let mut mp4 = Mp4Reader::new(reader);
21-
mp4.read(size)?;
22+
let mp4 = mp4::Mp4Reader::read_header(reader, size)?;
2223

24+
// Print boxes.
25+
println!("major brand: {}", mp4.ftyp.major_brand);
26+
println!("timescale: {}", mp4.moov.mvhd.timescale);
27+
28+
// Use available methods.
2329
println!("size: {}", mp4.size());
24-
println!("brands: {:?} {:?}\n", mp4.ftyp.major_brand, mp4.ftyp.compatible_brands);
30+
31+
let mut compatible_brands = String::new();
32+
for brand in mp4.compatible_brands().iter() {
33+
compatible_brands.push_str(&brand.to_string());
34+
compatible_brands.push_str(",");
35+
}
36+
println!("compatible brands: {}", compatible_brands);
37+
println!("duration: {:?}", mp4.duration());
38+
39+
// Track info.
40+
for track in mp4.tracks().iter() {
41+
println!(
42+
"track: #{}({}) {} : {}",
43+
track.track_id(),
44+
track.language(),
45+
track.track_type()?,
46+
track.box_type()?,
47+
);
48+
}
49+
Ok(())
2550
}
2651
```
2752

28-
See [examples/](examples/) for a full example.
53+
See [examples/](examples/) for more examples.
2954

3055
#### Documentation
3156
* https://docs.rs/mp4/

src/reader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::*;
77
#[derive(Debug)]
88
pub struct Mp4Reader<R> {
99
reader: R,
10-
ftyp: FtypBox,
11-
moov: MoovBox,
10+
pub ftyp: FtypBox,
11+
pub moov: MoovBox,
1212

1313
tracks: Vec<Mp4Track>,
1414
size: u64,

0 commit comments

Comments
 (0)