Skip to content

Commit

Permalink
add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
alastor0325 committed Jan 31, 2025
1 parent 2ebf687 commit 0cf6c85
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Binary file added mp4parse/tests/h264_white_frame_sar_16_9.mp4
Binary file not shown.
27 changes: 27 additions & 0 deletions mp4parse/tests/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ static AUDIO_AMRWB_3GP: &str = "tests/amr_wb_1f.3gp";
// "ffmpeg -i [input file] -f mp4 -c:v mpeg4 -vf scale=176x144 -frames:v 1 -an output.mp4"
static VIDEO_MP4V_MP4: &str = "tests/bbb_sunflower_QCIF_30fps_mp4v_noaudio_1f.mp4";

// The 1 frame h264 mp4 file with pasp box generated by ffmpeg with command
// ffmpeg -f lavfi -i color=c=white:s=640x480 -c:v libx264 -frames:v 1 -pix_fmt yuv420p -vf "setsar=16/9" h264_white_frame_sar_16_9.mp4
static VIDEO_H264_PASP_MP4: &str = "tests/h264_white_frame_sar_16_9.mp4";

// Adapted from https://github.com/GuillaumeGomez/audio-video-metadata/blob/9dff40f565af71d5502e03a2e78ae63df95cfd40/src/metadata.rs#L53
#[test]
fn public_api() {
Expand Down Expand Up @@ -1468,6 +1472,29 @@ fn public_video_hevc() {
}
}


#[test]
fn public_parse_pasp_h264() {
let mut fd = File::open(VIDEO_H264_PASP_MP4).expect("Unknown file");
let mut buf = Vec::new();
fd.read_to_end(&mut buf).expect("File error");

let mut c = Cursor::new(&buf);
let context = mp4::read_mp4(&mut c).expect("read_mp4 failed");
for track in context.tracks {
let stsd = track.stsd.expect("expected an stsd");
let v = match stsd.descriptions.first().expect("expected a SampleEntry") {
mp4::SampleEntry::Video(ref v) => v,
_ => panic!("expected a VideoSampleEntry"),
};
assert_eq!(v.codec_type, mp4::CodecType::H264);
assert_eq!(v.width, 640);
assert_eq!(v.height, 480);
assert!(v.pixel_aspect_ratio.is_some(), "pixel_aspect_ratio should exist");
assert_eq!(v.pixel_aspect_ratio.unwrap() as f32, 16.0 / 9.0, "pixel_aspect_ratio should be 16/9");
}
}

#[test]
#[cfg(feature = "3gpp")]
fn public_audio_amrnb() {
Expand Down

0 comments on commit 0cf6c85

Please sign in to comment.