forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBe12d32fTahinli6 days ago3982 commits

gen_vp8_fixtures.sh123 lines, 5.5 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# Generate the ec-vp8 test fixtures (gitignored, like the rest of the
3# workspace's fixtures/). Every vector is libvpx-encoded via ffmpeg; the
4# decoder's witnesses compare its raw YUV output against ffmpeg's.
5#
6# Usage: scripts/gen_vp8_fixtures.sh [worktree-root]
7set -euo pipefail
8ROOT="${1:-$(cd "$(dirname "$0")/.." && pwd)}"
9OUT="$ROOT/fixtures/vp8"
10mkdir -p "$OUT"
11
12enc() { # name size frames q extra-source-args...
13 local name=$1 size=$2 frames=$3 q=$4
14 shift 4
15 ffmpeg -hide_banner -loglevel error -y \
16 -f lavfi -i "$@" \
17 -frames:v "$frames" -c:v libvpx -qmin "$q" -qmax "$q" -crf "$q" \
18 -auto-alt-ref 0 -cpu-used 1 -g "$frames" \
19 "$OUT/$name.ivf"
20 echo "wrote $OUT/$name.ivf"
21}
22
23# Key-frame vectors (M2): several sizes incl. non-multiple-of-16, several q.
24enc kf-160x96-q20 160x96 4 20 testsrc2=size=160x96:rate=30
25enc kf-160x96-q40 160x96 4 40 testsrc2=size=160x96:rate=30
26enc kf-76x52-q30 76x52 4 30 testsrc2=size=76x52:rate=30
27enc kf-32x16-q35 32x16 4 35 testsrc2=size=32x16:rate=30
28enc kf-172x144-q25 172x144 4 25 testsrc2=size=172x144:rate=30
29enc kf-96x80-q63 96x80 4 63 testsrc2=size=96x80:rate=30
30
31# Multi-frame GOP (M3): keyframe + interframes, golden/altref in play.
32ffmpeg -hide_banner -loglevel error -y \
33 -f lavfi -i testsrc2=size=160x96:rate=30 \
34 -frames:v 60 -c:v libvpx -qmin 30 -qmax 45 -crf 38 \
35 -auto-alt-ref 0 -g 15 -keyint_min 15 -cpu-used 1 -lag-in-frames 0 \
36 "$OUT/gop-160x96.ivf"
37echo "wrote $OUT/gop-160x96.ivf"
38
39# Larger short GOP with the simple loop filter via profile (version 1)?
40# libvpx picks profile 0 normally; the version field is exercised through
41# -profile:v 1 (simple filter, bilinear reconstruction).
42ffmpeg -hide_banner -loglevel error -y \
43 -f lavfi -i testsrc2=size=96x80:rate=30 \
44 -frames:v 12 -c:v libvpx -qmin 30 -qmax 30 -crf 30 -auto-alt-ref 0 -g 6 \
45 -profile:v 1 -cpu-used 1 -lag-in-frames 0 \
46 "$OUT/gop-96x80-v1.ivf" 2>/dev/null || \
47 echo "SKIP gop-96x80-v1 (profile 1 unsupported by this libvpx build)"
48
49# Multi-partition token partitions (M3): ffmpeg's libvpx wrapper has no
50# token-part option, so this one vector comes from a locally built vpxenc
51# (checked out at ~/.cache/vp8/libvpx-src; `./configure && make -j`).
52VPXENC="$HOME/.cache/vp8/libvpx-src/vpxenc"
53if [ -x "$VPXENC" ]; then
54 ffmpeg -hide_banner -loglevel error -y \
55 -f lavfi -i testsrc2=size=160x96:rate=30 -frames:v 30 \
56 -pix_fmt yuv420p -f rawvideo /tmp/ecvp8-mparts.raw
57 { printf 'YUV4MPEG2 W160 H96 F30:1 Ip A1:1 C420jpeg\n'
58 python3 - <<'PYEOF'
59raw = open("/tmp/ecvp8-mparts.raw", "rb").read()
60frame = 160 * 96 * 3 // 2
61for i in range(len(raw) // frame):
62 open("/dev/stdout", "wb").write(b"FRAME\n" + raw[i*frame:(i+1)*frame])
63PYEOF
64 } | "$VPXENC" --codec=vp8 -w 160 -h 96 --token-parts=3 --limit=30 \
65 --ivf --cpu-used=1 --end-usage=q --cq-level=32 --min-q=30 --max-q=45 \
66 --kf-max-dist=10 -o "$OUT/mparts-160x96.ivf" - 2>/dev/null
67 echo "wrote $OUT/mparts-160x96.ivf"
68else
69 echo "SKIP mparts (build libvpx at ~/.cache/vp8/libvpx-src for vpxenc)"
70fi
71
72# VP8-in-WebP still (same key-frame payload in a RIFF container).
73ffmpeg -hide_banner -loglevel error -y \
74 -f lavfi -i testsrc2=size=96x80:rate=30 -frames:v 1 \
75 "$OUT/still.png"
76if ffmpeg -hide_banner -loglevel error -y -i "$OUT/still.png" -q:v 60 "$OUT/still.webp" 2>/dev/null; then
77 echo "wrote $OUT/still.webp"
78else
79 echo "SKIP still.webp (libwebp support missing)"
80 rm -f "$OUT/still.png"
81fi
82
83# Note on the three vectors below (review flag): every fixture in the set
84# must come from THIS script — no ad-hoc leftovers.
85#
86# kf-16x16-black-q0: 1-MB all-black frame at q0 (the M2 "no ONE tokens"
87# degenerate vector: exercises the zero-coefficient and overread paths).
88enc kf-16x16-black-q0 16x16 1 0 color=black:size=16x16:rate=30
89
90# clip-obs-320x192: screen-content-shaped 320x192 clip. The original was
91# an OBS window capture; the recorded reproducible stand-in is testsrc2
92# at the same size (same decoder paths: 20x12 MB grid, small-MV motion).
93enc clip-obs-320x192 320x192 169 28 testsrc2=size=320x192:rate=30
94
95# altref-160x96: vpxenc --auto-alt-ref=1 in TWO passes (one-pass CQ/VBR
96# never inserts hidden altrefs for this content) with --lag-in-frames, so
97# libvpx emits HIDDEN alternate-reference frames (frame tag show_frame=0,
98# currently 6 of 90 at decode indices 1,17,33,49,65,81). The witnesses
99# census the tags and refuse a shown-only stream: the hidden-frame
100# contract (no output, reference buffers still update, later frames
101# reference the hidden altref) must be exercised.
102ffmpeg -hide_banner -loglevel error -y \
103 -f lavfi -i testsrc2=size=160x96:rate=30 -frames:v 90 \
104 -pix_fmt yuv420p -f rawvideo /tmp/ecvp8-altref.raw
105# Two passes need a seekable input (stdin cannot rewind for pass 2), so
106# the y4m goes through a temp FILE, not a pipe.
107{ printf 'YUV4MPEG2 W160 H96 F30:1 Ip A1:1 C420jpeg\n'
108 cat /tmp/ecvp8-altref.raw | python3 -c '
109import sys
110raw = sys.stdin.buffer.read()
111frame = 160 * 96 * 3 // 2
112for i in range(len(raw) // frame):
113 sys.stdout.buffer.write(b"FRAME\n" + raw[i*frame:(i+1)*frame])
114' > /tmp/ecvp8-altref.y4m
115}
116"$VPXENC" --codec=vp8 -w 160 -h 96 --limit=90 --ivf --cpu-used=1 \
117 --end-usage=vbr --target-bitrate=400 --kf-max-dist=15 \
118 --auto-alt-ref=1 --lag-in-frames=15 --passes=2 --fpf=/tmp/ecvp8-altref.fpf \
119 --quiet -o "$OUT/altref-160x96.ivf" /tmp/ecvp8-altref.y4m
120rm -f /tmp/ecvp8-altref.raw /tmp/ecvp8-altref.y4m /tmp/ecvp8-altref.fpf
121echo "wrote $OUT/altref-160x96.ivf"
122
123ls -la "$OUT"