forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

gen-ac3dep-fixtures.sh58 lines, 3.2 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# gen-ac3dep-fixtures.sh: E-AC-3 dependent-substream fixtures for crates/ec-ac3 (root fixtures/audio).
3#
4# ffmpeg's E-AC-3 encoder stops at 5.1, so the 7.1 fixtures are spliced: an ffmpeg 5.1 encode
5# as the independent substream, and an ffmpeg stereo encode whose frames become dependent
6# substreams (scripts/splice-eac3-dependent.py). Outputs:
7# ac3dep-src-5.1.eac3 independent source (ffmpeg decodes it: the 5.1 reference)
8# ac3dep-src-2.0.eac3 dependent source (ffmpeg decodes it: the 2.0 reference)
9# ac3dep-7.1-48000.eac3 5.1 + dependent Lrs/Rrs (chanmap 0x0200) -> 8 channels, "7.1": BL/BR appended
10# ac3dep-7.1wide-48000.eac3 5.1 + dependent Lc/Rc (chanmap 0x0400) -> 8 channels, "7.1(wide-side)"
11# ac3dep-repl-48000.eac3 5.1 + dependent Ls/Rs (chanmap 0x1800) -> 6 channels, "5.1(side)": the
12# dependent replaces the core's Ls/Rs (ffmpeg's placement rule, see dependent.rs)
13# Chanmaps are Table E2.5 as a 16-bit value, bit 15 first (see crates/ec-ac3/src/dependent.rs).
14# The ac3dep-* names keep these out of decode_matrix's ac3-/eac3- sweep, which decodes one
15# syncframe at a time and so cannot read packets that carry a dependent substream.
16#
17# Usage: scripts/gen-ac3dep-fixtures.sh [--force]
18set -euo pipefail
19
20ROOT=$(cd -- "$(dirname -- "$0")/.." && pwd)
21OUT="$ROOT/fixtures/audio"
22TMP=${TMPDIR:-$HOME/.cache}/ac3dep-gen
23FORCE=0
24[ "${1:-}" = "--force" ] && FORCE=1
25command -v ffmpeg >/dev/null || { echo "gen-ac3dep: ffmpeg not found" >&2; exit 2; }
26mkdir -p "$OUT" "$TMP"
27
28# sine_inputs <freq...>: one lavfi sine input per frequency (3 s at 48 kHz), one argument per line.
29sine_inputs() {
30 local f
31 for f in "$@"; do
32 printf '%s\n' -f lavfi -i "sine=frequency=${f}:sample_rate=48000:duration=3"
33 done
34}
35
36if [ "$FORCE" -eq 1 ] || [ ! -s "$OUT/ac3dep-src-5.1.eac3" ]; then
37 # 5.1 order is FL FR FC LFE SL SR (ffmpeg labels AC-3 3/2 as side). The side pair (1100, 1500 Hz) is
38 # distinct from the dependent stereo pair (880, 1320 Hz), so a placement error shows up in the comparison.
39 mapfile -t A < <(sine_inputs 220 440 660 55 1100 1500)
40 ffmpeg -nostdin -y -v error "${A[@]}" \
41 -filter_complex "[0:a][1:a][2:a][3:a][4:a][5:a]amerge=inputs=6,channelmap=channel_layout=5.1" \
42 -c:a eac3 -b:a 640k -f eac3 "$OUT/ac3dep-src-5.1.eac3"
43fi
44if [ "$FORCE" -eq 1 ] || [ ! -s "$OUT/ac3dep-src-2.0.eac3" ]; then
45 mapfile -t B < <(sine_inputs 880 1320)
46 ffmpeg -nostdin -y -v error "${B[@]}" \
47 -filter_complex "[0:a][1:a]amerge=inputs=2,channelmap=channel_layout=stereo" \
48 -c:a eac3 -b:a 192k -f eac3 "$OUT/ac3dep-src-2.0.eac3"
49fi
50CONVSNR="$ROOT/scripts/ac3dep-src-2.0.convsnr.txt"
51python3 -I "$ROOT/scripts/splice-eac3-dependent.py" "$OUT/ac3dep-src-5.1.eac3" \
52 "$OUT/ac3dep-src-2.0.eac3" 0200 "$OUT/ac3dep-7.1-48000.eac3" "$CONVSNR"
53python3 -I "$ROOT/scripts/splice-eac3-dependent.py" "$OUT/ac3dep-src-5.1.eac3" \
54 "$OUT/ac3dep-src-2.0.eac3" 0400 "$OUT/ac3dep-7.1wide-48000.eac3" "$CONVSNR"
55python3 -I "$ROOT/scripts/splice-eac3-dependent.py" "$OUT/ac3dep-src-5.1.eac3" \
56 "$OUT/ac3dep-src-2.0.eac3" 1800 "$OUT/ac3dep-repl-48000.eac3" "$CONVSNR"
57rm -rf -- "$TMP"
58echo "gen-ac3dep: wrote ac3dep-{src-5.1,src-2.0,7.1,7.1wide,repl} under $OUT"