forge
Explore
Log in

Don't you dare go Hollow

Fixture scripts + comparison harness

Browse files at this commit

d207f1def34009adb0b2cbd40aad00cb5b6d9549Ahmet Kaan GümüşParent: a3c0049
  • feat
    • fixture scripts + comparison harness
Show full message
feat(oracle): fixture scripts + comparison harness

gen-fixtures.sh: 87 deterministic ffmpeg fixtures (10 audio codecs x mono/stereo/5.1 x 44.1/48k, 4 video codecs x mp4/mkv x 23.976/60 x 8/10-bit, 4K sample per codec).
fetch-vectors.sh: JVT H.264, JCT-VC HEVC, RFC6716 Opus, cellar FLAC, Xiph Vorbis; checksum-pinned in scripts/vectors.sha256, resumable, per-set graceful failure.
scan-real-library.sh: read-only ffprobe sweep of the local media dirs into fixtures/real-library-manifest.tsv (T3 gate input).
tools/oracle: std-only bin driving ffmpeg/ffprobe through process pipes (bit-exact, audio-compare, video-compare); ffmpeg stays test tooling, never a crate dep.
Cargo.lockmodified+4 -0
@@ -5,3 +5,7 @@ version = 4
55 [[package]]
66 name = "ec-core"
77 version = "0.1.0"
8+
9+[[package]]
10+name = "oracle"
11+version = "0.1.0"
scripts/fetch-vectors.shadded+216 -0
@@ -0,0 +1,216 @@
1+#!/usr/bin/env bash
2+# fetch-vectors.sh — download third-party conformance vectors into fixtures/vectors/.
3+#
4+# Vectors are NOT redistributed from this repo (fixtures/ is gitignored); only this
5+# script and scripts/vectors.sha256 are committed. Idempotent, checksum-verified,
6+# and graceful: a dead URL or offline network reports the set as FAILED and the
7+# script continues with the remaining sets.
8+#
9+# Usage: scripts/fetch-vectors.sh [set ...] (default: all sets)
10+# sets: h264-jvt hevc-jctvc opus-rfc6716 flac-xiph vorbis-xiph
11+# Env: EC_FIXTURES=<dir> (default <repo>/fixtures)
12+
13+set -uo pipefail
14+
15+ROOT=$(cd -- "$(dirname -- "$0")/.." && pwd)
16+VEC=${EC_FIXTURES:-$ROOT/fixtures}/vectors
17+SUMS=$ROOT/scripts/vectors.sha256
18+CURL=(curl -fsSL --retry 2 --retry-delay 2 --connect-timeout 20 --max-time 900)
19+
20+command -v curl >/dev/null || { echo "fetch-vectors: curl not found" >&2; exit 2; }
21+mkdir -p -- "$VEC"
22+touch -- "$SUMS"
23+
24+ok_sets=()
25+fail_sets=()
26+n_new=0
27+n_have=0
28+n_bad=0
29+
30+# verify_or_record <abs-file> — checksum against scripts/vectors.sha256, or record it.
31+verify_or_record() {
32+ local f=$1 rel=${1#"$VEC"/} want have
33+ have=$(sha256sum -- "$f" | cut -d' ' -f1)
34+ want=$(awk -v k="$rel" '$2 == k { print $1 }' "$SUMS")
35+ if [ -z "$want" ]; then
36+ printf '%s %s\n' "$have" "$rel" >>"$SUMS"
37+ return 0
38+ fi
39+ [ "$want" = "$have" ] && return 0
40+ echo "CHECKSUM MISMATCH $rel (want $want got $have)" >&2
41+ rm -f -- "$f"
42+ n_bad=$((n_bad + 1))
43+ return 1
44+}
45+
46+# fetch_list <destdir> <baseurl> <name...> — parallel download of missing names.
47+fetch_list() {
48+ local dest=$1 base=$2
49+ shift 2
50+ local name missing=() args=() rc=0
51+ mkdir -p -- "$dest"
52+ for name in "$@"; do
53+ if [ -s "$dest/$name" ]; then
54+ verify_or_record "$dest/$name" && { n_have=$((n_have + 1)); continue; }
55+ fi
56+ missing+=("$name")
57+ done
58+ if [ "${#missing[@]}" -gt 0 ]; then
59+ for name in "${missing[@]}"; do args+=(-O "$base/$name"); done
60+ "${CURL[@]}" --parallel --parallel-max 4 --output-dir "$dest" "${args[@]}" || rc=1
61+ for name in "${missing[@]}"; do
62+ if [ -s "$dest/$name" ] && verify_or_record "$dest/$name"; then
63+ n_new=$((n_new + 1))
64+ else
65+ rm -f -- "$dest/$name"
66+ rc=1
67+ fi
68+ done
69+ fi
70+ return "$rc"
71+}
72+
73+# fetch_archive <destdir> <url> <archive-name> — download + extract once.
74+fetch_archive() {
75+ local dest=$1 url=$2 arc=$3
76+ mkdir -p -- "$dest"
77+ if [ -s "$dest/$arc" ]; then
78+ verify_or_record "$dest/$arc" || return 1
79+ n_have=$((n_have + 1))
80+ else
81+ "${CURL[@]}" -o "$dest/$arc" "$url" || { rm -f -- "$dest/$arc"; return 1; }
82+ verify_or_record "$dest/$arc" || return 1
83+ n_new=$((n_new + 1))
84+ fi
85+ [ -e "$dest/.extracted" ] && return 0
86+ case $arc in
87+ *.tar.gz | *.tgz) tar -xzf "$dest/$arc" -C "$dest" || return 1 ;;
88+ *.zip) unzip -qo "$dest/$arc" -d "$dest" || return 1 ;;
89+ *) return 0 ;;
90+ esac
91+ touch -- "$dest/.extracted"
92+}
93+
94+# extract_zips <dir> — unpack each <name>.zip into <name>/ once (bitstream + ref yuv).
95+extract_zips() {
96+ local dir=$1 z base
97+ command -v unzip >/dev/null || {
98+ echo "fetch-vectors: unzip not found — zips left packed in $dir" >&2
99+ return 0
100+ }
101+ for z in "$dir"/*.zip; do
102+ [ -e "$z" ] || continue
103+ base=${z%.zip}
104+ [ -d "$base" ] && continue
105+ mkdir -p -- "$base"
106+ unzip -qo "$z" -d "$base" || {
107+ echo "fetch-vectors: unzip failed: $z" >&2
108+ rm -rf -- "$base"
109+ }
110+ done
111+}
112+
113+run_set() {
114+ local name=$1
115+ shift
116+ if "$@"; then ok_sets+=("$name"); else fail_sets+=("$name"); fi
117+}
118+
119+# ------------------------------------------------------------- h264-jvt -----
120+# JVT/ITU-T H.264.1 conformance bitstreams (the set openh264 & ffmpeg are checked
121+# against). 35-stream feature-covering subset: CAVLC/CABAC, MBAFF/PAFF, I_PCM,
122+# weighted pred, long-term refs, multiple slice groups, redundant slices.
123+JVT_BASE=https://www.itu.int/wftp3/av-arch/jvt-site/draft_conformance/AVCv1
124+JVT_STREAMS=(
125+ AUD_MW_E.zip BA1_Sony_D.zip BA3_SVA_C.zip BA_MW_D.zip BANM_MW_D.zip
126+ BASQP1_Sony_C.zip CABA1_SVA_B.zip CABA2_SVA_B.zip CABA3_SVA_B.zip
127+ CACQP3_Sony_D.zip CAMACI3_Sony_C.zip CAMASL3_Sony_B.zip CANL1_SVA_B.zip
128+ CANL2_SVA_B.zip CANL3_SVA_B.zip CANL4_SVA_B.zip CI_MW_D.zip CVFI1_SVA_C.zip
129+ CVFI2_SVA_C.zip CVMAQP2_Sony_G.zip CVMAQP3_Sony_D.zip CVPCMNL2_SVA_C.zip
130+ FI1_Sony_E.zip FM2_SVA_C.zip MIDR_MW_D.zip MR1_BT_A.zip MR9_BT_B.zip
131+ NL1_Sony_D.zip NL3_SVA_E.zip NRF_MW_E.zip SL1_SVA_B.zip SVA_BA2_D.zip
132+ SVA_CL1_E.zip SVA_FM1_E.zip SVA_NL2_E.zip
133+)
134+
135+# ----------------------------------------------------------- hevc-jctvc -----
136+# JCT-VC HEVC_v1 conformance suite. NOTE: "class A/B" names the CTC *test
137+# sequences* (Traffic/Kimono/...), not conformance bitstreams — the redistributable
138+# conformance set is feature-named, so this is a feature-covering subset incl. the
139+# Main10 streams needed for the 10-bit/P010 HW path.
140+HEVC_BASE=https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/HEVC_v1
141+HEVC_STREAMS=(
142+ AMP_A_Samsung_7.zip AMVP_A_MTK_4.zip BUMPING_A_ericsson_1.zip
143+ CAINIT_A_SHARP_4.zip CIP_A_Panasonic_3.zip CONFWIN_A_Sony_1.zip
144+ DBLK_A_SONY_3.zip DBLK_A_MAIN10_VIXS_4.zip DELTAQP_A_BRCM_4.zip
145+ DSLICE_A_HHI_5.zip ENTP_A_QUALCOMM_1.zip FILLER_A_Sony_1.zip
146+ INITQP_A_Sony_1.zip INITQP_B_Main10_Sony_1.zip ipcm_A_NEC_3.zip
147+ IPRED_A_docomo_2.zip MAXBINS_A_TI_5.zip MERGE_A_TI_3.zip
148+ PICSIZE_A_Bossen_1.zip POC_A_Bossen_3.zip RAP_A_docomo_6.zip
149+ RPS_A_docomo_5.zip RQT_A_HHI_4.zip SAO_A_MediaTek_4.zip SDH_A_Orange_4.zip
150+ SLICES_A_Rovi_3.zip TILES_A_Cisco_2.zip TSKIP_A_MS_3.zip
151+ TSUNEQBD_A_MAIN10_Technicolor_2.zip WPP_A_ericsson_MAIN_2.zip
152+ WPP_A_ericsson_MAIN10_2.zip WP_A_MAIN10_Toshiba_3.zip
153+)
154+
155+# ---------------------------------------------------------- vorbis-xiph -----
156+# Xiph's own Vorbis I decoder test vectors (chained streams, LSP edge cases,
157+# 48k mono, sample-rate oddities).
158+VORBIS_BASE=https://people.xiph.org/~xiphmont/test-vectors/vorbis
159+VORBIS_FILES=(
160+ 1.0-test.ogg 1.0.1-test.ogg 48k-mono.ogg beta3-test.ogg beta4-test.ogg
161+ bimS-silence.ogg chain-test1.ogg chain-test2.ogg chain-test3.ogg
162+ highrate-test.ogg lsp-test.ogg lsp-test2.ogg lsp-test3.ogg lsp-test4.ogg
163+ moog.ogg one-entry-codebook-test.ogg out-of-spec-blocksize.ogg
164+ rc1-test.ogg rc2-test.ogg rc3-test.ogg singlemap-test.ogg sleepzor.ogg
165+ test-short.ogg test-short2.ogg unused-mode-test.ogg
166+)
167+
168+SETS=("$@")
169+[ "${#SETS[@]}" -eq 0 ] && SETS=(h264-jvt hevc-jctvc opus-rfc6716 flac-xiph vorbis-xiph)
170+
171+for s in "${SETS[@]}"; do
172+ case $s in
173+ h264-jvt)
174+ run_set "$s" fetch_list "$VEC/h264-jvt" "$JVT_BASE" "${JVT_STREAMS[@]}"
175+ extract_zips "$VEC/h264-jvt"
176+ ;;
177+ hevc-jctvc)
178+ run_set "$s" fetch_list "$VEC/hevc-jctvc" "$HEVC_BASE" "${HEVC_STREAMS[@]}"
179+ extract_zips "$VEC/hevc-jctvc"
180+ ;;
181+ opus-rfc6716)
182+ # RFC 6716 / 8251 decoder test vectors (opus_compare reference set).
183+ run_set "$s" fetch_archive "$VEC/opus-rfc6716" \
184+ https://opus-codec.org/testvectors/opus_testvectors.tar.gz \
185+ opus_testvectors.tar.gz
186+ ;;
187+ flac-xiph)
188+ # IETF cellar WG FLAC test files (supersedes the old svn.xiph.org set;
189+ # carries the RFC 9639 subset + uncommon-but-legal stream shapes).
190+ run_set "$s" fetch_archive "$VEC/flac-xiph" \
191+ https://codeload.github.com/ietf-wg-cellar/flac-test-files/tar.gz/refs/heads/main \
192+ flac-test-files.tar.gz
193+ ;;
194+ vorbis-xiph)
195+ run_set "$s" fetch_list "$VEC/vorbis-xiph" "$VORBIS_BASE" "${VORBIS_FILES[@]}"
196+ ;;
197+ *)
198+ echo "unknown set: $s" >&2
199+ fail_sets+=("$s")
200+ ;;
201+ esac
202+done
203+
204+printf '\n%s\n' "== vectors: $VEC =="
205+for s in "${ok_sets[@]:-}"; do
206+ [ -n "$s" ] || continue
207+ printf 'OK %-14s files=%s bytes=%s\n' "$s" \
208+ "$(find "$VEC/$s" -type f ! -name .extracted 2>/dev/null | wc -l)" \
209+ "$(du -sb "$VEC/$s" 2>/dev/null | cut -f1)"
210+done
211+for s in "${fail_sets[@]:-}"; do
212+ [ -n "$s" ] && printf 'FAILED %-14s (network or dead URL — rerun to resume)\n' "$s"
213+done
214+printf 'downloaded=%s already-present=%s checksum-mismatch=%s sets-ok=%s sets-failed=%s\n' \
215+ "$n_new" "$n_have" "$n_bad" "${#ok_sets[@]}" "${#fail_sets[@]}"
216+[ "${#fail_sets[@]}" -eq 0 ] && [ "$n_bad" -eq 0 ]
scripts/gen-fixtures.shadded+167 -0
@@ -0,0 +1,167 @@
1+#!/usr/bin/env bash
2+# gen-fixtures.sh — deterministic ffmpeg-generated media fixtures for edith_codecs.
3+#
4+# ffmpeg is ORACLE/test-input tooling only; no ec-* crate depends on it at runtime.
5+# Idempotent: non-empty outputs are skipped, partial outputs are deleted on failure.
6+# Content is deterministic (sine tones per channel, testsrc2) so regenerating on
7+# another machine with the same ffmpeg yields the same bytes.
8+#
9+# Usage: scripts/gen-fixtures.sh [-f] (-f: regenerate everything)
10+# Env: EC_FIXTURES=<dir> (default <repo>/fixtures)
11+
12+set -uo pipefail
13+
14+ROOT=$(cd -- "$(dirname -- "$0")/.." && pwd)
15+FIXTURES=${EC_FIXTURES:-$ROOT/fixtures}
16+DUR_A=3
17+DUR_V=2
18+FORCE=0
19+[ "${1:-}" = "-f" ] && FORCE=1
20+
21+command -v ffmpeg >/dev/null || { echo "gen-fixtures: ffmpeg not found" >&2; exit 2; }
22+
23+TMPLOG=$(mktemp) || exit 2
24+trap 'rm -f "$TMPLOG"' EXIT
25+
26+n_made=0
27+n_skip=0
28+failed=()
29+unsupported=()
30+
31+# gen <out> <ffmpeg args...>
32+gen() {
33+ local out=$1
34+ shift
35+ if [ "$FORCE" -eq 0 ] && [ -s "$out" ]; then
36+ n_skip=$((n_skip + 1))
37+ return 0
38+ fi
39+ mkdir -p -- "$(dirname -- "$out")"
40+ if ffmpeg -nostdin -y -v error "$@" "$out" 2>"$TMPLOG"; then
41+ n_made=$((n_made + 1))
42+
43+ return 0
44+ fi
45+ rm -f -- "$out"
46+ failed+=("${out#"$FIXTURES"/}: $(tr '\n' ' ' <"$TMPLOG" | cut -c1-140)")
47+ return 1
48+}
49+
50+# ---------------------------------------------------------------- audio -----
51+# Per-channel distinct frequencies: lets the oracle catch channel-order bugs
52+# (5.1 order FL,FR,FC,LFE,BL,BR) that identical-tone fixtures hide.
53+FREQS=(220 440 660 55 880 1320)
54+
55+# build_audio_in <nch> <rate> -> sets AIN[] and AMAP[]
56+build_audio_in() {
57+ local nch=$1 rate=$2 i lbl="" layout
58+ AIN=()
59+ for ((i = 0; i < nch; i++)); do
60+ AIN+=(-f lavfi -i "sine=frequency=${FREQS[i]}:sample_rate=${rate}:duration=${DUR_A}")
61+ done
62+ if [ "$nch" -eq 1 ]; then
63+ AMAP=(-map 0:a)
64+ return
65+ fi
66+ for ((i = 0; i < nch; i++)); do lbl="${lbl}[${i}:a]"; done
67+ case $nch in
68+ 2) layout=stereo ;;
69+ 6) layout=5.1 ;;
70+ *) layout=$nch ;;
71+ esac
72+ AMAP=(-filter_complex "${lbl}join=inputs=${nch}:channel_layout=${layout}[a]" -map "[a]")
73+}
74+
75+# name|ext|encoder args
76+AUDIO_CODECS=(
77+ "wav16|wav|-c:a pcm_s16le"
78+ "flac|flac|-c:a flac -compression_level 5"
79+ "mp3|mp3|-c:a libmp3lame -b:a 192k"
80+ "aac-adts|aac|-c:a aac -b:a 160k"
81+ "aac-mp4|mp4|-c:a aac -b:a 160k"
82+ "ac3|ac3|-c:a ac3 -b:a 448k"
83+ "eac3|eac3|-c:a eac3 -b:a 448k"
84+ "vorbis-ogg|ogg|-c:a libvorbis -q:a 5"
85+ "opus-ogg|opus|-c:a libopus -b:a 160k -vbr on"
86+ "alac-mp4|m4a|-c:a alac"
87+)
88+LAYOUTS=("mono|1" "stereo|2" "5.1|6")
89+RATES=(44100 48000)
90+
91+for spec in "${AUDIO_CODECS[@]}"; do
92+ IFS='|' read -r cname cext cargs <<<"$spec"
93+ read -r -a CARGS <<<"$cargs"
94+ for lspec in "${LAYOUTS[@]}"; do
95+ IFS='|' read -r lname nch <<<"$lspec"
96+ for rate in "${RATES[@]}"; do
97+ # Encoder capability gates — a skipped combo is reported, never silent.
98+ if [ "$cname" = "mp3" ] && [ "$nch" -gt 2 ]; then
99+ unsupported+=("audio/${cname}-${lname}-${rate}: libmp3lame is mono/stereo only")
100+ continue
101+ fi
102+ if [ "$cname" = "opus-ogg" ] && [ "$rate" != 48000 ]; then
103+ unsupported+=("audio/${cname}-${lname}-${rate}: libopus encodes at 48 kHz only")
104+ continue
105+ fi
106+ build_audio_in "$nch" "$rate"
107+ gen "$FIXTURES/audio/${cname}-${lname}-${rate}.${cext}" \
108+ "${AIN[@]}" "${AMAP[@]}" "${CARGS[@]}" -ar "$rate"
109+ done
110+ done
111+done
112+
113+# ---------------------------------------------------------------- video -----
114+# name|encoder|extra args|pix_fmts (comma-separated)
115+VIDEO_CODECS=(
116+ "h264|libx264|-preset ultrafast -crf 23|yuv420p"
117+ "hevc|libx265|-preset ultrafast -crf 28 -x265-params log-level=error|yuv420p,yuv420p10le"
118+ "vp9|libvpx-vp9|-deadline realtime -cpu-used 8 -row-mt 1 -b:v 0 -crf 32|yuv420p,yuv420p10le"
119+ "av1|librav1e|-speed 10 -qp 100|yuv420p,yuv420p10le"
120+)
121+FPS=("23.976|24000/1001" "60|60")
122+CONTAINERS=(mp4 mkv)
123+
124+# gen_video <codec> <encoder> <extra-args-str> <pix_fmt> <fpstag> <fpsval> <WxH> <restag> <container>
125+gen_video() {
126+ local codec=$1 enc=$2 extra=$3 pix=$4 fpstag=$5 fpsval=$6 size=$7 restag=$8 cont=$9
127+ local depth=8 tag=()
128+ case $pix in *10le) depth=10 ;; esac
129+ [ "$codec" = hevc ] && [ "$cont" = mp4 ] && tag=(-tag:v hvc1)
130+ local ex=()
131+ read -r -a ex <<<"$extra"
132+ gen "$FIXTURES/video/${codec}-${restag}-${fpstag}-${depth}bit.${cont}" \
133+ -f lavfi -i "testsrc2=size=${size}:rate=${fpsval}:duration=${DUR_V}" \
134+ -pix_fmt "$pix" -c:v "$enc" "${ex[@]}" "${tag[@]}"
135+}
136+
137+for spec in "${VIDEO_CODECS[@]}"; do
138+ IFS='|' read -r vname venc vextra vpixs <<<"$spec"
139+ IFS=',' read -r -a PIXS <<<"$vpixs"
140+ for pix in "${PIXS[@]}"; do
141+ for fspec in "${FPS[@]}"; do
142+ IFS='|' read -r ftag fval <<<"$fspec"
143+ for cont in "${CONTAINERS[@]}"; do
144+ gen_video "$vname" "$venc" "$vextra" "$pix" "$ftag" "$fval" 1920x1080 1080p "$cont"
145+ done
146+ done
147+ done
148+ # One 4K sample per codec (8-bit, mp4, 23.976) — size/stride edge cases.
149+ gen_video "$vname" "$venc" "$vextra" yuv420p 23.976 24000/1001 3840x2160 2160p mp4
150+done
151+
152+# -------------------------------------------------------------- summary -----
153+printf '\n%s\n' "== fixtures: $FIXTURES =="
154+printf '%-42s %10s %s\n' FILE SIZE PROBE
155+total=0
156+while IFS= read -r f; do
157+ total=$((total + 1))
158+ sz=$(stat -c %s -- "$f")
159+ p=$(ffprobe -v error -show_entries stream=codec_name,channels,sample_rate,width,height,pix_fmt \
160+ -of default=nw=1:nk=1 "$f" 2>/dev/null | tr '\n' ' ')
161+ printf '%-42s %10s %s\n' "${f#"$FIXTURES"/}" "$sz" "$p"
162+done < <(find "$FIXTURES/audio" "$FIXTURES/video" -type f 2>/dev/null | sort)
163+
164+printf '\n%s\n' "total=$total generated=$n_made skipped-existing=$n_skip unsupported=${#unsupported[@]} failed=${#failed[@]}"
165+for u in "${unsupported[@]:-}"; do [ -n "$u" ] && printf 'UNSUPPORTED %s\n' "$u"; done
166+for e in "${failed[@]:-}"; do [ -n "$e" ] && printf 'FAILED %s\n' "$e"; done
167+[ "${#failed[@]}" -eq 0 ] || exit 1
scripts/scan-real-library.shadded+99 -0
@@ -0,0 +1,99 @@
1+#!/usr/bin/env bash
2+# scan-real-library.sh — ffprobe sweep of the user's real media library.
3+#
4+# READ-ONLY on the scanned directories; the only thing written is the manifest
5+# under fixtures/ (gitignored — regenerable). The manifest is the T3 gate input:
6+# every codec/container claim in this repo is checked against these files, not
7+# only against synthetic fixtures.
8+#
9+# Usage: scripts/scan-real-library.sh [dir ...] (default: ~/Videos ~/Downloads)
10+# Env: EC_FIXTURES=<dir> (default <repo>/fixtures)
11+# Out: fixtures/real-library-manifest.tsv
12+# columns: path container vcodec width height pix_fmt bit_depth acodecs duration size
13+
14+set -uo pipefail
15+
16+ROOT=$(cd -- "$(dirname -- "$0")/.." && pwd)
17+FIXTURES=${EC_FIXTURES:-$ROOT/fixtures}
18+OUT=$FIXTURES/real-library-manifest.tsv
19+
20+command -v ffprobe >/dev/null || { echo "scan-real-library: ffprobe not found" >&2; exit 2; }
21+
22+DIRS=("$@")
23+[ "${#DIRS[@]}" -eq 0 ] && DIRS=("$HOME/Videos" "$HOME/Downloads")
24+
25+EXTS=(mp4 m4v mov mkv webm avi flv ts m2ts mts wmv ogv
26+ mp3 m4a aac flac wav ogg oga opus wma ac3 eac3 alac aif aiff)
27+
28+mkdir -p -- "$FIXTURES"
29+tmp=$(mktemp) || exit 2
30+trap 'rm -f "$tmp"' EXIT
31+
32+# Build the -iname predicate list once.
33+find_args=()
34+for e in "${EXTS[@]}"; do find_args+=(-iname "*.$e" -o); done
35+unset 'find_args[${#find_args[@]}-1]'
36+
37+# field <key> <ffprobe-kv-block> — "" when absent or N/A.
38+field() {
39+ local v
40+ v=$(printf '%s\n' "$2" | sed -n "s/^$1=//p" | head -n1)
41+ [ "$v" = "N/A" ] && v=""
42+ printf '%s' "$v"
43+}
44+
45+n=0
46+nerr=0
47+{
48+ printf 'path\tcontainer\tvcodec\twidth\theight\tpix_fmt\tbit_depth\tacodecs\tduration\tsize\n'
49+ while IFS= read -r -d '' f; do
50+ # Key=value form (not nk=1): a field ffprobe omits must not shift the others.
51+ fmt=$(ffprobe -v error -show_entries format=format_name,duration \
52+ -of default=nw=1 "$f" 2>/dev/null)
53+ if [ -z "$fmt" ]; then
54+ nerr=$((nerr + 1))
55+ printf '%s\tUNREADABLE\t-\t-\t-\t-\t-\t-\t-\t%s\n' "$f" "$(stat -c %s -- "$f")"
56+ continue
57+ fi
58+ container=$(field format_name "$fmt")
59+ duration=$(field duration "$fmt")
60+ v=$(ffprobe -v error -select_streams v:0 \
61+ -show_entries stream=codec_name,width,height,pix_fmt,bits_per_raw_sample \
62+ -of default=nw=1 "$f" 2>/dev/null)
63+ vcodec=$(field codec_name "$v")
64+ vw=$(field width "$v")
65+ vh=$(field height "$v")
66+ vpix=$(field pix_fmt "$v")
67+ vbits=$(field bits_per_raw_sample "$v")
68+ # bits_per_raw_sample is often absent/0 — fall back to the pix_fmt suffix.
69+ if [ -z "$vbits" ] || [ "$vbits" = "N/A" ] || [ "$vbits" = 0 ]; then
70+ case $vpix in
71+ *12le | *12be) vbits=12 ;;
72+ *10le | *10be) vbits=10 ;;
73+ "") vbits="" ;;
74+ *) vbits=8 ;;
75+ esac
76+ fi
77+ acodecs=$(ffprobe -v error -select_streams a -show_entries stream=codec_name \
78+ -of default=nw=1:nk=1 "$f" 2>/dev/null | paste -sd, -)
79+ printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' \
80+ "$f" "${container:--}" "${vcodec:--}" "${vw:--}" "${vh:--}" \
81+ "${vpix:--}" "${vbits:--}" "${acodecs:--}" "${duration:--}" \
82+ "$(stat -c %s -- "$f")"
83+ n=$((n + 1))
84+ done < <(find "${DIRS[@]}" -type f \( "${find_args[@]}" \) -print0 2>/dev/null)
85+} >"$tmp"
86+
87+mv -- "$tmp" "$OUT"
88+trap - EXIT
89+
90+printf '%s\n' "== $OUT =="
91+printf 'scanned=%s unreadable=%s\n\n' "$((n + nerr))" "$nerr"
92+printf 'containers:\n'
93+tail -n +2 "$OUT" | cut -f2 | sort | uniq -c | sort -rn
94+printf '\nvideo codecs:\n'
95+tail -n +2 "$OUT" | cut -f3 | sort | uniq -c | sort -rn
96+printf '\naudio codecs (per file, comma-joined):\n'
97+tail -n +2 "$OUT" | cut -f8 | tr ',' '\n' | sort | uniq -c | sort -rn
98+printf '\nbit depths:\n'
99+tail -n +2 "$OUT" | cut -f7 | sort | uniq -c | sort -rn
scripts/vectors.sha256added+94 -0
@@ -0,0 +1,94 @@
1+ecaed4a05d02c8ffc0ec7dd02a640f87ba9d9f8c2dab3273ef1d6da3d7f8568e h264-jvt/AUD_MW_E.zip
2+399eae2eb03f82fc291bdc4fe9cedd110b40a96368ffe1e1bcf9ff6436fa9df7 h264-jvt/BA1_Sony_D.zip
3+1c7003ff7b4507204f50e0b279149fd183c0890ee2a12c4c2d008db387299b82 h264-jvt/BA3_SVA_C.zip
4+f85d0c1e6a8317ecff19bf11d1496b327ee11e391de27453031062ea62241843 h264-jvt/BA_MW_D.zip
5+b50e2e7ca2a355087e9d993174626a027cea2da5f84f704cc0b2c6cb9145dfbd h264-jvt/BANM_MW_D.zip
6+f7cdbfaee43ff2e88b78d0b41ddcde83ac5148867e7b7df1759d97e0294f6c19 h264-jvt/BASQP1_Sony_C.zip
7+d0cf94006df2319a6c98683a6013f85ea5a1c0d382c796523b751c263e8c8989 h264-jvt/CABA1_SVA_B.zip
8+68c700914c0926b5dcb75ef3fe601a3434c1de3af6c4906a3573baf9998752db h264-jvt/CABA2_SVA_B.zip
9+375996d3de61bf6f7a58f48c46a477804636d118fe743501eef48c04fb3993cf h264-jvt/CABA3_SVA_B.zip
10+c8efdbc5d0af62b99d1e357717c26eb34ed13f3cf8bacb04a60bf87a0bd2a054 h264-jvt/CACQP3_Sony_D.zip
11+da020750950a89277ff10b53d5983ab525d61ba9b180562fc4fc1da9af721227 h264-jvt/CAMACI3_Sony_C.zip
12+4e675b3701e5ed42c7f94c8d04ec755111a2bb595a759e512dc1361fb2f59ccd h264-jvt/CAMASL3_Sony_B.zip
13+2f364e4ff117f9fce0b55ae417f2f5ee992d6e4042e207eed0a212b71580ae27 h264-jvt/CANL1_SVA_B.zip
14+0936f0816c5b44e0115c5dcea65717c678f3de8cf858308283f1328358733186 h264-jvt/CANL2_SVA_B.zip
15+2398eca7b8da95820ccb025b37c1103d8abd9f9a06eb45ccc3b9704ab1f2ff2e h264-jvt/CANL3_SVA_B.zip
16+a19e259438917a68f026de4045eff25d2dfe416c081d215bca40901214617cab h264-jvt/CANL4_SVA_B.zip
17+6e41825983037e3af50a3e4add6ac9dbde3ea6f41ab6f77cc432de22a2920d49 h264-jvt/CI_MW_D.zip
18+3f3da0c2ae0400e9549af1bea567ee0833db3141d39b2d10e7612f8c246029de h264-jvt/CVFI1_SVA_C.zip
19+0c46afd124d9931ad349e9355e405f9f61b2f168223618691d023ab8e04a2877 h264-jvt/CVFI2_SVA_C.zip
20+7ba8640b584bcf5d96e942800b9f2e6a70d4fefa4c70768913c7cb559ddcd379 h264-jvt/CVMAQP2_Sony_G.zip
21+867360dcec6f9da7572be6717e20182ed5ff7fb574ba665b0d22fce4fb106822 h264-jvt/CVMAQP3_Sony_D.zip
22+90b0574aa7d02f8b250c4997b78fd4f112983fd3eb9eb7c12df6d5b7560ceb1d h264-jvt/CVPCMNL2_SVA_C.zip
23+9ce036bcd91bf89aa6256b4d5461231e74f8482dcf76bed075abddbcf4108f9f h264-jvt/FI1_Sony_E.zip
24+7e27a8776c70e47e4b4441809a6ec23c8a62e1a06eea364a6407839fc8650d4f h264-jvt/FM2_SVA_C.zip
25+69e7d04bd4b782f93401b12b79d58a96b39319d932743af8bc7134c752d6b577 h264-jvt/MIDR_MW_D.zip
26+a76d4e199e6ffb27292d1a07c516e5adea251e63e3f756de490c153b23d4684d h264-jvt/MR1_BT_A.zip
27+fd10a0be32f6fbe5d35e4a4b73707af97b3d8c1999bc5680c53d7068c20bf72e h264-jvt/MR9_BT_B.zip
28+1b26bfe8d05cf54b95e410779e48f90cc55305186e0c6184b5ea28ce9dc1b02d h264-jvt/NL1_Sony_D.zip
29+09d7a3fcf430e0635b55bc4308c56842863cdc1d52cc3e3ec6014487d13c1977 h264-jvt/NL3_SVA_E.zip
30+c48f067fe8ac1309b99292d024324a0a7561bf28312a133995a42d7a98ae9835 h264-jvt/NRF_MW_E.zip
31+60d61046c3aee6b9aa6b3dd4fad4081be9c959affec2bd641808632edffed1b2 h264-jvt/SL1_SVA_B.zip
32+e0cefee7e9206d06cad7bbdbe1441b6566208d693bcebc4396fa896be3a2c8d4 h264-jvt/SVA_BA2_D.zip
33+636098f10f2cdc80e31451b198c688bcc868fe536707c46ce2e0eaf54a33fa98 h264-jvt/SVA_CL1_E.zip
34+9db49088a67d960d1363605c40a603d38c87361f3b83e730e6541c5a1db4c10f h264-jvt/SVA_FM1_E.zip
35+f21e06d253b205aa65e796158daecfbcfc4ea2b5c41af1412f6bdd54a0a59977 h264-jvt/SVA_NL2_E.zip
36+3b8c7e4f77759351893470d87cd5c8252146ae19523786510914a9e8d5c7e340 hevc-jctvc/AMP_A_Samsung_7.zip
37+b89aa3d113bdff9aff61d4c190b9035155db44a9c9b08b5a40df89fde2e6a2c7 hevc-jctvc/AMVP_A_MTK_4.zip
38+3fef73e8e6263fd0f9f1bc6095e2a2cfba3451132e24f7ad08fa7c6510fafe5c hevc-jctvc/BUMPING_A_ericsson_1.zip
39+58d66213064bac9444cf13cc2f62d6f044bdb4d8ec9488640fb86090de976b43 hevc-jctvc/CAINIT_A_SHARP_4.zip
40+5c55b3594e5c951c9f5312913961750283eb2dadd15844fe35f9beb94a9a548c hevc-jctvc/CIP_A_Panasonic_3.zip
41+c3c823ffb9e526f5d9506ba2f1239b1f0323572850789230d762f4e4678fc298 hevc-jctvc/CONFWIN_A_Sony_1.zip
42+ce18cd42375359b9ff293d12a95793cc6b56eb75d899ad012c68e25dfa54dfbf hevc-jctvc/DBLK_A_SONY_3.zip
43+d86ec87f98fccbcec3758954a7cf430e8af8cf021d347dfbbed2f1d5dbb00f25 hevc-jctvc/DBLK_A_MAIN10_VIXS_4.zip
44+63abbbaf43d334d7952eab7bbc5b3e34b4ad0259eddcd63cdb164dbcf9a36ca6 hevc-jctvc/DELTAQP_A_BRCM_4.zip
45+c41c1a1e1e700af201eaf4cb0d11d4361b41ba0828e80c78d1835d1de187f80c hevc-jctvc/DSLICE_A_HHI_5.zip
46+66abdf60455ece468acf160274316c51dca3858d93a8ffce93646cbb5568fe43 hevc-jctvc/ENTP_A_QUALCOMM_1.zip
47+abf6cd7525378d2e1c8f32b67af01c594553c342c21dcd36ab677c3c77b528db hevc-jctvc/FILLER_A_Sony_1.zip
48+38b1d9396bab068fa701b08db73c3a900e893ef4cd00c82fc7b4d2b150a2f749 hevc-jctvc/INITQP_A_Sony_1.zip
49+c3f87037640953691dee02d4c9f28cd6a3b99de43e30bdcfdf583888191fa23e hevc-jctvc/INITQP_B_Main10_Sony_1.zip
50+89a71f4b9b7e22c481378f83bacc5aac6c8f204999691d3fa21f2804337e84c9 hevc-jctvc/ipcm_A_NEC_3.zip
51+5ee6e90cbcbf0547e43e72536ab39af1d831363f95c368c175267d6e48d264da hevc-jctvc/IPRED_A_docomo_2.zip
52+a6d1ed217b232aec8faff836c180a3368e5dd8ed3f8bf912c3527297ee89d498 hevc-jctvc/MAXBINS_A_TI_5.zip
53+b38d58301c0a8bd41ce982e40552850eabe9f140d2ff6ceca3375f9f5abc8a65 hevc-jctvc/MERGE_A_TI_3.zip
54+ffdffecff6ba03ce0220eb89e83bc3043af5953ab6864ad6acefee382e49ee7c hevc-jctvc/PICSIZE_A_Bossen_1.zip
55+aec93a088b81d68d87eda99e4a0e64bed7012b571158c8a2242223d1f9db8ccd hevc-jctvc/POC_A_Bossen_3.zip
56+5031bac0b1520ed826bf3112d000e59c76677c01dee706738af0d206cde031be hevc-jctvc/RAP_A_docomo_6.zip
57+45427f66400a033e7a47cc6ca9b21d456e9e06450db6ca8d8fa92c438125324b hevc-jctvc/RPS_A_docomo_5.zip
58+958d958baedbe4f2c864f5d9b3b87e69884170db403b4e190d1d33a0490ec3c6 hevc-jctvc/RQT_A_HHI_4.zip
59+e0b5c8f4ab4fb592971f06469db630d9e7ef72b4d37d729604e2fdaa9df706c9 hevc-jctvc/SAO_A_MediaTek_4.zip
60+ddf41877f10b47bad946712954e4a4b35cae435bac187d8c404c6bcfcb4acad0 hevc-jctvc/SDH_A_Orange_4.zip
61+d0141e111c1c854930eb16430cc5d3e5b82ccfa1458805fce20dd410b08c61ad hevc-jctvc/SLICES_A_Rovi_3.zip
62+bd63079966105a3bdac764979cb82b708f586cc7c34859a1d466e18cc6a5c345 hevc-jctvc/TILES_A_Cisco_2.zip
63+7f09bd323228975260b14c1b8e92cb15341771b29addd71cc0c2471d5e070a80 hevc-jctvc/TSKIP_A_MS_3.zip
64+615696a911a824988da0d883ab573fb673fd72bf45275d75549abc763602f814 hevc-jctvc/TSUNEQBD_A_MAIN10_Technicolor_2.zip
65+81c601e9301ba5f562ebf9918e73d1c7153e0a6fe8fa4509f61035a212188216 hevc-jctvc/WPP_A_ericsson_MAIN_2.zip
66+1827b7111a9ce76f6c04332b61cd24d9daf818fd203aa1d0b7d1087b9b83a6aa hevc-jctvc/WPP_A_ericsson_MAIN10_2.zip
67+26b3bc442265222032c1960cc02fe2bd55121fe933e70e5039521785073d33b2 hevc-jctvc/WP_A_MAIN10_Toshiba_3.zip
68+94ac78ca4f74c4e43bc9fe4ec1ad0aa36f38ab90f45b0727c40dd1e96096e767 opus-rfc6716/opus_testvectors.tar.gz
69+dae450db1ddd9d7773bc596bbca5d6cfd26e936eec48da9e1c2222f53e16526d flac-xiph/flac-test-files.tar.gz
70+9a882710314bcc1d2b4cdefb7f89911f4375acd1feb9e64a12eca9f7202377d3 vorbis-xiph/1.0-test.ogg
71+8c9423e00826d6d2457d78c09d6e2a94bcdf9216af796bb22a4c4f450c2e72bb vorbis-xiph/1.0.1-test.ogg
72+f51459d9bdd04ca3ec6f6732b8a01efcdc83e5c6fc79c7d5347527bfd4948e9e vorbis-xiph/48k-mono.ogg
73+7fc791a4d5a0d3b7cef2448093ccf2ae54600acc81667be90c6b209c366c32ea vorbis-xiph/beta3-test.ogg
74+bc367c0d4dcdbf1f0a2f81abf74cc52c8f0ab8366d150a75830782ca2dba080a vorbis-xiph/beta4-test.ogg
75+e2a38871d390ed651faf0fec5253a6873530da4f2503d85021c99325dfd23813 vorbis-xiph/bimS-silence.ogg
76+d9c37533a1f456d2a996755a43d112ef46b6ef953319913907bc79f1c014d79e vorbis-xiph/chain-test1.ogg
77+5b5bf834e93e9a93b7114be084161e972f33d2031963518492ba2c91dc4418a7 vorbis-xiph/chain-test2.ogg
78+ed039ba775d1b31e805d26d6413a3ef2c6663bf4c5ea47ce1462f8f23c84d8dc vorbis-xiph/chain-test3.ogg
79+0942c88369f84b125388cc8437575b66d67bc97baaeeb997b6602144821509df vorbis-xiph/highrate-test.ogg
80+ad1b07b68576ae2c85178475ef3607e1a96c09e96296cae83ee7a9726f8311eb vorbis-xiph/lsp-test.ogg
81+7b00f893a93071bdf243b8a22c1758a6ab09c1ab8eee89ca21659d98ec0f53ea vorbis-xiph/lsp-test2.ogg
82+7a5c4064fc31285f6fea0b2424a0d415a8b18ef13d1aa1ef931a429ab9a593d1 vorbis-xiph/lsp-test3.ogg
83+cb0b28931dfc8ef8b2d320f3028fab548171e7c6e94006f0c23532478a8d3596 vorbis-xiph/lsp-test4.ogg
84+bd5b51bb1d6855e0e990e3ebdd230fc16265407809bd6db44aea691ada498943 vorbis-xiph/moog.ogg
85+789b5146f2a7c0864a228ee4a870606a32c4169e22097be65129623705c54749 vorbis-xiph/one-entry-codebook-test.ogg
86+0970e66291744815f2ca0dec7523f5bbc112907c5c75978a0f91d3b0ed6f03b2 vorbis-xiph/out-of-spec-blocksize.ogg
87+ccfac6ac7c75615bec0632b94bcf088c027c0b112cd136c997d04f037252cd3d vorbis-xiph/rc1-test.ogg
88+4adcda786dfeea4188d7b1df35571dbe29c687f2d1cac680ed115353abfe1637 vorbis-xiph/rc2-test.ogg
89+edd984e84c7c2a59af7801f3e8d2db11a6619134fd8d0274d1289e70bf60cde7 vorbis-xiph/rc3-test.ogg
90+50d8077608a4192b8f8505aec0217be8b6c25def4068899afc19c17f30e1d521 vorbis-xiph/singlemap-test.ogg
91+01c67ecaf7a58b5ac5f1fe3bd060b5d61536595e97927a1b1cf0129a62b5cfcf vorbis-xiph/sleepzor.ogg
92+183510552403021fb90ce43796fcc88e16c8bb4ae5d0d72a316b8e51afc395fa vorbis-xiph/test-short.ogg
93+6bd3f59e0fa77904edd35c73dadd6558e2a36d78c9d7bc5db223862bf092fcc2 vorbis-xiph/test-short2.ogg
94+e27ae6fc2f7c0037c28328801c46d966abcee3050e3ebd40bf097f7986f50f94 vorbis-xiph/unused-mode-test.ogg
tools/oracle/Cargo.tomladded+15 -0
@@ -0,0 +1,15 @@
1+[package]
2+name = "oracle"
3+version.workspace = true
4+edition.workspace = true
5+license.workspace = true
6+authors.workspace = true
7+publish = false
8+
9+[[bin]]
10+name = "oracle"
11+path = "src/main.rs"
12+
13+# No dependencies on purpose: the oracle drives ffmpeg/ffprobe through std process
14+# pipes so that comparison tooling can never leak into any ec-* crate's dep graph.
15+[dependencies]
tools/oracle/src/main.rsadded+577 -0
@@ -0,0 +1,577 @@
1+//! `oracle` — ffmpeg-backed comparison harness for the edith_codecs family.
2+//!
3+//! ffmpeg/ffprobe are ORACLE tooling: they are driven here through `std::process`
4+//! pipes so no `ec-*` crate ever gains a media dependency, sync or async.
5+//!
6+//! Subcommands:
7+//! `bit-exact <a> <b>` byte-identical check
8+//! `audio-compare <ours.raw> <ref-file>` per-channel correlation + RMS delta
9+//! `video-compare <ours.raw> <ref-file>` per-frame PSNR, min/mean
10+//!
11+//! `<ours.raw>` is our decoder's raw output: interleaved f32 LE for audio, raw
12+//! planar/packed frames in `--pix-fmt` order for video. The reference is any file
13+//! ffmpeg can decode; it is decoded to the same raw layout and compared.
14+//!
15+//! stdout is TSV (every line `type<TAB>...`), stderr is the human summary.
16+//! Exit code: 0 = PASS, 1 = FAIL, 2 = usage/IO error.
17+
18+use std::collections::HashMap;
19+use std::process::{Command, Stdio};
20+
21+const USAGE: &str = "\
22+oracle — comparison harness (ffmpeg is test tooling only)
23+
24+ oracle bit-exact <a> <b>
25+ oracle audio-compare <ours.f32le.raw> <ref-file> [--channels N] [--min-corr F] [--max-rms F]
26+ oracle video-compare <ours.raw> <ref-file> [--pix-fmt FMT] [--size WxH] [--min-psnr DB]
27+
28+Defaults: --min-corr 0.999 --max-rms 1e-3 --min-psnr 40
29+Missing --channels/--pix-fmt/--size are probed from <ref-file> with ffprobe.
30+";
31+
32+fn main() {
33+ let argv: Vec<String> = std::env::args().skip(1).collect();
34+ let rc = match argv.first().map(String::as_str) {
35+ Some("bit-exact") => run(cmd_bit_exact(&argv[1..])),
36+ Some("audio-compare") => run(cmd_audio_compare(&argv[1..])),
37+ Some("video-compare") => run(cmd_video_compare(&argv[1..])),
38+ Some("-h") | Some("--help") => {
39+ print!("{USAGE}");
40+ 0
41+ }
42+ _ => {
43+ eprint!("{USAGE}");
44+ 2
45+ }
46+ };
47+ std::process::exit(rc);
48+}
49+
50+fn run(r: Result<bool, String>) -> i32 {
51+ match r {
52+ Ok(true) => 0,
53+ Ok(false) => 1,
54+ Err(e) => {
55+ eprintln!("oracle: {e}");
56+ 2
57+ }
58+ }
59+}
60+
61+// ------------------------------------------------------------------ args ---
62+
63+struct Args {
64+ pos: Vec<String>,
65+ flags: HashMap<String, String>,
66+}
67+
68+impl Args {
69+ fn parse(argv: &[String]) -> Result<Self, String> {
70+ let mut pos = Vec::new();
71+ let mut flags = HashMap::new();
72+ let mut it = argv.iter();
73+ while let Some(a) = it.next() {
74+ if let Some(key) = a.strip_prefix("--") {
75+ let v = it
76+ .next()
77+ .ok_or_else(|| format!("flag --{key} needs a value"))?;
78+ flags.insert(key.to_string(), v.clone());
79+ } else {
80+ pos.push(a.clone());
81+ }
82+ }
83+ Ok(Self { pos, flags })
84+ }
85+
86+ fn num<T: std::str::FromStr>(&self, key: &str, default: T) -> Result<T, String> {
87+ match self.flags.get(key) {
88+ None => Ok(default),
89+ Some(v) => v.parse().map_err(|_| format!("bad --{key} value: {v}")),
90+ }
91+ }
92+}
93+
94+// --------------------------------------------------------------- ffmpeg ----
95+
96+/// Decode `input` with ffmpeg and return the raw bytes it writes to stdout.
97+/// stderr is inherited so a large error log can never deadlock the pipe.
98+fn ffmpeg_raw(input: &str, extra: &[&str]) -> Result<Vec<u8>, String> {
99+ let out = Command::new("ffmpeg")
100+ .args(["-nostdin", "-v", "error", "-i", input])
101+ .args(extra)
102+ .arg("-")
103+ .stdout(Stdio::piped())
104+ .stderr(Stdio::inherit())
105+ .output()
106+ .map_err(|e| format!("spawning ffmpeg: {e}"))?;
107+ if !out.status.success() {
108+ return Err(format!("ffmpeg failed on {input} ({})", out.status));
109+ }
110+ if out.stdout.is_empty() {
111+ return Err(format!("ffmpeg produced no data for {input}"));
112+ }
113+ Ok(out.stdout)
114+}
115+
116+/// `ffprobe -show_entries stream=<entries>` as a key -> value map (first stream wins).
117+fn ffprobe(input: &str, select: &str, entries: &str) -> Result<HashMap<String, String>, String> {
118+ let out = Command::new("ffprobe")
119+ .args(["-v", "error", "-select_streams", select, "-show_entries"])
120+ .arg(format!("stream={entries}"))
121+ .args(["-of", "default=nw=1"])
122+ .arg(input)
123+ .stderr(Stdio::inherit())
124+ .output()
125+ .map_err(|e| format!("spawning ffprobe: {e}"))?;
126+ if !out.status.success() {
127+ return Err(format!("ffprobe failed on {input} ({})", out.status));
128+ }
129+ let mut map = HashMap::new();
130+ for line in String::from_utf8_lossy(&out.stdout).lines() {
131+ if let Some((k, v)) = line.split_once('=')
132+ && v != "N/A"
133+ {
134+ map.entry(k.to_string()).or_insert_with(|| v.to_string());
135+ }
136+ }
137+ Ok(map)
138+}
139+
140+fn read_file(path: &str) -> Result<Vec<u8>, String> {
141+ std::fs::read(path).map_err(|e| format!("reading {path}: {e}"))
142+}
143+
144+// ------------------------------------------------------------ bit-exact ----
145+
146+fn cmd_bit_exact(argv: &[String]) -> Result<bool, String> {
147+ let a = Args::parse(argv)?;
148+ if a.pos.len() != 2 {
149+ return Err("bit-exact needs exactly two files".into());
150+ }
151+ let (x, y) = (read_file(&a.pos[0])?, read_file(&a.pos[1])?);
152+ let first_diff = x.iter().zip(&y).position(|(p, q)| p != q);
153+ let pass = x.len() == y.len() && first_diff.is_none();
154+
155+ println!("meta\ta\t{}", a.pos[0]);
156+ println!("meta\tb\t{}", a.pos[1]);
157+ println!("meta\tlen_a\t{}", x.len());
158+ println!("meta\tlen_b\t{}", y.len());
159+ match first_diff {
160+ Some(off) => println!("diff\tfirst_offset\t{off}"),
161+ None => println!("diff\tfirst_offset\t-"),
162+ }
163+ println!("verdict\t{}", if pass { "PASS" } else { "FAIL" });
164+ eprintln!(
165+ "bit-exact: {} ({} vs {} bytes, first diff {})",
166+ if pass { "PASS" } else { "FAIL" },
167+ x.len(),
168+ y.len(),
169+ first_diff.map_or("-".into(), |o| o.to_string())
170+ );
171+ Ok(pass)
172+}
173+
174+// -------------------------------------------------------------- audio ------
175+
176+fn deinterleave_f32(buf: &[u8], channels: usize) -> Vec<Vec<f64>> {
177+ let frames = buf.len() / 4 / channels;
178+ let mut out = vec![Vec::with_capacity(frames); channels];
179+ for f in 0..frames {
180+ for (c, ch) in out.iter_mut().enumerate() {
181+ let i = (f * channels + c) * 4;
182+ ch.push(f32::from_le_bytes([buf[i], buf[i + 1], buf[i + 2], buf[i + 3]]) as f64);
183+ }
184+ }
185+ out
186+}
187+
188+/// Pearson correlation. Two constant signals correlate perfectly iff equal.
189+fn corr(a: &[f64], b: &[f64]) -> f64 {
190+ let n = a.len().min(b.len());
191+ if n == 0 {
192+ return 0.0;
193+ }
194+ let (ma, mb) = (
195+ a[..n].iter().sum::<f64>() / n as f64,
196+ b[..n].iter().sum::<f64>() / n as f64,
197+ );
198+ let (mut num, mut da, mut db) = (0.0, 0.0, 0.0);
199+ for i in 0..n {
200+ let (x, y) = (a[i] - ma, b[i] - mb);
201+ num += x * y;
202+ da += x * x;
203+ db += y * y;
204+ }
205+ if da == 0.0 || db == 0.0 {
206+ return if da == db && (ma - mb).abs() < 1e-12 {
207+ 1.0
208+ } else {
209+ 0.0
210+ };
211+ }
212+ num / (da * db).sqrt()
213+}
214+
215+fn rms_delta(a: &[f64], b: &[f64]) -> (f64, f64) {
216+ let n = a.len().min(b.len());
217+ if n == 0 {
218+ return (f64::INFINITY, f64::INFINITY);
219+ }
220+ let mut sum = 0.0;
221+ let mut peak: f64 = 0.0;
222+ for i in 0..n {
223+ let d = a[i] - b[i];
224+ sum += d * d;
225+ peak = peak.max(d.abs());
226+ }
227+ ((sum / n as f64).sqrt(), peak)
228+}
229+
230+fn cmd_audio_compare(argv: &[String]) -> Result<bool, String> {
231+ let a = Args::parse(argv)?;
232+ if a.pos.len() != 2 {
233+ return Err("audio-compare needs <ours.raw> <ref-file>".into());
234+ }
235+ let (ours_path, ref_path) = (&a.pos[0], &a.pos[1]);
236+ let min_corr: f64 = a.num("min-corr", 0.999)?;
237+ let max_rms: f64 = a.num("max-rms", 1e-3)?;
238+
239+ let probe = ffprobe(ref_path, "a:0", "channels,sample_rate")?;
240+ let channels: usize = match a.flags.get("channels") {
241+ Some(v) => v.parse().map_err(|_| "bad --channels".to_string())?,
242+ None => probe
243+ .get("channels")
244+ .ok_or("could not probe channel count; pass --channels")?
245+ .parse()
246+ .map_err(|_| "bad probed channel count".to_string())?,
247+ };
248+ if channels == 0 {
249+ return Err("channel count is zero".into());
250+ }
251+ let rate = probe
252+ .get("sample_rate")
253+ .cloned()
254+ .unwrap_or_else(|| "-".into());
255+
256+ let ours = read_file(ours_path)?;
257+ let reference = ffmpeg_raw(
258+ ref_path,
259+ &["-map", "0:a:0", "-f", "f32le", "-acodec", "pcm_f32le"],
260+ )?;
261+ let (na, nb) = (ours.len() / 4 / channels, reference.len() / 4 / channels);
262+ let (ca, cb) = (
263+ deinterleave_f32(&ours, channels),
264+ deinterleave_f32(&reference, channels),
265+ );
266+
267+ println!("meta\tours\t{ours_path}");
268+ println!("meta\tref\t{ref_path}");
269+ println!("meta\tchannels\t{channels}");
270+ println!("meta\tsample_rate\t{rate}");
271+ println!("meta\tframes_ours\t{na}");
272+ println!("meta\tframes_ref\t{nb}");
273+
274+ // A length gap beyond one percent is a decoder bug (dropped/duplicated
275+ // packets), not a comparison detail — it fails on its own.
276+ let len_ok = na.abs_diff(nb) as f64 <= 0.01 * na.max(nb) as f64;
277+ let mut min_c = f64::INFINITY;
278+ let mut max_r: f64 = 0.0;
279+ for c in 0..channels {
280+ let k = corr(&ca[c], &cb[c]);
281+ let (r, p) = rms_delta(&ca[c], &cb[c]);
282+ min_c = min_c.min(k);
283+ max_r = max_r.max(r);
284+ println!("ch\t{c}\tcorr\t{k:.6}\trms\t{r:.8}\tpeak\t{p:.8}");
285+ }
286+ let pass = len_ok && min_c >= min_corr && max_r <= max_rms;
287+ println!(
288+ "verdict\t{}\tmin_corr={min_c:.6}\tmax_rms={max_r:.8}\tlen_ok={len_ok}",
289+ if pass { "PASS" } else { "FAIL" }
290+ );
291+ eprintln!(
292+ "audio-compare: {} — {channels}ch @{rate}, min corr {min_c:.6} (>= {min_corr}), \
293+ max RMS delta {max_r:.8} (<= {max_rms}), lengths {na}/{nb}",
294+ if pass { "PASS" } else { "FAIL" }
295+ );
296+ Ok(pass)
297+}
298+
299+// -------------------------------------------------------------- video ------
300+
301+/// Raw-frame geometry for a pixel format: total samples, luma samples (0 when the
302+/// format is packed and has no contiguous luma plane), bytes per sample, max value.
303+struct PixGeom {
304+ samples: usize,
305+ luma: usize,
306+ bps: usize,
307+ max: f64,
308+}
309+
310+fn pix_geom(pix_fmt: &str, w: usize, h: usize) -> Result<PixGeom, String> {
311+ let wh = w * h;
312+ let g = |samples: usize, luma: usize, bps: usize, max: f64| PixGeom {
313+ samples,
314+ luma,
315+ bps,
316+ max,
317+ };
318+ // Semi-planar formats carry their depth inside the name, so match them first.
319+ match pix_fmt {
320+ "nv12" | "nv21" => return Ok(g(wh * 3 / 2, wh, 1, 255.0)),
321+ "p010le" | "p010be" => return Ok(g(wh * 3 / 2, wh, 2, 1023.0)),
322+ "p016le" | "p016be" => return Ok(g(wh * 3 / 2, wh, 2, 65535.0)),
323+ _ => {}
324+ }
325+ let mut base = pix_fmt;
326+ let mut bps = 1;
327+ let mut max = 255.0;
328+ for (suffix, depth) in [("9", 9u32), ("10", 10), ("12", 12), ("14", 14), ("16", 16)] {
329+ for endian in ["le", "be"] {
330+ let s = format!("{suffix}{endian}");
331+ if let Some(b) = pix_fmt.strip_suffix(&s) {
332+ base = b;
333+ bps = 2;
334+ max = ((1u32 << depth) - 1) as f64;
335+ }
336+ }
337+ }
338+ let geom = match base {
339+ "yuv420p" | "yuvj420p" => g(wh * 3 / 2, wh, bps, max),
340+ "yuv422p" | "yuvj422p" => g(wh * 2, wh, bps, max),
341+ "yuv444p" | "yuvj444p" | "gbrp" => g(wh * 3, wh, bps, max),
342+ "gray" => g(wh, wh, bps, max),
343+ // Packed: no contiguous luma plane, so luma PSNR falls back to all-plane.
344+ "yuyv422" | "uyvy422" => g(wh * 2, 0, bps, max),
345+ "rgb24" | "bgr24" => g(wh * 3, 0, bps, max),
346+ "rgba" | "bgra" | "argb" | "abgr" => g(wh * 4, 0, bps, max),
347+ _ => return Err(format!("unsupported pix_fmt for raw compare: {pix_fmt}")),
348+ };
349+ Ok(geom)
350+}
351+
352+fn sample(buf: &[u8], i: usize, bps: usize) -> f64 {
353+ if bps == 1 {
354+ buf[i] as f64
355+ } else {
356+ u16::from_le_bytes([buf[2 * i], buf[2 * i + 1]]) as f64
357+ }
358+}
359+
360+/// PSNR over `n` samples starting at sample index `off` in both buffers.
361+fn psnr(a: &[u8], b: &[u8], off: usize, n: usize, bps: usize, max: f64) -> f64 {
362+ let mut sum = 0.0;
363+ for i in off..off + n {
364+ let d = sample(a, i, bps) - sample(b, i, bps);
365+ sum += d * d;
366+ }
367+ let mse = sum / n as f64;
368+ if mse == 0.0 {
369+ f64::INFINITY
370+ } else {
371+ 10.0 * (max * max / mse).log10()
372+ }
373+}
374+
375+fn cmd_video_compare(argv: &[String]) -> Result<bool, String> {
376+ let a = Args::parse(argv)?;
377+ if a.pos.len() != 2 {
378+ return Err("video-compare needs <ours.raw> <ref-file>".into());
379+ }
380+ let (ours_path, ref_path) = (&a.pos[0], &a.pos[1]);
381+ let min_psnr: f64 = a.num("min-psnr", 40.0)?;
382+
383+ let probe = ffprobe(ref_path, "v:0", "width,height,pix_fmt")?;
384+ let pix = match a.flags.get("pix-fmt") {
385+ Some(v) => v.clone(),
386+ None => probe
387+ .get("pix_fmt")
388+ .cloned()
389+ .ok_or("could not probe pix_fmt; pass --pix-fmt")?,
390+ };
391+ let (w, h) = match a.flags.get("size") {
392+ Some(s) => {
393+ let (ws, hs) = s.split_once('x').ok_or("--size must look like 1920x1080")?;
394+ (
395+ ws.parse::<usize>().map_err(|_| "bad --size width")?,
396+ hs.parse::<usize>().map_err(|_| "bad --size height")?,
397+ )
398+ }
399+ None => (
400+ probe
401+ .get("width")
402+ .ok_or("could not probe width; pass --size")?
403+ .parse()
404+ .map_err(|_| "bad probed width".to_string())?,
405+ probe
406+ .get("height")
407+ .ok_or("could not probe height; pass --size")?
408+ .parse()
409+ .map_err(|_| "bad probed height".to_string())?,
410+ ),
411+ };
412+
413+ let geom = pix_geom(&pix, w, h)?;
414+ let frame_bytes = geom.samples * geom.bps;
415+ if frame_bytes == 0 {
416+ return Err("frame size computed as zero".into());
417+ }
418+
419+ let ours = read_file(ours_path)?;
420+ let reference = ffmpeg_raw(
421+ ref_path,
422+ &["-map", "0:v:0", "-f", "rawvideo", "-pix_fmt", &pix],
423+ )?;
424+ let (fa, fb) = (ours.len() / frame_bytes, reference.len() / frame_bytes);
425+ let frames = fa.min(fb);
426+
427+ println!("meta\tours\t{ours_path}");
428+ println!("meta\tref\t{ref_path}");
429+ println!("meta\tpix_fmt\t{pix}");
430+ println!("meta\tdims\t{w}x{h}");
431+ println!("meta\tframe_bytes\t{frame_bytes}");
432+ println!("meta\tframes_ours\t{fa}");
433+ println!("meta\tframes_ref\t{fb}");
434+ if frames == 0 {
435+ println!("verdict\tFAIL\tno complete frame in common");
436+ eprintln!("video-compare: FAIL — no complete frame in common ({fa} vs {fb})");
437+ return Ok(false);
438+ }
439+
440+ let luma_n = if geom.luma == 0 {
441+ geom.samples
442+ } else {
443+ geom.luma
444+ };
445+ let mut min_y = f64::INFINITY;
446+ let mut sum_y = 0.0;
447+ let mut min_all = f64::INFINITY;
448+ let mut sum_all = 0.0;
449+ let mut finite_y = 0usize;
450+ let mut finite_all = 0usize;
451+ for f in 0..frames {
452+ let off = f * geom.samples;
453+ let py = psnr(&ours, &reference, off, luma_n, geom.bps, geom.max);
454+ let pa = psnr(&ours, &reference, off, geom.samples, geom.bps, geom.max);
455+ min_y = min_y.min(py);
456+ min_all = min_all.min(pa);
457+ if py.is_finite() {
458+ sum_y += py;
459+ finite_y += 1;
460+ }
461+ if pa.is_finite() {
462+ sum_all += pa;
463+ finite_all += 1;
464+ }
465+ println!("frame\t{f}\tpsnr_y\t{py:.4}\tpsnr_all\t{pa:.4}");
466+ }
467+ // Mean over finite frames only: identical frames give +inf and would otherwise
468+ // poison the average of a run that also contains real differences.
469+ let mean_y = if finite_y == 0 {
470+ f64::INFINITY
471+ } else {
472+ sum_y / finite_y as f64
473+ };
474+ let mean_all = if finite_all == 0 {
475+ f64::INFINITY
476+ } else {
477+ sum_all / finite_all as f64
478+ };
479+ let len_ok = fa == fb;
480+ let pass = len_ok && min_y >= min_psnr;
481+ println!("stats\tpsnr_y\tmin\t{min_y:.4}\tmean\t{mean_y:.4}");
482+ println!("stats\tpsnr_all\tmin\t{min_all:.4}\tmean\t{mean_all:.4}");
483+ println!(
484+ "verdict\t{}\tmin_psnr_y={min_y:.4}\tframes={frames}\tlen_ok={len_ok}",
485+ if pass { "PASS" } else { "FAIL" }
486+ );
487+ eprintln!(
488+ "video-compare: {} — {frames} frames {w}x{h} {pix}, min luma PSNR {min_y:.4} dB \
489+ (>= {min_psnr}), mean {mean_y:.4} dB, frame counts {fa}/{fb}",
490+ if pass { "PASS" } else { "FAIL" }
491+ );
492+ Ok(pass)
493+}
494+
495+#[cfg(test)]
496+mod tests {
497+ use super::*;
498+
499+ #[test]
500+ fn corr_identical_and_inverted() {
501+ let a = [0.0, 1.0, -1.0, 0.5, -0.25];
502+ let inv: Vec<f64> = a.iter().map(|x| -x).collect();
503+ assert!((corr(&a, &a) - 1.0).abs() < 1e-12);
504+ assert!((corr(&a, &inv) + 1.0).abs() < 1e-12);
505+ // Silence vs silence correlates; silence vs DC offset does not.
506+ assert_eq!(corr(&[0.0; 4], &[0.0; 4]), 1.0);
507+ assert_eq!(corr(&[0.0; 4], &[1.0; 4]), 0.0);
508+ }
509+
510+ #[test]
511+ fn rms_and_peak_delta() {
512+ let (r, p) = rms_delta(&[0.0, 0.0, 0.0], &[0.0, 0.0, 0.0]);
513+ assert_eq!((r, p), (0.0, 0.0));
514+ let (r, p) = rms_delta(&[1.0, -1.0], &[0.0, 0.0]);
515+ assert!((r - 1.0).abs() < 1e-12 && (p - 1.0).abs() < 1e-12);
516+ }
517+
518+ #[test]
519+ fn psnr_identical_is_infinite_and_differing_is_finite() {
520+ let a = vec![10u8, 20, 30, 40];
521+ assert!(psnr(&a, &a, 0, 4, 1, 255.0).is_infinite());
522+ let b = vec![11u8, 21, 31, 41];
523+ let p = psnr(&a, &b, 0, 4, 1, 255.0);
524+ // MSE 1 over 8-bit range: 10*log10(255^2) = 48.13 dB.
525+ assert!((p - 48.1308).abs() < 1e-3, "psnr={p}");
526+ // 10-bit path reads little-endian u16 pairs.
527+ let x = [0u8, 1, 0, 1];
528+ let y = [1u8, 1, 0, 1];
529+ assert!(psnr(&x, &y, 0, 2, 2, 1023.0).is_finite());
530+ }
531+
532+ #[test]
533+ fn pix_geom_covers_the_generated_fixture_formats() {
534+ let (w, h) = (1920, 1080);
535+ let g = pix_geom("yuv420p", w, h).unwrap();
536+ assert_eq!(
537+ (g.samples, g.luma, g.bps, g.max),
538+ (w * h * 3 / 2, w * h, 1, 255.0)
539+ );
540+ let g = pix_geom("yuv420p10le", w, h).unwrap();
541+ assert_eq!(
542+ (g.samples, g.luma, g.bps, g.max),
543+ (w * h * 3 / 2, w * h, 2, 1023.0)
544+ );
545+ let g = pix_geom("p010le", w, h).unwrap();
546+ assert_eq!((g.samples, g.bps, g.max), (w * h * 3 / 2, 2, 1023.0));
547+ assert_eq!(pix_geom("yuv444p", w, h).unwrap().samples, w * h * 3);
548+ assert_eq!(pix_geom("yuyv422", w, h).unwrap().luma, 0);
549+ assert!(pix_geom("no_such_fmt", w, h).is_err());
550+ }
551+
552+ #[test]
553+ fn deinterleave_splits_channels() {
554+ let mut buf = Vec::new();
555+ for f in 0..3u32 {
556+ for c in 0..2u32 {
557+ buf.extend_from_slice(&((f * 10 + c) as f32).to_le_bytes());
558+ }
559+ }
560+ let ch = deinterleave_f32(&buf, 2);
561+ assert_eq!(ch[0], vec![0.0, 10.0, 20.0]);
562+ assert_eq!(ch[1], vec![1.0, 11.0, 21.0]);
563+ }
564+
565+ #[test]
566+ fn args_parse_flags_and_positionals() {
567+ let argv: Vec<String> = ["a.raw", "b.mp4", "--min-corr", "0.5"]
568+ .iter()
569+ .map(|s| s.to_string())
570+ .collect();
571+ let a = Args::parse(&argv).unwrap();
572+ assert_eq!(a.pos, ["a.raw", "b.mp4"]);
573+ assert_eq!(a.num::<f64>("min-corr", 0.999).unwrap(), 0.5);
574+ assert_eq!(a.num::<f64>("max-rms", 1e-3).unwrap(), 1e-3);
575+ assert!(Args::parse(&["--dangling".to_string()]).is_err());
576+ }
577+}
tools/oracle/tests/cli.rsadded+163 -0
@@ -0,0 +1,163 @@
1+//! Self-test of the `oracle` CLI itself: drives the built binary the way a codec
2+//! crate's test will, using ffmpeg as both the "our decoder" stand-in and the
3+//! reference. Exercises the PASS and the FAIL path of every subcommand.
4+//!
5+//! Fixture-gated: fixtures/ is gitignored, so a checkout without
6+//! `scripts/gen-fixtures.sh` run skips loudly instead of failing.
7+
8+use std::path::{Path, PathBuf};
9+use std::process::{Command, Stdio};
10+
11+fn fixtures() -> PathBuf {
12+ Path::new(env!("CARGO_MANIFEST_DIR"))
13+ .join("../../fixtures")
14+ .canonicalize()
15+ .unwrap_or_else(|_| PathBuf::from("/nonexistent"))
16+}
17+
18+// Per-test directory: the test binary runs its cases as threads of one process,
19+// so a pid-only name would let one case delete another's raw files.
20+fn workdir(name: &str) -> PathBuf {
21+ let d = std::env::temp_dir().join(format!("oracle-selftest-{}-{name}", std::process::id()));
22+ std::fs::create_dir_all(&d).unwrap();
23+ d
24+}
25+
26+/// Decode `input` to a raw file with ffmpeg — stands in for "our decoder's output".
27+fn decode_raw(input: &Path, out: &Path, extra: &[&str]) {
28+ let f = std::fs::File::create(out).unwrap();
29+ let st = Command::new("ffmpeg")
30+ .args(["-nostdin", "-y", "-v", "error", "-i"])
31+ .arg(input)
32+ .args(extra)
33+ .arg("-")
34+ .stdout(Stdio::from(f))
35+ .status()
36+ .expect("ffmpeg must be installed to run the oracle self-test");
37+ assert!(st.success(), "ffmpeg failed decoding {}", input.display());
38+}
39+
40+fn oracle(args: &[&str]) -> i32 {
41+ Command::new(env!("CARGO_BIN_EXE_oracle"))
42+ .args(args)
43+ .status()
44+ .expect("oracle binary")
45+ .code()
46+ .expect("oracle exited by signal")
47+}
48+
49+fn require(paths: &[PathBuf]) -> bool {
50+ for p in paths {
51+ if !p.is_file() {
52+ eprintln!(
53+ "SKIP: missing fixture {} — run scripts/gen-fixtures.sh",
54+ p.display()
55+ );
56+ return false;
57+ }
58+ }
59+ true
60+}
61+
62+const F32: &[&str] = &["-map", "0:a:0", "-f", "f32le", "-acodec", "pcm_f32le"];
63+
64+#[test]
65+fn bit_exact_passes_on_same_decode_and_fails_on_a_different_one() {
66+ let fx = fixtures();
67+ let a = fx.join("audio/flac-stereo-48000.flac");
68+ let b = fx.join("audio/flac-mono-48000.flac");
69+ if !require(&[a.clone(), b.clone()]) {
70+ return;
71+ }
72+ let w = workdir("bitexact");
73+ let (r1, r2, r3) = (w.join("a1.raw"), w.join("a2.raw"), w.join("b.raw"));
74+ decode_raw(&a, &r1, F32);
75+ decode_raw(&a, &r2, F32);
76+ decode_raw(&b, &r3, F32);
77+
78+ assert_eq!(
79+ oracle(&["bit-exact", r1.to_str().unwrap(), r2.to_str().unwrap()]),
80+ 0,
81+ "same file decoded twice must be bit-exact"
82+ );
83+ assert_eq!(
84+ oracle(&["bit-exact", r1.to_str().unwrap(), r3.to_str().unwrap()]),
85+ 1,
86+ "different fixtures must not be bit-exact"
87+ );
88+ let _ = std::fs::remove_dir_all(&w);
89+}
90+
91+#[test]
92+fn audio_compare_passes_against_its_own_source_and_fails_across_rates() {
93+ let fx = fixtures();
94+ let a = fx.join("audio/flac-stereo-48000.flac");
95+ let b = fx.join("audio/flac-stereo-44100.flac");
96+ if !require(&[a.clone(), b.clone()]) {
97+ return;
98+ }
99+ let w = workdir("audio");
100+ let (ra, rb) = (w.join("a.raw"), w.join("b.raw"));
101+ decode_raw(&a, &ra, F32);
102+ decode_raw(&b, &rb, F32);
103+
104+ assert_eq!(
105+ oracle(&["audio-compare", ra.to_str().unwrap(), a.to_str().unwrap()]),
106+ 0,
107+ "lossless decode vs its own source must correlate at 1.0"
108+ );
109+ // 44.1 kHz samples against a 48 kHz reference: wrong length and wrong phase.
110+ assert_eq!(
111+ oracle(&["audio-compare", rb.to_str().unwrap(), a.to_str().unwrap()]),
112+ 1,
113+ "a different-rate decode must be rejected"
114+ );
115+ let _ = std::fs::remove_dir_all(&w);
116+}
117+
118+#[test]
119+fn video_compare_passes_against_its_own_source_and_fails_on_frame_count() {
120+ let fx = fixtures();
121+ let a = fx.join("video/h264-1080p-23.976-8bit.mp4");
122+ let b = fx.join("video/h264-1080p-60-8bit.mp4");
123+ if !require(&[a.clone(), b.clone()]) {
124+ return;
125+ }
126+ let w = workdir("video");
127+ let raw = w.join("a.raw");
128+ decode_raw(
129+ &a,
130+ &raw,
131+ &["-map", "0:v:0", "-f", "rawvideo", "-pix_fmt", "yuv420p"],
132+ );
133+
134+ assert_eq!(
135+ oracle(&[
136+ "video-compare",
137+ raw.to_str().unwrap(),
138+ a.to_str().unwrap(),
139+ "--pix-fmt",
140+ "yuv420p",
141+ ]),
142+ 0,
143+ "decode vs its own source must be lossless (infinite PSNR)"
144+ );
145+ assert_eq!(
146+ oracle(&[
147+ "video-compare",
148+ raw.to_str().unwrap(),
149+ b.to_str().unwrap(),
150+ "--pix-fmt",
151+ "yuv420p",
152+ ]),
153+ 1,
154+ "48 frames against a 120-frame reference must fail"
155+ );
156+ let _ = std::fs::remove_dir_all(&w);
157+}
158+
159+#[test]
160+fn bad_usage_exits_two() {
161+ assert_eq!(oracle(&["no-such-subcommand"]), 2);
162+ assert_eq!(oracle(&["bit-exact", "only-one-arg"]), 2);
163+}