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

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.
This commit is contained in:
Alfred Gutierrez 2020-07-25 20:07:39 -07:00 committed by GitHub
parent 8dfe751516
commit a4fd45b3e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 9 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@
*.mp4
.idea/
.vscode/
!tests/samples/*.mp4

9
.travis.yml Normal file
View file

@ -0,0 +1,9 @@
language: rust
rust:
- stable
- beta
- nightly
jobs:
allow_failures:
- rust: nightly
fast_finish: true

View file

@ -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 <movie.mp4>
```
#### 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

View file

@ -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;

38
tests/lib.rs Normal file
View file

@ -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);
}

BIN
tests/samples/minimal.mp4 Normal file

Binary file not shown.