forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB2bbef8bTahinli3 months ago1573 commits

fetch-vectors.sh216 lines, 8.5 KiBHistoryRawDownload
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
13set -uo pipefail
14
15ROOT=$(cd -- "$(dirname -- "$0")/.." && pwd)
16VEC=${EC_FIXTURES:-$ROOT/fixtures}/vectors
17SUMS=$ROOT/scripts/vectors.sha256
18CURL=(curl -fsSL --retry 2 --retry-delay 2 --connect-timeout 20 --max-time 900)
19
20command -v curl >/dev/null || { echo "fetch-vectors: curl not found" >&2; exit 2; }
21mkdir -p -- "$VEC"
22touch -- "$SUMS"
23
24ok_sets=()
25fail_sets=()
26n_new=0
27n_have=0
28n_bad=0
29
30# verify_or_record <abs-file> — checksum against scripts/vectors.sha256, or record it.
31verify_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.
47fetch_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.
74fetch_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).
95extract_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
113run_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.
123JVT_BASE=https://www.itu.int/wftp3/av-arch/jvt-site/draft_conformance/AVCv1
124JVT_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.
140HEVC_BASE=https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/HEVC_v1
141HEVC_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).
158VORBIS_BASE=https://people.xiph.org/~xiphmont/test-vectors/vorbis
159VORBIS_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
168SETS=("$@")
169[ "${#SETS[@]}" -eq 0 ] && SETS=(h264-jvt hevc-jctvc opus-rfc6716 flac-xiph vorbis-xiph)
170
171for 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
202done
203
204printf '\n%s\n' "== vectors: $VEC =="
205for 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)"
210done
211for s in "${fail_sets[@]:-}"; do
212 [ -n "$s" ] && printf 'FAILED %-14s (network or dead URL — rerun to resume)\n' "$s"
213done
214printf '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 ]