24-bit ALAC, Matroska-carried audio and cover art
Browse files at this commitabd41b68412aa45fa92f4cefe989f5004e5872f0Parent: 32195c9- test
- 24-bit ALAC, Matroska-carried audio and cover art
2 changed files +75 -4
- crates/ec-mp4/tests/mp4.rs +32 -4
- scripts/gen-fixtures.sh +43 -0
crates/ec-mp4/tests/mp4.rsmodified+32 -4
| @@ -62,6 +62,27 @@ fn probe_field(path: &Path, entries: &str) -> Vec<String> { | |||
| 62 | .collect() | 62 | .collect() |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | +/// Streams ffprobe reports that are cover art rather than a video track: a | ||
| 66 | +/// still picture in a `trak`, which this crate deliberately does not list (a | ||
| 67 | +/// player that shows an album cover as a video stream is the bug). | ||
| 68 | +fn attached_pictures(path: &Path) -> Vec<bool> { | ||
| 69 | + probe_field(path, "stream_disposition=attached_pic") | ||
| 70 | + .iter() | ||
| 71 | + .map(|v| v.trim() == "1") | ||
| 72 | + .collect() | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +/// `fields` with the cover-art streams dropped, so the oracle lists what this | ||
| 76 | +/// crate claims to list. | ||
| 77 | +fn without_cover_art(fields: Vec<String>, cover: &[bool]) -> Vec<String> { | ||
| 78 | + fields | ||
| 79 | + .into_iter() | ||
| 80 | + .enumerate() | ||
| 81 | + .filter(|(i, _)| !cover.get(*i).copied().unwrap_or(false)) | ||
| 82 | + .map(|(_, f)| f) | ||
| 83 | + .collect() | ||
| 84 | +} | ||
| 85 | + | ||
| 65 | /// The fields a remux must not change. | 86 | /// The fields a remux must not change. |
| 66 | fn probe(path: &Path) -> String { | 87 | fn probe(path: &Path) -> String { |
| 67 | probe_field( | 88 | probe_field( |
| @@ -169,10 +190,11 @@ fn every_fixture_demuxes_into_the_streams_ffprobe_reports() { | |||
| 169 | let mut table = Vec::new(); | 190 | let mut table = Vec::new(); |
| 170 | for path in &files { | 191 | for path in &files { |
| 171 | let demuxer = open(path); | 192 | let demuxer = open(path); |
| 172 | - let names = probe_field(path, "stream=codec_name"); | 193 | + let cover = attached_pictures(path); |
| 173 | - let widths = probe_field(path, "stream=width"); | 194 | + let names = without_cover_art(probe_field(path, "stream=codec_name"), &cover); |
| 174 | - let rates = probe_field(path, "stream=r_frame_rate"); | 195 | + let widths = without_cover_art(probe_field(path, "stream=width"), &cover); |
| 175 | - let avg_rates = probe_field(path, "stream=avg_frame_rate"); | 196 | + let rates = without_cover_art(probe_field(path, "stream=r_frame_rate"), &cover); |
| 197 | + let avg_rates = without_cover_art(probe_field(path, "stream=avg_frame_rate"), &cover); | ||
| 176 | assert_eq!( | 198 | assert_eq!( |
| 177 | demuxer.streams().len(), | 199 | demuxer.streams().len(), |
| 178 | names.len(), | 200 | names.len(), |
| @@ -240,6 +262,12 @@ fn every_fixture_demuxes_into_the_streams_ffprobe_reports() { | |||
| 240 | fn every_fixture_remuxes_into_a_file_ffprobe_and_ffmpeg_agree_with() { | 262 | fn every_fixture_remuxes_into_a_file_ffprobe_and_ffmpeg_agree_with() { |
| 241 | let mut table = Vec::new(); | 263 | let mut table = Vec::new(); |
| 242 | for src in &mp4_fixtures() { | 264 | for src in &mp4_fixtures() { |
| 265 | + // Cover art is read (as no stream at all) but not written: this crate | ||
| 266 | + // carries no `covr`/attached-picture writer, so a remux of one would | ||
| 267 | + // field-compare against a stream that was never claimed. | ||
| 268 | + if attached_pictures(src).iter().any(|&c| c) { | ||
| 269 | + continue; | ||
| 270 | + } | ||
| 243 | let dst = work().join(format!( | 271 | let dst = work().join(format!( |
| 244 | "remux-{}", | 272 | "remux-{}", |
| 245 | src.file_name().unwrap().to_string_lossy() | 273 | src.file_name().unwrap().to_string_lossy() |
scripts/gen-fixtures.shmodified+43 -0
| @@ -110,6 +110,49 @@ for spec in "${AUDIO_CODECS[@]}"; do | |||
| 110 | done | 110 | done |
| 111 | done | 111 | done |
| 112 | 112 | ||
| 113 | +# ------------------------------------------------- probe/ALAC extras -------- | ||
| 114 | +# 24-bit ALAC: the only path where the low bytes of a sample ride uncompressed | ||
| 115 | +# beside the residuals, which 16-bit fixtures never exercise. | ||
| 116 | +for lspec in "stereo|2" "5.1|6"; do | ||
| 117 | + IFS='|' read -r lname nch <<<"$lspec" | ||
| 118 | + build_audio_in "$nch" 48000 | ||
| 119 | + gen "$FIXTURES/audio/alac24-mp4-${lname}-48000.m4a" \ | ||
| 120 | + "${AIN[@]}" "${AMAP[@]}" -c:a alac -sample_fmt s32p -ar 48000 | ||
| 121 | +done | ||
| 122 | + | ||
| 123 | +# Matroska-carried audio: what the probe hands to the Matroska reader rather | ||
| 124 | +# than parsing itself. One per codec family that has a Matroska mapping. | ||
| 125 | +for spec in "aac|-c:a aac -b:a 160k" "flac|-c:a flac" "opus|-c:a libopus -b:a 160k"; do | ||
| 126 | + IFS='|' read -r cname cargs <<<"$spec" | ||
| 127 | + read -r -a CARGS <<<"$cargs" | ||
| 128 | + build_audio_in 2 48000 | ||
| 129 | + gen "$FIXTURES/audio/${cname}-mka-stereo-48000.mka" \ | ||
| 130 | + "${AIN[@]}" "${AMAP[@]}" "${CARGS[@]}" -ar 48000 | ||
| 131 | +done | ||
| 132 | +# A film-shaped Matroska: picture and sound in one file, which is how a probe | ||
| 133 | +# meets one in the real library. | ||
| 134 | +build_audio_in 2 48000 | ||
| 135 | +gen "$FIXTURES/audio/av-h264-aac-stereo-48000.mkv" \ | ||
| 136 | + "${AIN[@]}" -f lavfi -i "testsrc2=size=320x240:rate=24:duration=$DUR_A" \ | ||
| 137 | + "${AMAP[@]}" -map 2:v -c:v libx264 -preset ultrafast -c:a aac -b:a 160k | ||
| 138 | + | ||
| 139 | +# Cover art: an mjpeg "video" stream that is a still picture, in the two | ||
| 140 | +# containers that carry one. A probe that lists it as a video track is broken. | ||
| 141 | +if [ -s "$FIXTURES/stills/baseline-420.jpg" ]; then | ||
| 142 | + build_audio_in 2 44100 | ||
| 143 | + gen "$FIXTURES/audio/cover-mp3-stereo-44100.mp3" \ | ||
| 144 | + "${AIN[@]}" -i "$FIXTURES/stills/baseline-420.jpg" \ | ||
| 145 | + "${AMAP[@]}" -map 2:v -c:a libmp3lame -b:a 192k -c:v copy \ | ||
| 146 | + -id3v2_version 3 -metadata title="A Tone" -metadata artist="edith_codecs" \ | ||
| 147 | + -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" \ | ||
| 148 | + -disposition:v attached_pic | ||
| 149 | + gen "$FIXTURES/audio/cover-mp4-stereo-44100.m4a" \ | ||
| 150 | + "${AIN[@]}" -i "$FIXTURES/stills/baseline-420.jpg" \ | ||
| 151 | + "${AMAP[@]}" -map 2:v -c:a aac -b:a 160k -c:v copy \ | ||
| 152 | + -metadata title="A Tone" -metadata artist="edith_codecs" \ | ||
| 153 | + -disposition:v attached_pic | ||
| 154 | +fi | ||
| 155 | + | ||
| 113 | # ---------------------------------------------------------------- video ----- | 156 | # ---------------------------------------------------------------- video ----- |
| 114 | # name|encoder|extra args|pix_fmts (comma-separated) | 157 | # name|encoder|extra args|pix_fmts (comma-separated) |
| 115 | VIDEO_CODECS=( | 158 | VIDEO_CODECS=( |