From a4fd45b3e86a113b604914f7f5a9df6b0e9f07c9 Mon Sep 17 00:00:00 2001 From: Alfred Gutierrez Date: Sat, 25 Jul 2020 20:07:39 -0700 Subject: [PATCH] Add basic integration test (#10) * Add basic integration test and update README and example. Add sample minimal.mp4 file for tests. * Add .travis.yml file. * Update readme. --- .gitignore | 1 + .travis.yml | 9 +++++++++ README.md | 33 +++++++++++++++++++++++++++++++++ examples/mp4info.rs | 16 +++++++--------- tests/lib.rs | 38 ++++++++++++++++++++++++++++++++++++++ tests/samples/minimal.mp4 | Bin 0 -> 2591 bytes 6 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 .travis.yml create mode 100644 tests/lib.rs create mode 100644 tests/samples/minimal.mp4 diff --git a/.gitignore b/.gitignore index acbda4d..e1c3920 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.mp4 .idea/ .vscode/ +!tests/samples/*.mp4 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5fea970 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: rust +rust: + - stable + - beta + - nightly +jobs: + allow_failures: + - rust: nightly + fast_finish: true \ No newline at end of file diff --git a/README.md b/README.md index cc21ad1..1b7e1e1 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,29 @@ ISO/IEC 14496-12 - ISO Base Media File Format (QuickTime, MPEG-4, etc) [![Crates.io](https://img.shields.io/crates/v/mp4)](https://crates.io/crates/mp4) [![Crates.io](https://img.shields.io/crates/d/mp4)](https://crates.io/crates/mp4) +[![Build Status](https://travis-ci.org/alfg/mp4rs.svg?branch=master)](https://travis-ci.org/alfg/mp4rs) +![Rust](https://github.com/alfg/mp4rs/workflows/Rust/badge.svg) + +#### Example +```rust +use mp4; + +fn main() { + let f = File::open("example.mp4").unwrap(); + + let bmff = mp4::read_mp4(f).unwrap(); + + println!("file size: {}", bmff.size); + println!("brands: {:?} {:?}\n", + bmff.ftyp.major_brand, bmff.ftyp.compatible_brands + ); +} +``` + +See [examples/](examples/) for a full example. + +#### Documentation +* https://docs.rs/mp4/ ## Development @@ -22,6 +45,16 @@ cargo build cargo run --example mp4info ``` +#### Run Tests +``` +cargo test +``` + +With print statement output. +``` +cargo test -- --nocapture +``` + ## Resources Thanks to the following resources used when learning Rust: * https://github.com/mozilla/mp4parse-rust diff --git a/examples/mp4info.rs b/examples/mp4info.rs index 65f3cda..dc6b906 100644 --- a/examples/mp4info.rs +++ b/examples/mp4info.rs @@ -1,6 +1,4 @@ -extern crate mp4; - -use mp4::TrackType; +use mp4; use std::env; use std::fs::File; @@ -71,7 +69,7 @@ fn main() { " duration: {:?} (ms)", get_duration_ms(mdhd.duration, mdhd.timescale) ); - if get_handler_type(hdlr.handler_type.value.as_ref()) == TrackType::Video { + if get_handler_type(hdlr.handler_type.value.as_ref()) == mp4::TrackType::Video { if let Some(ref s) = stts { println!( " frame rate: (computed): {:?}", @@ -88,12 +86,12 @@ fn main() { } } -fn get_handler_type(handler: &str) -> TrackType { - let mut typ: TrackType = TrackType::Unknown; +fn get_handler_type(handler: &str) -> mp4::TrackType { + let mut typ: mp4::TrackType = mp4::TrackType::Unknown; match handler { - "vide" => typ = TrackType::Video, - "soun" => typ = TrackType::Audio, - "meta" => typ = TrackType::Unknown, + "vide" => typ = mp4::TrackType::Video, + "soun" => typ = mp4::TrackType::Audio, + "meta" => typ = mp4::TrackType::Unknown, _ => (), } return typ; diff --git a/tests/lib.rs b/tests/lib.rs new file mode 100644 index 0000000..c229338 --- /dev/null +++ b/tests/lib.rs @@ -0,0 +1,38 @@ +use mp4; +use std::fs::File; + + +#[test] +fn test_read_mp4() { + let filename = "tests/samples/minimal.mp4"; + let f = File::open(filename).unwrap(); + let bmff = mp4::read_mp4(f).unwrap(); + + assert_eq!(2591, bmff.size); + + // ftyp. + println!("{:?}", bmff.ftyp.compatible_brands); + assert_eq!(4, bmff.ftyp.compatible_brands.len()); + + // Check compatible_brands. + let brands = vec![ + String::from("isom"), + String::from("iso2"), + String::from("avc1"), + String::from("mp41") + ]; + + for b in brands { + let t = bmff.ftyp.compatible_brands.iter().any(|x| x.to_string() == b); + assert_eq!(t, true); + } + + // moov. + let moov = bmff.moov.unwrap(); + assert_eq!(moov.mvhd.version, 0); + assert_eq!(moov.mvhd.creation_time, 0); + assert_eq!(moov.mvhd.duration, 62); + assert_eq!(moov.mvhd.timescale, 1000); + assert_eq!(moov.traks.len(), 2); + +} \ No newline at end of file diff --git a/tests/samples/minimal.mp4 b/tests/samples/minimal.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9fe1e672241766bccf54731219bf03b81ff223ef GIT binary patch literal 2591 zcma)6eNYr-7=MogJvBv3gBYqcaK;jj-QzfjT0A8tn$&UnfW{h^z1=--z1`bocY!<8 zJR(2)oTg+d6{$Z`ODg*C69+T3i5k;B)I=LKO3eY(DJ6~TdH3$%GIe@p-}iZ*-}CW) zJkPrbA;N2fR8d!Cgpv^EFdS?hN6D&_LMXXkR+Kt~kR;dnc;E?SJq1b$vLO5o(Z3Xc zuhQK^p4XDBu#a>@WBp)!%J7?O0yaqTY?B9(xDdBoM|T5m!BZa$gt7(R(1B+Pl5Utt zbf?k0W-iMsGB2`VBV_*SvpWDzLXUr8M&|l>NsHw`bs{gsWy~u;SIXG{FA3Pka-S>) zydaFPlg*@w+s@{rwoG0Vun#6|zo}M}h?sm?H#`!^O}e4S3xa)?;-Ue^l$bLLxZ&94 zAmV}PKORvyVNQ=kK%*dQsf9e^;YDC1VL21F%V7a1h7a=bV4EK`CH2PafN@F`!+t4UkZ05l`odfU{7Ygn zm|5^b<|>%S$pqsHLhd0EOE>6?zv{$w5RD6Q3cJNMltMzm!4B6{Bx`(t1O|y>&a! zn!)DP%wX%h1unajv{NL0M>ek}z(Y=b6S{n{e_quuVfac-E4=uE(>e`NchfZH2`L%lvPD+PblIF#7 zl{trq!&yDOL5Ispkm#^NYzKMdcH+K>LIsq1SpqDkM}r1fei9 z8c$Pp5`thNWHBi449-YF1f#KmYJsL)1n1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