diff --git a/Cargo.toml b/Cargo.toml index 140d83c..fd93474 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,5 @@ version = "0.1.0" authors = ["Alf "] edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] byteorder = "1" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c0309cd --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/README.md b/README.md index 5ac5a5b..317de63 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/examples/mp4info.rs b/examples/mp4info.rs new file mode 100644 index 0000000..ed070bc --- /dev/null +++ b/examples/mp4info.rs @@ -0,0 +1,24 @@ +extern crate mp4; + +use std::env; +use std::fs::File; + +fn main() { + let args: Vec = 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 "); + } + } + +} \ No newline at end of file diff --git a/src/main.rs b/src/lib.rs similarity index 95% rename from src/main.rs rename to src/lib.rs index f651204..fce2d11 100644 --- a/src/main.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ pub enum Error { pub type Result = std::result::Result; #[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 { // 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 { @@ -233,7 +226,6 @@ fn parse_mvhd_box(f: &mut BufReader, _offset: u64, size: u32) -> Result().unwrap(); let rate = f.read_u32::().unwrap(); - Ok(MvhdBox{ version, flags,