diff --git a/mp4parse/tests/h264_white_frame_sar_16_9.mp4 b/mp4parse/tests/h264_white_frame_sar_16_9.mp4 new file mode 100644 index 00000000..e92c65f8 Binary files /dev/null and b/mp4parse/tests/h264_white_frame_sar_16_9.mp4 differ diff --git a/mp4parse/tests/public.rs b/mp4parse/tests/public.rs index 36f62f47..937b0ddc 100644 --- a/mp4parse/tests/public.rs +++ b/mp4parse/tests/public.rs @@ -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() { @@ -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() {