forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB4c07cbcTahinli2 months ago3583 commits

gen-bitstream-fixtures.sh128 lines, 5.4 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# (a2) H.264/HEVC elementary streams in Annex B form, for the hardware decoder:
58# a stateless decoder is fed NAL units, and the mp4 fixtures carry them
59# length-prefixed. `-bsf` puts the start codes and the in-band parameter sets back.
60for src in "$FIXTURES"/video/*h264*.mp4; do
61 [ -e "$src" ] || continue
62 base=$(basename "$src")
63 run "$OUT/${base%.*}.264" -i "$src" -map 0:v:0 -c:v copy -bsf:v h264_mp4toannexb -f h264
64done
65for src in "$FIXTURES"/video/*hevc*.mp4; do
66 [ -e "$src" ] || continue
67 base=$(basename "$src")
68 run "$OUT/${base%.*}.265" -i "$src" -map 0:v:0 -c:v copy -bsf:v hevc_mp4toannexb -f hevc
69done
70
71# (b) branch coverage the container set does not have.
72SYN="-f lavfi -i testsrc2=size=320x240:rate=30:duration=2"
73
74# VP9 superframes: a hidden ALTREF is packed with the next frame, and the frame
75# that finally shows it is a show_existing_frame header. libvpx only picks
76# alternate references in two-pass mode ("2-pass only" in its own option help),
77# so a single-pass encode here yields no superframe at all.
78if [ "$FORCE" = 1 ] || [ ! -s "$OUT/vp9-superframe-altref.ivf" ]; then
79 PASSLOG=$(mktemp -d)
80 # shellcheck disable=SC2086
81 ffmpeg -nostdin -y -v error $SYN -c:v libvpx-vp9 -pix_fmt yuv420p -b:v 300k \
82 -auto-alt-ref 1 -lag-in-frames 25 -cpu-used 5 \
83 -pass 1 -passlogfile "$PASSLOG/vp9" -f null - >"$TMPLOG" 2>&1
84 # shellcheck disable=SC2086
85 run "$OUT/vp9-superframe-altref.ivf" $SYN -c:v libvpx-vp9 -pix_fmt yuv420p -b:v 300k \
86 -auto-alt-ref 1 -lag-in-frames 25 -cpu-used 5 \
87 -pass 2 -passlogfile "$PASSLOG/vp9" -f ivf
88 rm -rf "$PASSLOG"
89else
90 echo "skip vp9-superframe-altref.ivf"
91fi
92# VP9 profile 1 (4:4:4 8-bit) and profile 3 (4:4:4 10-bit): the color_config
93# branches where subsampling_x/y are coded rather than assumed.
94# shellcheck disable=SC2086
95run "$OUT/vp9-profile1-444.ivf" $SYN -c:v libvpx-vp9 -pix_fmt yuv444p \
96 -cpu-used 5 -b:v 300k -f ivf
97# shellcheck disable=SC2086
98run "$OUT/vp9-profile3-444-10bit.ivf" $SYN -c:v libvpx-vp9 -pix_fmt yuv444p10le \
99 -cpu-used 5 -b:v 300k -f ivf
100# VP9 tiles: 4 tile columns needs a frame wide enough for log2_tile_cols > 0.
101run "$OUT/vp9-tiles-1280.ivf" -f lavfi -i testsrc2=size=1280x720:rate=30:duration=1 \
102 -c:v libvpx-vp9 -pix_fmt yuv420p -tile-columns 2 -cpu-used 5 -b:v 1M -f ivf
103
104# AV1 profile 1 (4:4:4) and monochrome, plus a multi-tile frame.
105# shellcheck disable=SC2086
106run "$OUT/av1-profile1-444.ivf" $SYN -c:v libaom-av1 -pix_fmt yuv444p \
107 -cpu-used 8 -b:v 300k -f ivf
108# shellcheck disable=SC2086
109run "$OUT/av1-monochrome.ivf" $SYN -c:v libaom-av1 -pix_fmt gray \
110 -cpu-used 8 -b:v 300k -f ivf
111run "$OUT/av1-tiles-1280.ivf" -f lavfi -i testsrc2=size=1280x720:rate=30:duration=1 \
112 -c:v libaom-av1 -pix_fmt yuv420p -tiles 2x2 -cpu-used 8 -b:v 1M -f ivf
113# H.264 with B frames and an open GOP: reordering, so the decoder's output order
114# is exercised rather than assumed, plus 4 reference frames for the DPB.
115# shellcheck disable=SC2086
116run "$OUT/h264-bframes-320.264" $SYN -c:v libx264 -pix_fmt yuv420p -bf 3 -refs 4 \
117 -g 30 -b:v 500k -f h264
118# HEVC with B frames, for the same reason on the reference-picture-set side.
119# shellcheck disable=SC2086
120run "$OUT/hevc-bframes-320.265" $SYN -c:v libx265 -pix_fmt yuv420p \
121 -x265-params "bframes=3:ref=3:keyint=30:log-level=none" -b:v 500k -f hevc
122
123# AV1 with a hidden ALTREF: forward keyframe + show_existing_frame headers.
124# shellcheck disable=SC2086
125run "$OUT/av1-altref.ivf" $SYN -c:v libaom-av1 -pix_fmt yuv420p \
126 -lag-in-frames 25 -cpu-used 6 -b:v 300k -f ivf
127
128exit $fail