forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

gen_fixtures.sh857 lines, 52.3 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# Regenerates the gitignored test fixtures under assets/.
3# Needs the ffmpeg CLI (dev tool only — the app itself never uses ffmpeg).
4set -euo pipefail
5cd "$(dirname "$0")/.."
6mkdir -p assets
7ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=5 \
8 -c:v libx264 -profile:v baseline -pix_fmt yuv420p assets/test_baseline.mp4
9ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=5 \
10 -c:v libx264 -profile:v high -pix_fmt yuv420p assets/test_high.mp4
11# A/V fixture: video + stereo AAC. Left channel 440 Hz, right 880 Hz, so
12# channel mapping mistakes are audible; 1 Hz volume pulse makes drift visible.
13ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=5 \
14 -f lavfi -i "sine=frequency=440:duration=5" \
15 -f lavfi -i "sine=frequency=880:duration=5" \
16 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
17 -map 0:v -map "[a]" -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
18 -c:a aac -b:a 128k assets/test_av.mp4
19# Second A/V fixture for multi-file import: same properties as test_av.mp4
20# (1280x720@30 baseline, AAC-LC 44.1k stereo) but plainly different content —
21# testsrc pattern, 4 s, an octave up (660/1320 Hz) with the same 1 Hz pulse.
22ffmpeg -y -f lavfi -i testsrc=size=1280x720:rate=30:duration=4 \
23 -f lavfi -i "sine=frequency=660:duration=4" \
24 -f lavfi -i "sine=frequency=1320:duration=4" \
25 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
26 -map 0:v -map "[a]" -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
27 -c:a aac -b:a 128k assets/test_av2.mp4
28# Multi-audio fixture: one video and three audio streams, so stream selection
29# has something to select. Stream 0 is AAC 44.1k stereo (440 Hz left, 880 Hz
30# right), stream 1 is AAC 22.05k mono 220 Hz tagged French — different rate,
31# layout and content, so a test can tell which stream it was handed — and
32# stream 2 is AC-3, the codec we cannot decode and must still list.
33ffmpeg -y -f lavfi -i testsrc2=size=320x240:rate=30:duration=2 \
34 -f lavfi -i "sine=frequency=440:duration=2" \
35 -f lavfi -i "sine=frequency=880:duration=2" \
36 -f lavfi -i "sine=frequency=220:duration=2" \
37 -f lavfi -i "sine=frequency=330:duration=2" \
38 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo[a0]" \
39 -map 0:v -map "[a0]" -map 3:a -map 4:a \
40 -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
41 -c:a:0 aac -ar:a:0 44100 -ac:a:0 2 \
42 -c:a:1 aac -ar:a:1 22050 -ac:a:1 1 \
43 -c:a:2 ac3 -ar:a:2 44100 -ac:a:2 2 \
44 -metadata:s:a:1 language=fra assets/test_multiaudio.mp4
45# Unsupported-audio fixture: an AC-3 track, which we cannot decode at all. The
46# file plays as picture with silence, and the point is that it says so.
47ffmpeg -y -f lavfi -i testsrc2=size=320x180:rate=30:duration=2 \
48 -f lavfi -i "sine=frequency=440:duration=2" \
49 -map 0:v -map 1:a -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
50 -c:a ac3 -b:a 192k assets/test_ac3.mp4
51# The shape a BluRay remux has: 48 kHz 5.1 AC-3, which the decoder downmixes to
52# stereo for the timeline. The mono fixture above is the other end of the same
53# path — no downmix at all — and both have to work.
54ffmpeg -y -f lavfi -i testsrc2=size=320x180:rate=30:duration=2 \
55 -f lavfi -i "sine=frequency=440:duration=2:sample_rate=48000" \
56 -map 0:v -map 1:a -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
57 -ac 6 -c:a ac3 -b:a 448k assets/test_ac3_51.mp4
58# Multi-language fixture: the shape real media has — one video and two AAC
59# streams that *agree* on rate and layout (44.1k stereo) and differ only in
60# language and content, 440/880 Hz undefined and 220/330 Hz French. One
61# timeline means one set of audio parameters, so this is the file where the
62# second stream can actually be put on the timeline; test_multiaudio.mp4 is the
63# file where it cannot, and both cases have to be shown.
64ffmpeg -y -f lavfi -i testsrc2=size=320x240:rate=30:duration=2 \
65 -f lavfi -i "sine=frequency=440:duration=2" \
66 -f lavfi -i "sine=frequency=880:duration=2" \
67 -f lavfi -i "sine=frequency=220:duration=2" \
68 -f lavfi -i "sine=frequency=330:duration=2" \
69 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo[a0];\
70[3:a][4:a]join=inputs=2:channel_layout=stereo[a1]" \
71 -map 0:v -map "[a0]" -map "[a1]" \
72 -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
73 -c:a aac -ar 44100 -ac 2 \
74 -metadata:s:a:1 language=fra assets/test_multilang.mp4
75# VP9 fixture: the same A/V shape as test_av.mp4 (1280x720@30, AAC-LC 44.1k
76# stereo) with a VP9 picture, so what the tests measure is the codec and
77# nothing else. 2 s, because VP9 only ever decodes on the hardware path.
78ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
79 -f lavfi -i "sine=frequency=440:duration=2" \
80 -f lavfi -i "sine=frequency=880:duration=2" \
81 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
82 -map 0:v -map "[a]" -c:v libvpx-vp9 -b:v 2M -pix_fmt yuv420p \
83 -c:a aac -b:a 128k assets/test_vp9.mp4
84# The same VP9 stream in Matroska, which is where a yt-dlp download and every
85# other VP9 file in the wild actually arrives: `V_VP9` used to fall through the
86# mkv track dispatch and be refused by name while the mp4 twin above decoded.
87# Opus audio because that is what a .webm carries -- the sound decodes here now
88# (`ec-opus`), and this is the webm cell of the Opus row in `capability_matrix`.
89ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
90 -f lavfi -i "sine=frequency=440:duration=2" \
91 -c:v libvpx-vp9 -b:v 2M -g 30 -pix_fmt yuv420p \
92 -c:a libopus -b:a 96k assets/test_vp9.webm
93# ...and profile 2, 10-bit, which no container states: an mkv `TrackEntry`
94# carries no configuration record for VP9 at all and the `vpcC` in an mp4 is
95# optional, so the depth is read off the keyframe's uncompressed header
96# (`demux::vp9_bit_depth`) -- the difference between a P010 surface pool and a
97# picture of garbage.
98ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
99 -c:v libvpx-vp9 -b:v 2M -g 30 -profile:v 2 -pix_fmt yuv420p10le \
100 -an assets/test_vp9_10.webm
101# VP8 fixture pair, the twins of the VP9 ones. ffmpeg's mov muxer carries no
102# VP8 tag for mp4 at all (and its VP9 path re-parses the frames it is handed,
103# dropping them), so the mp4 half is assembled by hand: the picture is encoded
104# to an IVF, the AAC sound to an mp4 of its own, and the video track is
105# spliced in with the `vp08` sample entry written out byte for byte -- the
106# very entry `demux::sample_entry` reads by hand, which is what this fixture
107# exists to exercise. `-enc_time_base 1/30` keeps the IVF timestamps exact,
108# which is what the mp4 stts and the 30 fps the tests assert come from.
109ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
110 -c:v libvpx -b:v 2M -g 30 -enc_time_base 1/30 -pix_fmt yuv420p -an \
111 assets/.test_vp8.ivf
112ffmpeg -y -f lavfi -i "sine=frequency=440:duration=2" \
113 -f lavfi -i "sine=frequency=880:duration=2" \
114 -filter_complex "[0:a][1:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
115 -map "[a]" -c:a aac -b:a 128k assets/.test_vp8_audio.mp4
116python3 - <<'SPLICE'
117import struct
118
119def boxes(buf, start, end):
120 res, at = [], start
121 while at + 8 <= end:
122 size = int.from_bytes(buf[at:at + 4], 'big')
123 hdr = 8
124 if size == 1:
125 size = int.from_bytes(buf[at + 8:at + 16], 'big')
126 hdr = 16
127 if size == 0:
128 size = end - at
129 res.append((bytes(buf[at + 4:at + 8]), at, at + size, at + hdr))
130 at += size
131 return res
132
133def box(typ, payload):
134 return struct.pack('>I', 8 + len(payload)) + typ + payload
135
136def full(typ, ver_flags, payload):
137 return box(typ, struct.pack('>I', ver_flags) + payload)
138
139ivf = open('assets/.test_vp8.ivf', 'rb').read()
140assert ivf[:4] == b'DKIF'
141frames, at = [], 32
142while at + 12 <= len(ivf):
143 (n,) = struct.unpack_from('<I', ivf, at)
144 frames.append(ivf[at + 12:at + 12 + n])
145 at += 12 + n
146assert len(frames) == 60, len(frames)
147video = b''.join(frames)
148
149data = bytearray(open('assets/.test_vp8_audio.mp4', 'rb').read())
150top = boxes(data, 0, len(data))
151mdat = next(b for b in top if b[0] == b'mdat')
152moov = next(b for b in top if b[0] == b'moov')
153mvhd = next(b for b in boxes(data, moov[3], moov[2]) if b[0] == b'mvhd')
154assert data[mvhd[3]] == 0
155movie_ts = int.from_bytes(data[mvhd[3] + 12:mvhd[3] + 16], 'big')
156next_id = int.from_bytes(data[mvhd[3] + 96:mvhd[3] + 100], 'big')
157TIMESCALE, DELTA = 15360, 512 # exact 30 fps
158vid_dur = len(frames) * DELTA
159movie_dur = vid_dur * movie_ts // TIMESCALE
160old_dur = int.from_bytes(data[mvhd[3] + 16:mvhd[3] + 20], 'big')
161assert movie_dur >= old_dur, 'video shorter than audio'
162splice_at = moov[1] # the video bytes go in right here, inside mdat
163
164UNITY = struct.pack('>9I', 0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0x40000000)
165entry = box(b'vp08',
166 b'\0' * 6 + struct.pack('>H', 1) # resv, data ref index
167 + struct.pack('>HHI', 0, 0, 0) # pre_def, resv, pre_def
168 + struct.pack('>HH', 1280, 720) # width, height
169 + struct.pack('>II', 0x480000, 0x480000) # 72 dpi resolutions
170 + b'\0' * 12 + struct.pack('>H', 1) # resv, frame_count
171 + b'\0' * 32 # compressorname
172 + struct.pack('>HH', 0x18, 0xFFFF)) # depth, pre_defined
173assert len(entry) == 86
174stco = bytearray(full(b'stco', 0, struct.pack('>II', 1, splice_at)))
175tkhd = full(b'tkhd', 3,
176 struct.pack('>IIIII', 0, 0, next_id, 0, movie_dur)
177 + b'\0' * 8 + struct.pack('>HHHH', 0, 0, 0, 0) + UNITY
178 + struct.pack('>II', 1280 << 16, 720 << 16))
179mdhd = full(b'mdhd', 0,
180 struct.pack('>IIII', 0, 0, TIMESCALE, vid_dur)
181 + struct.pack('>HH', 0x55C4, 0)) # language und
182hdlr = full(b'hdlr', 0, struct.pack('>I', 0) + b'vide' + b'\0' * 12 + b'\0')
183minf = box(b'minf',
184 full(b'vmhd', 1, struct.pack('>HHHH', 0, 0, 0, 0))
185 + box(b'dinf', box(b'dref',
186 struct.pack('>II', 0, 1) + full(b'url ', 1, b'')))
187 + box(b'stbl',
188 full(b'stsd', 0, struct.pack('>I', 1) + entry)
189 + full(b'stts', 0, struct.pack('>III', 1, len(frames), DELTA))
190 + full(b'stsc', 0, struct.pack('>IIII', 1, 1, len(frames), 1))
191 + full(b'stsz', 0, struct.pack('>II', 0, len(frames))
192 + b''.join(struct.pack('>I', len(f)) for f in frames))
193 + bytes(stco)))
194mdia = box(b'mdia', mdhd + full(b'hdlr', 0,
195 struct.pack('>I', 0) + b'vide' + b'\0' * 12 + b'\0')
196 + minf)
197trak = box(b'trak', tkhd + mdia)
198
199new = bytearray(data[:moov[1]])
200new += video
201struct.pack_into('>I', new, mdat[1], (mdat[2] - mdat[1]) + len(video))
202moov_new = bytearray(data[moov[1]:moov[2]])
203m = next(b for b in boxes(moov_new, 8, len(moov_new)) if b[0] == b'mvhd')
204struct.pack_into('>I', moov_new, m[3] + 16, max(old_dur, movie_dur))
205struct.pack_into('>I', moov_new, m[3] + 96, next_id + 1)
206moov_new += trak
207struct.pack_into('>I', moov_new, 0, len(moov_new))
208open('assets/test_vp8.mp4', 'wb').write(bytes(new + moov_new + data[moov[2]:]))
209SPLICE
210rm -f assets/.test_vp8.ivf assets/.test_vp8_audio.mp4
211# ...and the Matroska twin, the recipe of test_vp9.webm with libvpx rather
212# than libvpx-vp9 for the picture and the same Opus sound a `.webm` carries.
213# The engine reads `V_VP8` since the demux dispatch learned it; the decode
214# half is the plugin's (there is no software VP8 decoder here), so both files
215# are container and refusal fixtures.
216ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
217 -f lavfi -i "sine=frequency=440:duration=2" \
218 -c:v libvpx -b:v 2M -g 30 -pix_fmt yuv420p \
219 -c:a libopus -b:a 96k assets/test_vp8.webm
220# One Matroska file per audio codec the refusal string in `audio.rs` claims is
221# decodable, as five tracks of one file: FLAC, MP3, Vorbis, ALAC and PCM. The
222# string said "AAC and AC-3 only" long after every one of these decoded, which is
223# the shape of refusal this suite exists to stop (`tests/capability_matrix.rs`).
224ffmpeg -y -f lavfi -i testsrc2=size=320x240:rate=30:duration=2 \
225 -f lavfi -i "sine=frequency=440:duration=2" \
226 -map 0:v -map 1:a -map 1:a -map 1:a -map 1:a -map 1:a \
227 -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
228 -c:a:0 flac -c:a:1 libmp3lame -c:a:2 libvorbis -c:a:3 alac -c:a:4 pcm_s16le \
229 assets/test_mkv_audio.mkv
230# ...and the codec that really is refused, so the other half of the refusal is
231# testable too: DTS, which no decoder in this tree has (symphonia has none at any
232# version and there is no pure-Rust one to reach for, unlike AC-3 and Opus). The
233# notice must name *this* track and go on naming what would have worked.
234ffmpeg -y -f lavfi -i testsrc2=size=320x240:rate=30:duration=2 \
235 -f lavfi -i "sine=frequency=440:duration=2:sample_rate=48000" \
236 -map 0:v -map 1:a -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
237 -c:a dca -strict -2 -ac 2 assets/test_dts.mkv
238# Two video tracks in one mp4, at different sizes so a test can tell which one
239# the demuxer picked. `Mp4Reader::tracks()` is a HashMap and iterating it made
240# "the video track" a different one from one run to the next; the pick comes out
241# of `moov.traks` (file order) and this is what holds it there.
242ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
243 -f lavfi -i testsrc=size=320x240:rate=30:duration=2 \
244 -map 0:v -map 1:v -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
245 assets/test_two_video.mp4
246# HEVC fixture: the same A/V shape again, so the tests measure the codec and
247# nothing else. 8-bit Main profile, because the plugin's NV12 read-back cannot
248# carry Main 10.
249ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
250 -f lavfi -i "sine=frequency=440:duration=2" \
251 -f lavfi -i "sine=frequency=880:duration=2" \
252 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
253 -map 0:v -map "[a]" -c:v libx265 -tag:v hev1 -pix_fmt yuv420p \
254 -c:a aac -b:a 128k assets/test_hevc.mp4
255# The same HEVC stream tagged hvc1, which is what Apple and ffmpeg's mov muxer
256# write in practice: mp4 0.14 recognises only a hev1 sample entry, so this one
257# is found by demux.rs reading the stsd fourcc itself (`tests/hevc_hvc1.rs`).
258ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
259 -f lavfi -i "sine=frequency=440:duration=2" \
260 -f lavfi -i "sine=frequency=880:duration=2" \
261 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
262 -map 0:v -map "[a]" -c:v libx265 -tag:v hvc1 -pix_fmt yuv420p \
263 -c:a aac -b:a 128k assets/test_hevc_hvc1.mp4
264# AV1 fixture, and the only Matroska one: `mp4 0.14` has no `av01` sample entry
265# at all, so AV1 is read out of an mkv (`demux::MkvDemuxer`). Same A/V shape as
266# the others so the tests measure the codec and nothing else -- but `-g 30` is
267# not a preference: it puts a second keyframe at frame 30, which is what the
268# sync index and the seek test are checked against. 8-bit Main profile here; the
269# 10-bit twin is below. Its AAC track is deliberate too: it is the AAC a Matroska
270# file's sound is read out of through symphonia, beside the AC-3 fixtures further
271# down that no symphonia version decodes.
272ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
273 -f lavfi -i "sine=frequency=440:duration=2" \
274 -f lavfi -i "sine=frequency=880:duration=2" \
275 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
276 -map 0:v -map "[a]" -c:v libsvtav1 -preset 8 -g 30 -pix_fmt yuv420p \
277 -c:a aac -b:a 128k assets/test_av1.mkv
278# ...and an AV1 file that asks for film grain, which no other fixture here does.
279# A frame with `apply_grain` set is *displayed* from a second surface the driver
280# synthesizes the grain into, and a decoder that hands it none is refused the
281# picture outright (radeonsi: VA_STATUS_ERROR_INVALID_SURFACE out of
282# `vaEndPicture`) -- which is how AV1 decode died at frame 49 of a real film
283# while every fixture above sailed through. Three seconds rather than two so the
284# surface pool wraps several times, `noise` on the source because SVT-AV1 reads
285# the grain parameters it signals *off the source* (a clean testsrc2 yields grain
286# with no amplitude at all, measured), and `film-grain-denoise=1` so the coded
287# picture is the smooth one and the grain is really the decoder's own work.
288ffmpeg -y -f lavfi -i "testsrc2=size=1280x720:rate=30:duration=3,noise=alls=24:allf=t+u" \
289 -f lavfi -i "sine=frequency=440:duration=3" \
290 -f lavfi -i "sine=frequency=880:duration=3" \
291 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
292 -map 0:v -map "[a]" -c:v libsvtav1 -preset 8 -g 30 -pix_fmt yuv420p \
293 -svtav1-params film-grain=40:film-grain-denoise=1 \
294 -c:a aac -b:a 128k assets/test_av1_grain.mkv
295# ...and the same file 10-bit, which is what an `av1C` with `high_bitdepth` set
296# reads as and what the P010 surface pool is picked by -- the AV1 seat of the
297# pair test_hevc.mkv/test_hevc10.mkv already make for HEVC. libaom rather than
298# SVT-AV1 because it is the encoder that writes a 10-bit `av1C` here.
299ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
300 -f lavfi -i "sine=frequency=440:duration=2" \
301 -f lavfi -i "sine=frequency=880:duration=2" \
302 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
303 -map 0:v -map "[a]" -c:v libaom-av1 -cpu-used 8 -row-mt 1 -g 30 -pix_fmt yuv420p10le \
304 -c:a aac -b:a 128k assets/test_av1_10.mkv
305# The AV1 chroma and depth matrix, 64x64 and 3 frames each, in both containers.
306# 4:4:4, 4:2:2 and 12-bit are refused at open by name; the two 4:2:0 files (8 and
307# 10-bit) are the ones that open and decode. `test_av1_gray` is monochrome.
308for fmt in yuv420p:420 yuv420p10le:420_10 yuv444p:444 yuv422p:422 yuv420p12le:12bit gray:gray; do
309 pix=${fmt%%:*}; tag=${fmt##*:}
310 for ext in mkv mp4; do
311 ffmpeg -y -loglevel error -f lavfi -i testsrc2=size=64x64:rate=30:duration=0.1 \
312 -frames:v 3 -c:v libaom-av1 -cpu-used 8 -g 30 -pix_fmt "$pix" \
313 "assets/test_av1_$tag.$ext"
314 done
315done
316# H.264 in Matroska: the same stream the mp4 fixtures carry, in the container
317# that used to refuse it. Baseline profile so `rusty_h264` reads it with nothing
318# installed, `-g 30` for the second keyframe the sync index is checked against,
319# and the AAC track for the sound an mkv's audio path reads back.
320ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
321 -f lavfi -i "sine=frequency=440:duration=2" \
322 -f lavfi -i "sine=frequency=880:duration=2" \
323 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
324 -map 0:v -map "[a]" -c:v libx264 -profile:v baseline -g 30 -pix_fmt yuv420p \
325 -c:a aac -b:a 128k assets/test_h264.mkv
326# Subtitles in Matroska: the two text codecs a film carries, muxed out of the
327# hand-written files the tests also parse standalone
328# (`crates/engine/tests/data/`), so the embedded cues and the external ones can
329# be compared to each other and both to the source. Track 2 is S_TEXT/UTF8 and
330# track 3 is S_TEXT/ASS -- the same three cues, one of them with markup, which
331# is what makes "the markup is resolved, not carried" measurable.
332#
333# No bitmap track here: ffmpeg cannot encode text subtitles into pictures, so
334# the PGS refusal is checked against a Matroska file the test writes itself
335# (`crates/engine/tests/subtitles.rs`).
336ffmpeg -y -f lavfi -i testsrc2=size=320x240:rate=30:duration=5 \
337 -i crates/engine/tests/data/test_subs.srt \
338 -i crates/engine/tests/data/test_subs.ass \
339 -map 0:v -map 1:0 -map 2:0 \
340 -c:v libsvtav1 -preset 8 -g 30 -pix_fmt yuv420p \
341 -c:s:0 srt -metadata:s:s:0 language=eng \
342 -c:s:1 ass -metadata:s:s:1 language=fra -metadata:s:s:1 title=Signs \
343 assets/test_subs.mkv
344# The same two tracks with no picture and no sound at all: `.mks`, the Matroska
345# extension that is the subtitles alone (what a subtitle release ships beside
346# the film). Refused by name until the container gate learned every Matroska
347# extension rather than the two that carry a film -- the very reader that walks
348# a `.mkv` walks this.
349ffmpeg -y -i crates/engine/tests/data/test_subs.srt \
350 -i crates/engine/tests/data/test_subs.ass -map 0:0 -map 1:0 \
351 -c:s:0 srt -metadata:s:s:0 language=eng \
352 -c:s:1 ass -metadata:s:s:1 language=fra -metadata:s:s:1 title=Signs \
353 -f matroska assets/test_subs.mks
354# ...and the same file stating its languages the way a modern muxer does: in
355# `LanguageBCP47` (0x22B59D) and *not* in the legacy `Language` (0x22B59C),
356# which is the shape of every English track of two real Blu-ray-sourced films.
357# ffmpeg writes only the legacy element (8.1.2 does not read
358# the BCP-47 one either), so the element is swapped in place afterwards: the
359# 4-byte id, then the length as a two-byte VINT (`40 02`, a legal non-minimal
360# encoding) so the tag is two bytes and the element stays the eight bytes it
361# was -- every enclosing size in the file survives untouched.
362python3 - <<'PATCH'
363data = open("assets/test_subs.mkv", "rb").read()
364size = len(data)
365for legacy, tag in ((b"eng", b"en"), (b"fra", b"fr")):
366 data = data.replace(b"\x22\xb5\x9c\x83" + legacy, b"\x22\xb5\x9d\x40\x02" + tag)
367assert len(data) == size, "the swap has to be size-for-size"
368assert b"\x22\xb5\x9d" in data, "and it has to have happened"
369open("assets/test_subs_bcp47.mkv", "wb").write(data)
370PATCH
371# HEVC in Matroska: the shape a film off a disc arrives in. Same A/V shape as
372# test_hevc.mp4 so the tests measure the container and nothing else, `-g 30` for
373# the same reason test_av1.mkv has it (a second keyframe to seek to), and the
374# AAC track is read out of the mkv now rather than named as unsupported.
375ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
376 -f lavfi -i "sine=frequency=440:duration=2" \
377 -f lavfi -i "sine=frequency=880:duration=2" \
378 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
379 -map 0:v -map "[a]" -c:v libx265 -x265-params log-level=error -g 30 -pix_fmt yuv420p \
380 -c:a aac -b:a 128k assets/test_hevc.mkv
381# ...and the same file in the shape the ask came from: HEVC **Main 10** with a
382# 5.1 AAC track, which is a 4K BluRay remux in miniature. The picture decodes
383# through a P010 surface pool and the sound is folded to stereo, so both halves
384# of that file have a fixture. One tone per channel -- 440 FL, 880 FR, 220 FC,
385# 60 LFE, 1320 BL, 1760 BR as written, whatever the encoder's own element order
386# does with them -- so a test can say which channel reached which output.
387ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=2 \
388 -f lavfi -i "sine=frequency=440:duration=2:sample_rate=48000" \
389 -f lavfi -i "sine=frequency=880:duration=2:sample_rate=48000" \
390 -f lavfi -i "sine=frequency=220:duration=2:sample_rate=48000" \
391 -f lavfi -i "sine=frequency=60:duration=2:sample_rate=48000" \
392 -f lavfi -i "sine=frequency=1320:duration=2:sample_rate=48000" \
393 -f lavfi -i "sine=frequency=1760:duration=2:sample_rate=48000" \
394 -filter_complex "[1:a][2:a][3:a][4:a][5:a][6:a]join=inputs=6:channel_layout=5.1[a]" \
395 -map 0:v -map "[a]" -c:v libx265 -x265-params log-level=error -g 30 -pix_fmt yuv420p10le \
396 -c:a aac -b:a 384k assets/test_hevc10.mkv
397# Matroska sound: the two Dolby codecs that arrive in one and are read straight
398# out of its blocks (`demux::MkvAudio`). Stereo AC-3 for the plain syntax and
399# **5.1 E-AC-3** for Annex E -- the shape a remux has, and the one that must
400# come down to stereo through the same A/52 7.8 downmix the mp4 path uses.
401# 48 kHz both, which is the only rate E-AC-3 is written at in practice. Small
402# H.264 picture on purpose: these two are about the sound, and the software
403# decoder reads that one, so an audio test needs no VA-API plugin to open a
404# session on them.
405ffmpeg -y -f lavfi -i testsrc2=size=320x180:rate=30:duration=2 \
406 -f lavfi -i "sine=frequency=440:duration=2:sample_rate=48000" \
407 -f lavfi -i "sine=frequency=880:duration=2:sample_rate=48000" \
408 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo[a]" \
409 -map 0:v -map "[a]" -c:v libx264 -profile:v baseline -g 30 -pix_fmt yuv420p \
410 -c:a ac3 -b:a 192k assets/test_ac3.mkv
411ffmpeg -y -f lavfi -i testsrc2=size=320x180:rate=30:duration=2 \
412 -f lavfi -i "sine=frequency=440:duration=2:sample_rate=48000" \
413 -map 0:v -map 1:a -c:v libx264 -profile:v baseline -g 30 -pix_fmt yuv420p \
414 -ac 6 -c:a eac3 -b:a 384k assets/test_eac3.mkv
415# Dual audio in Matroska: the shape an anime remux has -- one picture and two
416# AAC tracks that differ in language and content and *agree* on rate and layout
417# (44.1k stereo), so either one can go on the same timeline. Stream 0 is
418# 440/880 Hz English, stream 1 is 220/330 Hz French; the tones are what a test
419# tells the two apart by, and getting the mapping wrong plays the other
420# language. test_multilang.mp4 is this file's mp4 twin.
421ffmpeg -y -f lavfi -i testsrc2=size=320x180:rate=30:duration=2 \
422 -f lavfi -i "sine=frequency=440:duration=2" \
423 -f lavfi -i "sine=frequency=880:duration=2" \
424 -f lavfi -i "sine=frequency=220:duration=2" \
425 -f lavfi -i "sine=frequency=330:duration=2" \
426 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo[a0];\
427[3:a][4:a]join=inputs=2:channel_layout=stereo[a1]" \
428 -map 0:v -map "[a0]" -map "[a1]" \
429 -c:v libx264 -profile:v baseline -g 30 -pix_fmt yuv420p \
430 -c:a aac -ar 44100 -ac 2 \
431 -metadata:s:a:0 language=eng -metadata:s:a:1 language=fra \
432 assets/test_multiaudio.mkv
433# Colour-tag fixtures. The picture is irrelevant here -- what is measured is
434# what the file *says* its numbers mean (`engine::colorspace`), so these are
435# one-second clips with nothing in them.
436#
437# First pair: SMPTE 170M (BT.601) tagged in the container, at 720 lines, where
438# the resolution heuristic would have said BT.709. That is the point: it is the
439# fixture that shows the container tags being read and outranking the guess.
440# Both containers, because the `colr` box and the Matroska `Colour` element are
441# parsed by different code.
442for out in assets/test_bt601.mp4 assets/test_bt601.mkv; do
443 ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=30:duration=1 \
444 -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
445 -colorspace smpte170m -color_primaries smpte170m -color_trc smpte170m \
446 "$out"
447done
448# ...and the tier below it: BT.709 written into the *bitstream* by the encoder
449# and nowhere else. Passing the codes through `-x264-params`/`-x265-params`/
450# `-svtav1-params` rather than through ffmpeg's stream tags leaves the muxer
451# with nothing to write, so these files have no `colr` box at all -- checked by
452# the test. 480 lines, so the heuristic would say BT.601 and a pass means the
453# VUI (or AV1 `color_config`) was really read. The HEVC one asks for
454# `scaling-lists=default` on purpose: a set of scaling lists sits between the
455# SPS header and its VUI, and a walk that counts them wrongly reads the colour
456# out of the middle of a coefficient. (x264 writes its quant matrices into the
457# PPS instead, so the H.264 side of that is a synthetic SPS in the unit tests.)
458ffmpeg -y -f lavfi -i testsrc2=size=640x480:rate=30:duration=1 \
459 -c:v libx264 -profile:v high -pix_fmt yuv420p \
460 -x264-params colormatrix=bt709:transfer=bt709:colorprim=bt709 \
461 assets/test_vui_h264.mp4
462ffmpeg -y -f lavfi -i testsrc2=size=640x480:rate=30:duration=1 \
463 -c:v libx265 -pix_fmt yuv420p \
464 -x265-params log-level=error:scaling-lists=default:colormatrix=bt709:transfer=bt709:colorprim=bt709 \
465 assets/test_vui_hevc.mp4
466ffmpeg -y -f lavfi -i testsrc2=size=640x480:rate=30:duration=1 \
467 -c:v libsvtav1 -preset 8 -pix_fmt yuv420p \
468 -svtav1-params color-primaries=1:transfer-characteristics=1:matrix-coefficients=1 \
469 assets/test_vui_av1.mp4
470# The HDR fixture, and the one place in this set where the *picture* is the
471# point: four flat patches written straight into the planes by `geq`, so a test
472# can name the code it feeds the tone map (`engine::tonemap`) and the code it
473# expects back. Top left is BT.2408 diffuse white -- 203 cd/m^2 is PQ signal
474# 0.584, limited-range code 144 -- top right the 1000 cd/m^2 the grade is
475# mastered against (code 181), and the bottom half a saturated BT.2020 red,
476# which is what a grey-washed render loses. H.264 rather than HEVC so the
477# software decoder can read it on a machine with no VA-API plugin: the tone map
478# is fed by the tags, not by the codec. `-qp 1` on flat patches is exact to the
479# code, so the numbers a test names are the numbers that arrive; the tags go on
480# through `setparams` rather than through the encoder's own `-colorspace`,
481# because that one makes ffmpeg *convert* into BT.2020 and the patches would no
482# longer be the codes written above.
483ffmpeg -y -f lavfi -i "color=c=black:s=320x240:rate=25:duration=1,format=yuv420p,geq=lum='if(lt(Y,H/2),if(lt(X,W/2),144,181),100)':cb='if(lt(Y,H/2),128,90)':cr='if(lt(Y,H/2),128,200)',setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc:range=tv" \
484 -c:v libx264 -profile:v high -qp 1 -pix_fmt yuv420p \
485 assets/test_pq.mp4
486# The HDR *metadata* fixtures: the same grade written three ways, so the three
487# places a film's real peak brightness can live each have a file with known
488# numbers in it. MaxCLL 1000, MaxFALL 400, mastering display 1000 nits down to
489# 0.005 (which is what x265's `L(10000000,50)` means: ten-thousandths of a nit).
490#
491# Two passes, and the second one is not optional: `-x265-params master-display`
492# only writes the SEI messages *inside the bitstream*, and ffmpeg's muxers write
493# a container's own MaxCLL/`mdcv` off stream side data, which exists only once a
494# decode has extracted those SEIs. Remuxing with `-c copy` does not do it --
495# verified, the `Colour` element comes back out with the code points and nothing
496# else. So: encode HEVC with the SEIs, then transcode into each container, which
497# is also what leaves test_hdr_sei.mkv carrying the SEI tier *alone* (H.264
498# writes no such SEI, so the transcoded pair carry the container tier alone).
499ffmpeg -y -f lavfi -i "color=c=black:s=320x240:rate=25:duration=0.4,format=yuv420p10le,setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc:range=tv" \
500 -c:v libx265 -pix_fmt yuv420p10le \
501 -x265-params "log-level=error:master-display=G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(10000000,50):max-cll=1000,400" \
502 assets/test_hdr_sei.mkv
503ffmpeg -y -i assets/test_hdr_sei.mkv -c:v libx264 -qp 20 -pix_fmt yuv420p \
504 assets/test_hdr_meta.mkv
505ffmpeg -y -i assets/test_hdr_sei.mkv -c:v libx264 -qp 20 -pix_fmt yuv420p \
506 assets/test_hdr_meta.mp4
507# ...and one whose declared peak is a number nothing assumes: the three above
508# say 1000, which is exactly what a file that declared *nothing* is assumed at,
509# so no picture made from them can show that the metadata was read. This one is
510# mastered at 4000 (`L(40000000,50)`, MaxCLL 4000) over the same four patches
511# `test_pq.mp4` carries -- ten-bit codes here, four times the eight-bit ones --
512# so a tone map told 4000 lands them visibly elsewhere than one told 1000.
513#
514# Same two passes for the same reason, and the H.264 second one is what makes it
515# software-decodable: the render tests that read it must not need a VA-API
516# plugin. `-qp 1` on flat patches so the codes arrive as written (measured: 144,
517# 181 and 100 come back exactly).
518bright_sei="$(mktemp -t edith_hdr_bright_XXXXXX.mkv)"
519ffmpeg -y -f lavfi -i "color=c=black:s=320x240:rate=25:duration=0.4,format=yuv420p10le,geq=lum='if(lt(Y,H/2),if(lt(X,W/2),576,724),400)':cb='if(lt(Y,H/2),512,360)':cr='if(lt(Y,H/2),512,800)',setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc:range=tv" \
520 -c:v libx265 -pix_fmt yuv420p10le \
521 -x265-params "log-level=error:master-display=G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(40000000,50):max-cll=4000,400" \
522 "$bright_sei"
523ffmpeg -y -i "$bright_sei" -c:v libx264 -qp 1 -pix_fmt yuv420p \
524 assets/test_hdr_bright.mkv
525rm -f "$bright_sei"
526# Sync fixture: one flash and one beep, at the same instant. Black picture with
527# a white frame from t=1.0 to t=1.1, silence with a 1 kHz tone over exactly that
528# stretch — so a test can find each of them and say how far apart they came out.
529# What it is for is *speed*: a re-timed clip that drifts puts the beep somewhere
530# the flash is not, and nothing else in the fixture set has a mark to measure
531# that against. Same 30 fps / 44.1k stereo shape as test_av.mp4, so it can share
532# a timeline with the rest.
533# The beep is silence-then-tone-then-silence rather than a gated tone: lavfi's
534# `sine` comes out at an eighth of full scale, and a mark a test looks for has
535# to be plainly louder than anything around it.
536ffmpeg -y -f lavfi -i "color=c=black:s=320x180:r=30:d=3" \
537 -f lavfi -i "sine=frequency=1000:duration=0.1:sample_rate=44100" \
538 -filter_complex "[0:v]drawbox=x=0:y=0:w=iw:h=ih:color=white:t=fill:\
539enable='between(t,1,1.1)'[v];\
540[1:a]volume=6,aformat=channel_layouts=stereo,adelay=1000|1000,apad=whole_dur=3[a]" \
541 -map "[v]" -map "[a]" -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
542 -c:a aac -b:a 128k assets/test_speed_sync.mp4
543# Mismatch fixture: different resolution and no audio track at all, so import
544# has something concrete to refuse.
545ffmpeg -y -f lavfi -i testsrc2=size=640x360:rate=30:duration=2 \
546 -an -c:v libx264 -profile:v baseline -pix_fmt yuv420p assets/test_mismatch.mp4
547# Frame-rate fixture: test_av.mp4 in every respect a timeline is held to -- same
548# codec, same profile, same 44.1k stereo AAC -- except that it runs at 25 fps,
549# so a timeline of 30 fps clips has one at another rate to read through `Rate`.
550ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=25:duration=2 \
551 -f lavfi -i "sine=frequency=440:duration=2" \
552 -f lavfi -i "sine=frequency=880:duration=2" \
553 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
554 -map 0:v -map "[a]" -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
555 -c:a aac -b:a 128k assets/test_25fps.mp4
556# ...and the same again at 23.976 fps (24000/1001), the rate whose ratio to a
557# 30 fps timeline does not terminate: what the frame mapping's rounding is
558# actually tested against.
559ffmpeg -y -f lavfi -i testsrc2=size=1280x720:rate=24000/1001:duration=2 \
560 -f lavfi -i "sine=frequency=440:duration=2" \
561 -f lavfi -i "sine=frequency=880:duration=2" \
562 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]" \
563 -map 0:v -map "[a]" -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
564 -c:a aac -b:a 128k assets/test_23976fps.mp4
565# Standalone audio fixtures: the same 440/880 Hz tone with the 1 Hz pulse the
566# A/V fixture carries, at test_av.mp4's own 44.1k stereo -- so an imported song
567# can share a timeline with the video clips and the peaks tests can reuse the
568# dip pattern. One per container we claim to read.
569tone="[0:a][1:a]join=inputs=2:channel_layout=stereo,volume='0.5+0.5*sin(2*PI*t)':eval=frame[a]"
570for fmt in mp3 wav flac ogg m4a aac; do
571 case $fmt in
572 mp3) codec=(-c:a libmp3lame -b:a 128k) ;;
573 wav) codec=(-c:a pcm_s16le) ;;
574 flac) codec=(-c:a flac) ;;
575 ogg) codec=(-c:a libvorbis) ;;
576 # ALAC in mp4, and raw AAC in ADTS -- the two the mp4/AAC packet-copy
577 # path cannot claim: one is not AAC, the other is not in an mp4.
578 m4a) codec=(-c:a alac) ;;
579 aac) codec=(-c:a aac -b:a 128k -f adts) ;;
580 esac
581 ffmpeg -y -f lavfi -i "sine=frequency=440:duration=3" \
582 -f lavfi -i "sine=frequency=880:duration=3" \
583 -filter_complex "$tone" -map "[a]" -ar 44100 "${codec[@]}" \
584 "assets/test_tone.$fmt"
585done
586# ...and the same tone in the MPEG audio spellings an encoder names after the
587# standard rather than the codec (`.mpeg`/`.mpg`), carrying a JPEG cover in its
588# ID3v2 tag -- the shape a voice note or a tagged download has. `-f mp3` is what
589# makes it an MPEG *audio* stream: left to the extension, ffmpeg would write an
590# MPEG program stream instead, which is a different file that this engine has no
591# demuxer for. `test_tone_cover.jpg` is the cover it muxes in; a reader that
592# walked the file as an mp4 saw only `InvalidData("file contains a box with a
593# larger size than it")` before `is_audio` admitted the spelling.
594ffmpeg -y -f lavfi -i "color=c=blue:s=64x64:d=1" -frames:v 1 \
595 "assets/test_tone_cover.jpg"
596ffmpeg -y -f lavfi -i "sine=frequency=440:duration=3" \
597 -f lavfi -i "sine=frequency=880:duration=3" \
598 -i "assets/test_tone_cover.jpg" \
599 -filter_complex "$tone" -map "[a]" -map 2:v -ar 44100 \
600 -c:a libmp3lame -b:a 128k -c:v mjpeg -disposition:v attached_pic \
601 -id3v2_version 3 -f mp3 "assets/test_tone_cover.mpeg"
602ffmpeg -y -f lavfi -i "sine=frequency=440:duration=3" \
603 -f lavfi -i "sine=frequency=880:duration=3" \
604 -filter_complex "$tone" -map "[a]" -ar 44100 \
605 -c:a libmp3lame -b:a 128k -id3v2_version 3 -f mp3 "assets/test_tone.mpg"
606# The two Opus fixtures, which cannot join the loop above: Opus decodes at 48 kHz
607# and nothing else, so these are the 48k twins of the tone rather than 44.1k ones.
608# First the standalone `.opus`, an Ogg file `crate::is_audio` now admits.
609ffmpeg -y -f lavfi -i "sine=frequency=440:duration=3:sample_rate=48000" \
610 -f lavfi -i "sine=frequency=880:duration=3:sample_rate=48000" \
611 -filter_complex "$tone" -map "[a]" -c:a libopus -b:a 96k \
612 assets/test_tone.opus
613# ...and 5.1 Opus in an `.mka`, which is the shape a film soundtrack has: four
614# Opus streams with the Vorbis channel mapping, folded to stereo on the way to
615# the timeline. The tone sits in **FL and BR only**, both silent in between, so
616# the fold's channel order is checkable without an FFT: done right, 440 Hz comes
617# out left and 880 Hz right; read in the decoder's own Vorbis order (FL, FC, FR,
618# BL, BR, LFE) instead of the film order the fold wants (FL, FR, FC, LFE, BL, BR),
619# BR lands on the left with FL and the right channel comes out silent.
620# `join` needs every output channel mapped and assigns them by *name*, not by
621# input order: without the explicit `map=` the two tones land in FC and BR
622# instead, and the fixture stops testing what its comment says.
623ffmpeg -y -f lavfi -i "sine=frequency=440:duration=3:sample_rate=48000" \
624 -f lavfi -i "sine=frequency=880:duration=3:sample_rate=48000" \
625 -f lavfi -i "anullsrc=r=48000:cl=quad:d=3" \
626 -filter_complex "[0:a][1:a][2:a]join=inputs=3:channel_layout=5.1:map=0.0-FL|2.0-FR|2.1-FC|2.2-LFE|2.3-BL|1.0-BR[a]" \
627 -map "[a]" -c:a libopus -b:a 256k assets/test_opus_51.mka
628# ...and **7.1 Opus**, which is a large film's soundtrack in miniature: five
629# Opus streams, three coupled, and the widest layout the fold has a table for.
630# One frequency per channel, four of the eight carrying anything, so the whole
631# downmix is checkable by picking those four out of the folded pair
632# (`tests/audio_multi.rs`): 440 in FL is left only, 880 in FC is both sides at
633# -3 dB, 1320 in the LFE must be *gone*, and 1760 in SR is right only. Get the
634# Vorbis-to-film permutation wrong at this width and every one of those moves.
635ffmpeg -y -f lavfi -i "sine=frequency=440:duration=3:sample_rate=48000" \
636 -f lavfi -i "sine=frequency=880:duration=3:sample_rate=48000" \
637 -f lavfi -i "sine=frequency=1320:duration=3:sample_rate=48000" \
638 -f lavfi -i "sine=frequency=1760:duration=3:sample_rate=48000" \
639 -f lavfi -i "anullsrc=r=48000:cl=quad:d=3" \
640 -filter_complex "[0:a][1:a][2:a][3:a][4:a]join=inputs=5:channel_layout=7.1:map=0.0-FL|4.0-FR|1.0-FC|2.0-LFE|4.1-BL|4.2-BR|4.3-SL|3.0-SR[a]" \
641 -map "[a]" -c:a libopus -b:a 320k assets/test_opus_71.mka
642# ...and standalone AC-3 in an `.mka`: the same syntax `test_ac3.mkv` carries,
643# with no picture at all, which is DEBT #64's shape -- an AC-3 soundtrack
644# ripped to its own Matroska file rather than left beside a video track. Read
645# through the same [`MkvAc3Track`] door `.mkv` uses (`crate::demux::is_matroska`
646# admits `.mka`), not symphonia, which has no AC-3 decoder.
647ffmpeg -y -f lavfi -i "sine=frequency=440:duration=2:sample_rate=44100" \
648 -c:a ac3 -b:a 192k -ac 2 assets/test_ac3.mka
649# Still-image fixture: the source with a picture and no timeline in it. Two
650# bands rather than one colour, so a test can tell top from bottom (a flipped
651# decode) and red from blue (a swapped channel order); 640x360, which is 16:9
652# like the video fixtures, so a Fit onto 1280x720 covers the canvas with no
653# bars and every pixel of the exported frame is the image.
654ffmpeg -y -f lavfi -i "color=c=red:s=640x180,format=rgb24" \
655 -f lavfi -i "color=c=blue:s=640x180,format=rgb24" \
656 -filter_complex "[0:v][1:v]vstack=inputs=2,format=rgb24" \
657 -frames:v 1 assets/test_still.png
658# The refusal fixture: same tone at 48k, which one output device cannot mix
659# with a 44.1k timeline.
660ffmpeg -y -f lavfi -i "sine=frequency=440:duration=3" \
661 -f lavfi -i "sine=frequency=880:duration=3" \
662 -filter_complex "$tone" -map "[a]" -ar 48000 -c:a pcm_s16le \
663 assets/test_tone_48k.wav
664# A file long enough to have a *cue table*, whose audio says where in it you
665# are: a 30 s chirp from 200 Hz rising 160 Hz a second, so the frequency of any
666# quarter second of it names the second it came from. That is what makes a seek
667# landing measurable without a reference decode (`tests/audio_seek.rs`), and the
668# length is the point -- symphonia's Matroska seek goes through the cues, and on
669# a two-second fixture there are none to go wrong. Opus in an mkv because that
670# is the film the desync was measured on, keyframes every five seconds because
671# that is what writes a cue point per cluster.
672ffmpeg -y -f lavfi -i "testsrc2=size=320x180:rate=24:duration=30" \
673 -f lavfi -i "aevalsrc=sin(2*PI*(200*t+80*t*t)):s=48000:d=30" \
674 -map 0:v -map 1:a -c:v libx264 -profile:v baseline -pix_fmt yuv420p -g 120 \
675 -c:a libopus -b:a 128k assets/test_seek_chirp.mkv
676# The lopsided container: 2 s of picture under 60 s of sound, which is what a
677# still with a song over it or a botched remux looks like from the outside. The
678# point is the *denominator* -- a file 60 s long whose video track is 2 s long
679# reports thirty times its real byte rate if the bitrate row divides by the
680# picture rather than by the file (`crates/engine/tests/bitrate.rs`). Nothing
681# else here has this shape, which is exactly why it is here.
682ffmpeg -y -f lavfi -i "testsrc2=size=320x240:rate=30:duration=2" \
683 -f lavfi -i "sine=frequency=440:duration=60" \
684 -map 0:v -map 1:a -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
685 -c:a aac -b:a 64k assets/test_short_video_long_audio.mp4
686# A song wearing a film's extension: AAC audio, no video track, muxed into an
687# `.mp4` -- the shape a phone's voice memo or a stripped remux takes, and the
688# one `crate::is_audio` cannot see (`tests/audio_files.rs`).
689ffmpeg -y -f lavfi -i "sine=frequency=440:duration=3" \
690 -c:a aac -b:a 128k assets/test_audio_only.mp4
691
692# A QuickTime-brand `.mov` (what Resolve, Final Cut and `ffmpeg -f mov` write):
693# its AAC sample entry is a version-1 SoundDescription -- 16 bytes of
694# compression fields after the sample rate, then the `esds` inside a `wave`
695# wrapper -- rather than the bare ISO `mp4a`+`esds` an `.mp4` carries. Stock
696# mp4 0.14 walked past both and called the track esds-less, so a `.mov` opened
697# with no sound at all (`tests/audio_decode.rs`). 440 Hz left / 880 Hz right
698# at 44.1k, 2 s, so the same channel-identity check applies.
699ffmpeg -y -f lavfi -i testsrc2=size=320x240:rate=24:duration=2 \
700 -f lavfi -i "sine=frequency=440:duration=2" \
701 -f lavfi -i "sine=frequency=880:duration=2" \
702 -filter_complex "[1:a][2:a]join=inputs=2:channel_layout=stereo[a]" \
703 -map 0:v -map "[a]" -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
704 -c:a aac -b:a 96k -f mov assets/test_qt.mov
705
706# The display matrix: `test_rotation*.mp4` are one 320x180 source -- four
707# coloured quadrants, so a quarter turn is readable from a single sampled pixel
708# per corner and a wrong direction cannot pass -- written back out with a
709# rotation asked for. This is how a phone records a portrait video: the pixels
710# stay landscape and the container says which way to turn them.
711#
712# The trap this recipe exists to avoid: `-metadata:s:v rotate=90`, the form
713# every search result gives, writes **no display matrix at all** with this
714# machine's ffmpeg (`ffprobe -show_streams` comes back with an empty side-data
715# block, so a "rotated" fixture is really an unrotated one and the test passes
716# against nothing). `-display_rotation` is a *muxer* option here and, being an
717# input option, goes **before** the `-i` it applies to.
718#
719# The four quadrants are red, green, blue and yellow:
720#
721# coded -display_rotation 90 -display_rotation 180
722# red green green yellow yellow blue
723# blue yellow red blue green red
724#
725# which is exactly ffmpeg's own autorotation of each file -- measured
726# (`ffmpeg -i f.mp4 -f rawvideo -pix_fmt rgb24 -`) rather than derived, because
727# which way a display matrix turns a picture is the one thing a reader has to be
728# told rather than guess. `tests/rotation.rs` asserts those layouts.
729#
730# `-display_rotation 45` is the other half: a matrix that is a rotation and not
731# a *quarter* turn, which this engine refuses by name (`demux::UnsupportedRotation`)
732# instead of showing it sideways.
733ffmpeg -y -f lavfi -i "color=c=red:s=160x90:d=1:r=30,format=yuv420p" \
734 -f lavfi -i "color=c=green:s=160x90:d=1:r=30,format=yuv420p" \
735 -f lavfi -i "color=c=blue:s=160x90:d=1:r=30,format=yuv420p" \
736 -f lavfi -i "color=c=yellow:s=160x90:d=1:r=30,format=yuv420p" \
737 -filter_complex "[0:v][1:v]hstack[top];[2:v][3:v]hstack[bot];[top][bot]vstack[v]" \
738 -map "[v]" -frames:v 30 -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
739 assets/.rotation_src.mp4
740for deg in 90 180 270 45; do
741 ffmpeg -y -display_rotation "$deg" -i assets/.rotation_src.mp4 \
742 -c copy "assets/test_rotation$deg.mp4"
743done
744# ...and the very same turn asked for inside a Matroska, from the very same
745# source: one set of expected layouts then covers both containers
746# (`tests/rotation.rs`), which is the point -- a roll read the wrong way round is
747# a file that plays on its side in exactly one of the two.
748#
749# What the muxer actually writes, byte-verified by walking the header rather than
750# taken off a table: a `Projection` master (`0x7670`) holding one
751# `ProjectionPoseRoll` (`0x7675`), an 8-byte big-endian float -- `+90.0`, `+180.0`
752# and *`-90.0`* for `-display_rotation 90/180/270` -- and no `ProjectionType`
753# element at all, which is the spec's default of 0 (rectangular). `ffprobe`
754# reports the same display matrix as the mp4 twin, which is what makes the
755# layouts above ffmpeg's own autorotation of either file. The roll counts
756# counter-clockwise where the matrix counts clockwise turns, which is why the
757# engine negates it.
758for deg in 90 180 270 45; do
759 ffmpeg -y -display_rotation "$deg" -i assets/.rotation_src.mp4 \
760 -c copy "assets/test_rotation$deg.mkv"
761done
762rm -f assets/.rotation_src.mp4
763
764# The one fixture where the coded and the displayed height disagree about what the
765# material is: `test_rotation90tall` is 1280x640 as stored and 640x1280 as shown,
766# and neither container tags its colour (the mkv's `Colour` element carries only
767# chroma siting, the mp4 has no `colr` box), so the 720-line rule an untagged
768# stream's matrix is guessed from reads a different side of itself depending on
769# which height a door feeds it.
770ffmpeg -y -f lavfi -i "color=c=red:s=640x320:d=1:r=30,format=yuv420p" \
771 -f lavfi -i "color=c=green:s=640x320:d=1:r=30,format=yuv420p" \
772 -f lavfi -i "color=c=blue:s=640x320:d=1:r=30,format=yuv420p" \
773 -f lavfi -i "color=c=yellow:s=640x320:d=1:r=30,format=yuv420p" \
774 -filter_complex "[0:v][1:v]hstack[top];[2:v][3:v]hstack[bot];[top][bot]vstack[v]" \
775 -map "[v]" -frames:v 30 -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
776 assets/.rotation_tall_src.mp4
777for ext in mp4 mkv; do
778 ffmpeg -y -display_rotation 90 -i assets/.rotation_tall_src.mp4 \
779 -c copy "assets/test_rotation90tall.$ext"
780done
781rm -f assets/.rotation_tall_src.mp4
782
783# The sample aspect ratio: `test_anamorphic.*` are one 1440x1080 source whose
784# pixels are drawn 4/3 wide -- the classic anamorphic 16:9 frame stored on a
785# 4:3 raster (`-vf setsar=4/3`), so the displayed picture is 1920x1080 and the
786# stored one never is. This is how a DVD rip and a Blu-ray remux say "widen
787# me": the pixels stay where the encoder put them and the container carries
788# the ratio.
789#
790# What each muxer actually writes, byte-verified by walking the output rather
791# than taken off a table: the Matroska muxer writes `DisplayWidth` 16,
792# `DisplayHeight` 9 and `DisplayUnit` 3 -- a *display aspect ratio* pair, not
793# a sample aspect ratio, and 4:3 SAR over 1440x1080 is exactly 16:9 DAR -- and
794# a square-pixel file gets no `Display*` element at all. The mp4 muxer writes
795# a `pasp` box (hSpacing 4, vSpacing 3) inside the `avc1` sample entry, and
796# 1/1 for a square one. `tests/anamorphic.rs` reads both spellings through the
797# engine and asserts the same displayed shape off either.
798ffmpeg -y -f lavfi -i "testsrc2=size=1440x1080:rate=30:duration=1" \
799 -vf "setsar=4/3" -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
800 assets/test_anamorphic.mp4
801ffmpeg -y -f lavfi -i "testsrc2=size=1440x1080:rate=30:duration=1" \
802 -vf "setsar=4/3" -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
803 assets/test_anamorphic.mkv
804
805# ...and the anamorphic HEVC Matroska twin, for the copy path: `tests/`'s
806# copy door only copies HEVC or AV1 Matroska (`tests/video_copy.rs`), so an
807# anamorphic *copy* needs an anamorphic source in a codec that door takes.
808# Same source as above through libx265; the SAR rides the stream.
809ffmpeg -y -f lavfi -i "testsrc2=size=1440x1080:rate=30:duration=2" \
810 -vf "setsar=4/3" -c:v libx265 -pix_fmt yuv420p \
811 -x265-params "log-level=error:keyint=30:min-keyint=30" \
812 assets/test_anamorphic_hevc.mkv
813
814# HEVC on the software seat (`ec-h265`, `tests/hevc_sw.rs`, `decode/hevc.rs`):
815# libx265 at 8-bit and Main 10, in mp4 and Matroska, at 352x288 for one second,
816# B-frames and an IDR every 15 frames. The odd size is 350x286 (a conformance
817# window that crops the coded 352x288). The CRA file is open-GOP, so its GOPs
818# start on CRAs with RASL pictures. The 4:2:2 file is refused by name at open.
819ffmpeg -y -f lavfi -i "testsrc2=size=352x288:rate=30:duration=1" \
820 -c:v libx265 -pix_fmt yuv420p -x265-params "keyint=15:bframes=3:log-level=error" \
821 assets/test_hevcsw_8.mp4
822ffmpeg -y -f lavfi -i "testsrc2=size=352x288:rate=30:duration=1" \
823 -c:v libx265 -pix_fmt yuv420p -x265-params "keyint=15:bframes=3:log-level=error" \
824 assets/test_hevcsw_8.mkv
825ffmpeg -y -f lavfi -i "testsrc2=size=352x288:rate=30:duration=1" \
826 -c:v libx265 -pix_fmt yuv420p10le -x265-params "keyint=15:bframes=3:log-level=error" \
827 assets/test_hevcsw_10.mp4
828ffmpeg -y -f lavfi -i "testsrc2=size=352x288:rate=30:duration=1" \
829 -c:v libx265 -pix_fmt yuv420p10le -x265-params "keyint=15:bframes=3:log-level=error" \
830 assets/test_hevcsw_10.mkv
831ffmpeg -y -f lavfi -i "testsrc2=size=350x286:rate=30:duration=1" \
832 -c:v libx265 -pix_fmt yuv420p -x265-params "keyint=15:bframes=3:log-level=error" \
833 assets/test_hevcsw_odd.mp4
834ffmpeg -y -f lavfi -i "testsrc2=size=352x288:rate=30:duration=1" \
835 -c:v libx265 -pix_fmt yuv420p -x265-params "keyint=15:bframes=3:open-gop=1:log-level=error" \
836 assets/test_hevcsw_cra.mp4
837ffmpeg -y -f lavfi -i "testsrc2=size=352x288:rate=30:duration=1" \
838 -c:v libx265 -pix_fmt yuv422p -x265-params "keyint=15:bframes=3:log-level=error" \
839 assets/test_hevcsw_422.mp4
840# The 10-bit RExt 4:2:2 HEVC the probe refuses by name at open (`hvcC` chroma 2, depth 10).
841ffmpeg -y -f lavfi -i "testsrc2=size=64x64:rate=30:duration=0.1" \
842 -frames:v 3 -c:v libx265 -pix_fmt yuv422p10le -x265-params "log-level=error" \
843 assets/test_hevcsw_422_10.mp4
844# The 1080p 8-bit clip the software seat's per-frame timing is read off.
845ffmpeg -y -f lavfi -i "testsrc2=size=1920x1080:rate=30:duration=2" \
846 -c:v libx265 -pix_fmt yuv420p -x265-params "keyint=15:bframes=3:log-level=error" \
847 assets/test_hevcsw_1080.mp4
848
849
850echo "fixtures written to assets/"
851# Copy-length fixture: 4.0 s of picture over 44.1k AAC, whose 172.27 packets'
852# worth of sound a stream copy has to round up, not away (export.rs
853# a_copied_sound_runs_as_long_as_its_picture).
854ffmpeg -y -f lavfi -i testsrc2=size=320x180:rate=30:duration=4 \
855 -f lavfi -i "sine=frequency=440:sample_rate=44100:duration=4" \
856 -map 0:v -map 1:a -c:v libx264 -profile:v baseline -pix_fmt yuv420p \
857 -ac 2 -c:a aac -b:a 128k -shortest assets/test_sync.mp4