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

Add simple test for parsing mp4 with multiple tracks #8

Merged
merged 1 commit into from
Sep 30, 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
9 changes: 4 additions & 5 deletions tests/mp4box_comparison.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![allow(clippy::unwrap_used)]

use std::path::Path;
mod paths;

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

fn assert_snapshot(snapshot_path: &Path, contents: &[u8]) {
// if file doesn't exist, create it
Expand Down Expand Up @@ -53,7 +52,7 @@ fn compare_video_snapshot_with_mp4box_output(video_path: &Path) {
assert!(
std::process::Command::new("node")
.arg(
Path::new(TEST_BASE_PATH)
Path::new(paths::TEST_BASE_PATH)
.join("mp4box_parse.mjs")
.to_str()
.unwrap()
Expand Down Expand Up @@ -97,7 +96,7 @@ fn compare_video_snapshot_with_mp4box_output(video_path: &Path) {
#[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 base_path = Path::new(paths::SAMPLE_BASE_PATH);
let bigbuckbunny_path = base_path.join("bigbuckbunny");

for entry in std::fs::read_dir(bigbuckbunny_path).unwrap() {
Expand Down
49 changes: 49 additions & 0 deletions tests/multitrack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
mod paths;

#[test]
fn multitrack_video_with_subtitles_and_sound() {
let mp4_with_subtitles_and_sound = std::path::Path::new(paths::SAMPLE_BASE_PATH)
.join("rerun404_avc_with_subtitles_and_sound.mp4");

let bytes = std::fs::read(mp4_with_subtitles_and_sound).unwrap();
let video = re_mp4::read(&bytes).unwrap();

assert_eq!(video.tracks().len(), 3);
assert_eq!(video.moov.mvhd.next_track_id, 4);

// Video track.
{
let track = video.tracks().get(&1).unwrap();
assert_eq!(track.kind, Some(re_mp4::TrackKind::Video));
assert_eq!(track.codec_string(&video), Some("avc1.640028".to_owned()));
assert_eq!(track.track_id, 1);
assert_eq!(track.width, 600);
assert_eq!(track.height, 600);
assert!(!track.samples.is_empty());
assert!(!track.data.is_empty());
}

// Audio track.
{
let track = video.tracks().get(&2).unwrap();
assert_eq!(track.kind, Some(re_mp4::TrackKind::Audio));
assert_eq!(track.codec_string(&video), None);
assert_eq!(track.track_id, 2);
assert_eq!(track.width, 0);
assert_eq!(track.height, 0);
assert!(!track.samples.is_empty());
assert!(!track.data.is_empty());
}

// Subtitle track.
{
let track = video.tracks().get(&3).unwrap();
assert_eq!(track.kind, Some(re_mp4::TrackKind::Subtitle));
assert_eq!(track.codec_string(&video), None);
assert_eq!(track.track_id, 3);
assert_eq!(track.width, 0);
assert_eq!(track.height, 0);
assert!(!track.samples.is_empty());
assert!(!track.data.is_empty());
}
}
4 changes: 4 additions & 0 deletions tests/paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[allow(dead_code)]

pub const TEST_BASE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests");
pub const SAMPLE_BASE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/samples");
3 changes: 3 additions & 0 deletions tests/samples/rerun404_avc_with_subtitles_and_sound.mp4
Git LFS file not shown
Loading