forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB30d372eTahinli3 months ago42 commits

gen-bitstream-fixtures.sh104 lines, 4.2 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# gen-bitstream-fixtures.sh — raw VP9/AV1 elementary streams for the syntax crates.
3#
4# ffmpeg is ORACLE/test-input tooling only; no ec-* crate depends on it at runtime.
5# Two sources: (a) the container fixtures from gen-fixtures.sh, remuxed to IVF so a
6# header parser sees the elementary stream with no container in the way, and (b)
7# small purpose-built clips for the header branches the 4:2:0 8/10-bit set never
8# reaches — VP9 superframes with a hidden ALTREF plus show_existing_frame, 4:4:4
9# (VP9 profile 1/3, AV1 profile 1), monochrome AV1, multi-tile AV1.
10#
11# Idempotent: non-empty outputs are skipped, partial outputs are deleted on failure.
12#
13# Usage: scripts/gen-bitstream-fixtures.sh [-f] (-f: regenerate everything)
14# Env: EC_FIXTURES=<dir> (default <repo>/fixtures)
15
16set -uo pipefail
17
18ROOT=$(cd -- "$(dirname -- "$0")/.." && pwd)
19FIXTURES=${EC_FIXTURES:-$ROOT/fixtures}
20OUT=$FIXTURES/bitstreams
21FORCE=0
22[ "${1:-}" = "-f" ] && FORCE=1
23
24command -v ffmpeg >/dev/null || { echo "gen-bitstream-fixtures: ffmpeg not found" >&2; exit 2; }
25
26mkdir -p "$OUT" || exit 2
27TMPLOG=$(mktemp) || exit 2
28trap 'rm -f "$TMPLOG"' EXIT
29
30fail=0
31
32# run <output> <ffmpeg args...>
33run() {
34 local out=$1
35 shift
36 if [ "$FORCE" = 0 ] && [ -s "$out" ]; then
37 echo "skip $(basename "$out")"
38 return 0
39 fi
40 if ffmpeg -nostdin -y -v error "$@" "$out" >"$TMPLOG" 2>&1 && [ -s "$out" ]; then
41 echo "ok $(basename "$out")"
42 else
43 echo "FAIL $(basename "$out")" >&2
44 sed 's/^/ /' "$TMPLOG" >&2
45 rm -f "$out"
46 fail=1
47 fi
48}
49
50# (a) remux every VP9/AV1 container fixture into IVF, keeping the codec bytes.
51for src in "$FIXTURES"/video/*vp9*.mp4 "$FIXTURES"/video/*av1*.mp4; do
52 [ -e "$src" ] || continue
53 base=$(basename "$src")
54 run "$OUT/${base%.*}.ivf" -i "$src" -map 0:v:0 -c:v copy -f ivf
55done
56
57# (b) branch coverage the container set does not have.
58SYN="-f lavfi -i testsrc2=size=320x240:rate=30:duration=2"
59
60# VP9 superframes: a hidden ALTREF is packed with the next frame, and the frame
61# that finally shows it is a show_existing_frame header. libvpx only picks
62# alternate references in two-pass mode ("2-pass only" in its own option help),
63# so a single-pass encode here yields no superframe at all.
64if [ "$FORCE" = 1 ] || [ ! -s "$OUT/vp9-superframe-altref.ivf" ]; then
65 PASSLOG=$(mktemp -d)
66 # shellcheck disable=SC2086
67 ffmpeg -nostdin -y -v error $SYN -c:v libvpx-vp9 -pix_fmt yuv420p -b:v 300k \
68 -auto-alt-ref 1 -lag-in-frames 25 -cpu-used 5 \
69 -pass 1 -passlogfile "$PASSLOG/vp9" -f null - >"$TMPLOG" 2>&1
70 # shellcheck disable=SC2086
71 run "$OUT/vp9-superframe-altref.ivf" $SYN -c:v libvpx-vp9 -pix_fmt yuv420p -b:v 300k \
72 -auto-alt-ref 1 -lag-in-frames 25 -cpu-used 5 \
73 -pass 2 -passlogfile "$PASSLOG/vp9" -f ivf
74 rm -rf "$PASSLOG"
75else
76 echo "skip vp9-superframe-altref.ivf"
77fi
78# VP9 profile 1 (4:4:4 8-bit) and profile 3 (4:4:4 10-bit): the color_config
79# branches where subsampling_x/y are coded rather than assumed.
80# shellcheck disable=SC2086
81run "$OUT/vp9-profile1-444.ivf" $SYN -c:v libvpx-vp9 -pix_fmt yuv444p \
82 -cpu-used 5 -b:v 300k -f ivf
83# shellcheck disable=SC2086
84run "$OUT/vp9-profile3-444-10bit.ivf" $SYN -c:v libvpx-vp9 -pix_fmt yuv444p10le \
85 -cpu-used 5 -b:v 300k -f ivf
86# VP9 tiles: 4 tile columns needs a frame wide enough for log2_tile_cols > 0.
87run "$OUT/vp9-tiles-1280.ivf" -f lavfi -i testsrc2=size=1280x720:rate=30:duration=1 \
88 -c:v libvpx-vp9 -pix_fmt yuv420p -tile-columns 2 -cpu-used 5 -b:v 1M -f ivf
89
90# AV1 profile 1 (4:4:4) and monochrome, plus a multi-tile frame.
91# shellcheck disable=SC2086
92run "$OUT/av1-profile1-444.ivf" $SYN -c:v libaom-av1 -pix_fmt yuv444p \
93 -cpu-used 8 -b:v 300k -f ivf
94# shellcheck disable=SC2086
95run "$OUT/av1-monochrome.ivf" $SYN -c:v libaom-av1 -pix_fmt gray \
96 -cpu-used 8 -b:v 300k -f ivf
97run "$OUT/av1-tiles-1280.ivf" -f lavfi -i testsrc2=size=1280x720:rate=30:duration=1 \
98 -c:v libaom-av1 -pix_fmt yuv420p -tiles 2x2 -cpu-used 8 -b:v 1M -f ivf
99# AV1 with a hidden ALTREF: forward keyframe + show_existing_frame headers.
100# shellcheck disable=SC2086
101run "$OUT/av1-altref.ivf" $SYN -c:v libaom-av1 -pix_fmt yuv420p \
102 -lag-in-frames 25 -cpu-used 6 -b:v 300k -f ivf
103
104exit $fail