1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2024-11-13 18:51:02 +00:00

Change main.rs to lib.rs and create example mp4info project. Update readme and license.

This commit is contained in:
Alf 2020-01-12 19:33:26 -08:00
parent d4f69d82ee
commit efd7ac8981
5 changed files with 61 additions and 16 deletions

View file

@ -4,7 +4,5 @@ version = "0.1.0"
authors = ["Alf <alf.g.jr@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
byteorder = "1"

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Alfred Gutierrez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,8 +1,18 @@
# mp4.rs
MP4 Reader in Rust
#### Development
## Development
#### Requirements
* [Rust](https://www.rust-lang.org/)
#### Build
```
cargo build
cargo run
```
#### Run Examples
* `mp4info`
```
cargo run --example mp4info <movie.mp4>
```

24
examples/mp4info.rs Normal file
View file

@ -0,0 +1,24 @@
extern crate mp4;
use std::env;
use std::fs::File;
fn main() {
let args: Vec<String> = env::args().collect();
match args.len() {
2 => {
let filename = &args[1];
let f = File::open(filename).unwrap();
let bmff = mp4::read_mp4(f);
// Print results.
println!("{:?}", bmff.unwrap());
},
_ => {
println!("Usage: mp4info <filename>");
}
}
}

View file

@ -16,7 +16,7 @@ pub enum Error {
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Default)]
struct BMFF {
pub struct BMFF {
ftyp: FtypBox,
moov: MoovBox,
}
@ -99,19 +99,12 @@ impl fmt::Debug for FourCC {
}
}
fn main() -> std::io::Result<()> {
pub fn read_mp4(f: File) -> Result<BMFF> {
// Open file and read boxes.
let f = File::open("tears-of-steel-2s.mp4")?;
// let boxes = read_boxes(f);
let bmff = read_boxes(f);
let bmff = read_boxes(f).unwrap();
// Print results.
println!("{:?}", bmff.unwrap());
// Done.
println!("done");
Ok(())
Ok(bmff)
}
fn read_boxes(f: File) -> Result<BMFF> {
@ -233,7 +226,6 @@ fn parse_mvhd_box(f: &mut BufReader<File>, _offset: u64, size: u32) -> Result<Mv
let duration = f.read_u32::<byteorder::BigEndian>().unwrap();
let rate = f.read_u32::<byteorder::BigEndian>().unwrap();
Ok(MvhdBox{
version,
flags,