Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup generic mp4box parse comparision tests #7

Merged
merged 6 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* text=auto eol=lf
*.mp4 filter=lfs diff=lfs merge=lfs -text
Cargo.lock linguist-generated=false
16 changes: 9 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- "main"
pull_request:
types: [ opened, synchronize ]
types: [opened, synchronize]

name: Rust

Expand All @@ -18,6 +18,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
lfs: true # Needed for tests.

- uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -123,9 +125,9 @@ jobs:
name: Check Rust dependencies (cargo-deny)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
with:
rust-version: "1.76.0"
log-level: warn
command: check
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
with:
rust-version: "1.76.0"
log-level: warn
command: check
9 changes: 9 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Tests

Execution of tests requires [git-lfs](https://git-lfs.github.com/) to download sample data.
Ensure that all video samples are pushed as lfs files!

## mp4box comparison tests

These tests compare the output of `mp4box` against the output of this library.
In order to run these tests, you'll need to install `node` (and have `node` in your `PATH`).
22 changes: 0 additions & 22 deletions tests/cmp.mjs

This file was deleted.

51 changes: 43 additions & 8 deletions tests/lib.rs → tests/mp4box_comparison.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![allow(dead_code)] // TODO(#3): enable tests again
#![allow(clippy::unwrap_used)]

use std::path::Path;

const TEST_BASE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests");
const SAMPLE_BASE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/samples");

fn assert_snapshot(snapshot_path: &Path, contents: &[u8]) {
// if file doesn't exist, create it
// otherwise, compare the contents and report failure if they don't match
Expand Down Expand Up @@ -43,24 +45,41 @@ fn get_track_description(track: &re_mp4::TrakBox) -> Vec<u8> {
}
}

const BASE: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/samples");
fn assert_video_snapshot(file_path: &str) {
let base_path = Path::new(BASE);
let bytes = std::fs::read(base_path.join(file_path)).unwrap();
fn compare_video_snapshot_with_mp4box_output(video_path: &Path) {
let video_path_str = video_path.to_str().unwrap();
let base_path = video_path.parent().unwrap();

// Run mp4 box to parse a video file and dump the result to files.
assert!(
std::process::Command::new("node")
.arg(
Path::new(TEST_BASE_PATH)
.join("mp4box_parse.mjs")
.to_str()
.unwrap()
)
.arg(video_path_str)
.status()
.unwrap()
.success(),
"Failed to run mp4box."
);

let bytes = std::fs::read(base_path.join(video_path)).unwrap();
let video = re_mp4::read(&bytes).unwrap();

for (id, track) in video.tracks() {
if track.kind == Some(re_mp4::TrackKind::Video) {
assert_snapshot(
&base_path.join(format!("{file_path}.track_{id}.bin")),
&base_path.join(format!("{video_path_str}.track_{id}.bin")),
&track.data,
);
assert_snapshot(
&base_path.join(format!("{file_path}.track_{id}.segments")),
&base_path.join(format!("{video_path_str}.track_{id}.segments")),
format!(r#"{:#?}"#, track.samples).as_bytes(),
);
assert_snapshot(
&base_path.join(format!("{file_path}.track_{id}.json")),
&base_path.join(format!("{video_path_str}.track_{id}.json")),
format!(
r#"{{ "codec": {:?}, "width": {}, "height": {}, "num_samples": {}, "description": {:?} }}"#,
track.codec_string(&video).unwrap_or("unknown".to_owned()),
Expand All @@ -74,3 +93,19 @@ fn assert_video_snapshot(file_path: &str) {
}
}
}

#[test]
fn compare_video_snapshot_with_mp4box_output_bigbuckbunny() {
// List all mp4 files in the bigbuckbunny directory.
let base_path = Path::new(SAMPLE_BASE_PATH);
let bigbuckbunny_path = base_path.join("bigbuckbunny");

for entry in std::fs::read_dir(bigbuckbunny_path).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if path.is_file() && path.extension().map_or(false, |e| e == "mp4") {
println!("-- Comparing {path:?}");
compare_video_snapshot_with_mp4box_output(&path);
}
}
}
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/samples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.segments
*.json
*.bin
4 changes: 4 additions & 0 deletions tests/samples/bigbuckbunny/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Big Buck Bunny is licensed under the Creative Commons Attribution 3.0 license.

https://creativecommons.org/licenses/by/3.0/
https://peach.blender.org/about/
3 changes: 3 additions & 0 deletions tests/samples/bigbuckbunny/av1.mp4
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/samples/bigbuckbunny/avc.mp4
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/samples/bigbuckbunny/hevc.mp4
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/samples/bigbuckbunny/vp8.mp4
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/samples/bigbuckbunny/vp9.mp4
Git LFS file not shown
Loading