diff --git a/crates/ec-mp4/tests/mp4.rs b/crates/ec-mp4/tests/mp4.rs index 2a693260..ee395ba5 100644 --- a/crates/ec-mp4/tests/mp4.rs +++ b/crates/ec-mp4/tests/mp4.rs @@ -62,6 +62,27 @@ fn probe_field(path: &Path, entries: &str) -> Vec { .collect() } +/// Streams ffprobe reports that are cover art rather than a video track: a +/// still picture in a `trak`, which this crate deliberately does not list (a +/// player that shows an album cover as a video stream is the bug). +fn attached_pictures(path: &Path) -> Vec { + probe_field(path, "stream_disposition=attached_pic") + .iter() + .map(|v| v.trim() == "1") + .collect() +} + +/// `fields` with the cover-art streams dropped, so the oracle lists what this +/// crate claims to list. +fn without_cover_art(fields: Vec, cover: &[bool]) -> Vec { + fields + .into_iter() + .enumerate() + .filter(|(i, _)| !cover.get(*i).copied().unwrap_or(false)) + .map(|(_, f)| f) + .collect() +} + /// The fields a remux must not change. fn probe(path: &Path) -> String { probe_field( @@ -169,10 +190,11 @@ fn every_fixture_demuxes_into_the_streams_ffprobe_reports() { let mut table = Vec::new(); for path in &files { let demuxer = open(path); - let names = probe_field(path, "stream=codec_name"); - let widths = probe_field(path, "stream=width"); - let rates = probe_field(path, "stream=r_frame_rate"); - let avg_rates = probe_field(path, "stream=avg_frame_rate"); + let cover = attached_pictures(path); + let names = without_cover_art(probe_field(path, "stream=codec_name"), &cover); + let widths = without_cover_art(probe_field(path, "stream=width"), &cover); + let rates = without_cover_art(probe_field(path, "stream=r_frame_rate"), &cover); + let avg_rates = without_cover_art(probe_field(path, "stream=avg_frame_rate"), &cover); assert_eq!( demuxer.streams().len(), names.len(), @@ -240,6 +262,12 @@ fn every_fixture_demuxes_into_the_streams_ffprobe_reports() { fn every_fixture_remuxes_into_a_file_ffprobe_and_ffmpeg_agree_with() { let mut table = Vec::new(); for src in &mp4_fixtures() { + // Cover art is read (as no stream at all) but not written: this crate + // carries no `covr`/attached-picture writer, so a remux of one would + // field-compare against a stream that was never claimed. + if attached_pictures(src).iter().any(|&c| c) { + continue; + } let dst = work().join(format!( "remux-{}", src.file_name().unwrap().to_string_lossy() diff --git a/scripts/gen-fixtures.sh b/scripts/gen-fixtures.sh index 85665ef7..64ce90d9 100755 --- a/scripts/gen-fixtures.sh +++ b/scripts/gen-fixtures.sh @@ -110,6 +110,49 @@ for spec in "${AUDIO_CODECS[@]}"; do done done +# ------------------------------------------------- probe/ALAC extras -------- +# 24-bit ALAC: the only path where the low bytes of a sample ride uncompressed +# beside the residuals, which 16-bit fixtures never exercise. +for lspec in "stereo|2" "5.1|6"; do + IFS='|' read -r lname nch <<<"$lspec" + build_audio_in "$nch" 48000 + gen "$FIXTURES/audio/alac24-mp4-${lname}-48000.m4a" \ + "${AIN[@]}" "${AMAP[@]}" -c:a alac -sample_fmt s32p -ar 48000 +done + +# Matroska-carried audio: what the probe hands to the Matroska reader rather +# than parsing itself. One per codec family that has a Matroska mapping. +for spec in "aac|-c:a aac -b:a 160k" "flac|-c:a flac" "opus|-c:a libopus -b:a 160k"; do + IFS='|' read -r cname cargs <<<"$spec" + read -r -a CARGS <<<"$cargs" + build_audio_in 2 48000 + gen "$FIXTURES/audio/${cname}-mka-stereo-48000.mka" \ + "${AIN[@]}" "${AMAP[@]}" "${CARGS[@]}" -ar 48000 +done +# A film-shaped Matroska: picture and sound in one file, which is how a probe +# meets one in the real library. +build_audio_in 2 48000 +gen "$FIXTURES/audio/av-h264-aac-stereo-48000.mkv" \ + "${AIN[@]}" -f lavfi -i "testsrc2=size=320x240:rate=24:duration=$DUR_A" \ + "${AMAP[@]}" -map 2:v -c:v libx264 -preset ultrafast -c:a aac -b:a 160k + +# Cover art: an mjpeg "video" stream that is a still picture, in the two +# containers that carry one. A probe that lists it as a video track is broken. +if [ -s "$FIXTURES/stills/baseline-420.jpg" ]; then + build_audio_in 2 44100 + gen "$FIXTURES/audio/cover-mp3-stereo-44100.mp3" \ + "${AIN[@]}" -i "$FIXTURES/stills/baseline-420.jpg" \ + "${AMAP[@]}" -map 2:v -c:a libmp3lame -b:a 192k -c:v copy \ + -id3v2_version 3 -metadata title="A Tone" -metadata artist="edith_codecs" \ + -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" \ + -disposition:v attached_pic + gen "$FIXTURES/audio/cover-mp4-stereo-44100.m4a" \ + "${AIN[@]}" -i "$FIXTURES/stills/baseline-420.jpg" \ + "${AMAP[@]}" -map 2:v -c:a aac -b:a 160k -c:v copy \ + -metadata title="A Tone" -metadata artist="edith_codecs" \ + -disposition:v attached_pic +fi + # ---------------------------------------------------------------- video ----- # name|encoder|extra args|pix_fmts (comma-separated) VIDEO_CODECS=(