forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

seed.sh63 lines, 2.2 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# seed.sh: fill fuzz/corpus/<target>/ with TrueHD/MLP seeds.
3#
4# There are no TrueHD fixtures in the repo, so the seeds are generated with ffmpeg's
5# truehd and mlp encoders: stereo, 2.1, 5.1 and mono MLP, 1 s of sine each.
6# (Any *thd*, *truehd* or *mlp* file under the root fixtures/ is also used when present.)
7#
8# decode_stream gets each stream as-is (elementary stream of access units).
9# parse_sync gets the first access unit of each stream (its header and major sync).
10#
11# Corpus lives under fuzz/corpus, which is git-ignored.
12set -euo pipefail
13
14FUZZ_DIR=$(cd -- "$(dirname -- "$0")" && pwd)
15ROOT=$(cd -- "$FUZZ_DIR/../../.." && pwd)
16FIXTURES="$ROOT/fixtures"
17
18STREAM_DIR="$FUZZ_DIR/corpus/decode_stream"
19SYNC_DIR="$FUZZ_DIR/corpus/parse_sync"
20mkdir -p "$STREAM_DIR" "$SYNC_DIR"
21
22GEN=$(mktemp -d "${TMPDIR:-$HOME}/ec-truehd-seed.XXXXXX")
23trap 'rm -rf "$GEN"' EXIT
24
25command -v ffmpeg >/dev/null || { echo "seed.sh: ffmpeg not found" >&2; exit 2; }
26gen() { # name channels codec muxer
27 ffmpeg -hide_banner -loglevel error -y -f lavfi -i "sine=frequency=440:duration=1" \
28 -ac "$2" -c:a "$3" -strict -2 -t 1 -f "$4" "$GEN/$1"
29}
30gen stereo.thd 2 truehd truehd
31gen 51.thd 6 truehd truehd
32gen 21.thd 3 truehd truehd
33gen mono.mlp 1 mlp mlp
34
35# Repo fixtures, if the root fixtures/ directory is linked in this worktree.
36if [ -d "$FIXTURES" ]; then
37 find "$FIXTURES" -type f \( -iname '*thd*' -o -iname '*truehd*' -o -iname '*mlp*' \) \
38 -exec cp {} "$GEN/" \; 2>/dev/null || true
39fi
40
41python3 -I - "$GEN" "$STREAM_DIR" "$SYNC_DIR" <<'PY'
42import glob, os, shutil, sys
43
44gen_dir, stream_dir, sync_dir = sys.argv[1], sys.argv[2], sys.argv[3]
45
46def first_au(data):
47 """Bytes of the first access unit: 12-bit word length, in 16-bit words."""
48 if len(data) < 2:
49 return b""
50 n = ((data[0] << 8) | data[1]) & 0x0FFF
51 return data[: n * 2]
52
53count = 0
54for path in sorted(glob.glob(os.path.join(gen_dir, "*"))):
55 name = os.path.basename(path)
56 data = open(path, "rb").read()
57 shutil.copy(path, os.path.join(stream_dir, name))
58 au = first_au(data)
59 if au:
60 open(os.path.join(sync_dir, name), "wb").write(au)
61 count += 1
62print(f"seeded {count} streams: {len(os.listdir(stream_dir))} decode_stream, {len(os.listdir(sync_dir))} parse_sync")
63PY