ws-video: video/avi tests (OpenDML / idx1 / scan, PCM / ADPCM / MP2 audio, raw RGB / I420, mux round trip), video/y4m tests (every C tag, 10-bit, writer), empty audio chunks are padding

This commit is contained in:
4DBug committed 2026-10-31 09:45:10 -05:00
1 parent 9411cd97c6
commit d221bb5327
9 files changed
+402 -9

No files matched your search

+2 -2
View File
@@ -20,9 +20,9 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| audio | mp3 | .mp3 .mp2 .mp1 .mpga | yes | - | streaming: true, seek: true, layers: 1, 2, 3, channels: 2 | `tests/audio/mp3.luau` |
| audio | opus | .opus | yes | - | streaming: true, seek: true, lossy: true, channels: 255, rates: 48000 | `tests/audio/opus.luau` |
| audio | wav | .wav .wave .rf64 .bw64 | yes | yes | streaming: true, depths: 8, 16, 24, 32, float: true, rf64: true | `tests/audio/wav.luau` |
| video | avi | .avi | yes | yes | streaming: true, video: "mjpeg", "mpeg1", "rawvideo", audio: true, odml: true | **missing** |
| video | avi | .avi | yes | yes | streaming: true, video: "mjpeg", "mpeg1", "rawvideo", audio: true, odml: true | `tests/video/avi.luau` |
| video | mkv | .mkv .webm .mka .mk3d | yes | yes | streaming: true, remux: true, video: "vp8", "mjpeg", "mpeg1", "rawvideo", audio: true, subtitles: true | `tests/video/mkv.luau` |
| video | y4m | .y4m | yes | yes | streaming: true, video: "rawvideo", depths: 8, 10, 12, 16 | **missing** |
| video | y4m | .y4m | yes | yes | streaming: true, video: "rawvideo", depths: 8, 10, 12, 16 | `tests/video/y4m.luau` |
| model | gltf | .gltf .glb | yes | yes | binary: true, materials: true, animation: true, skins: true, morphTargets: true, cameras: true, lights: true | `tests/model/gltf.luau` |
| model | obj | .obj | yes | yes | materials: true, polygons: true, vertexColors: true | `tests/model/obj.luau` |
| model | off | .off | yes | yes | polygons: true, points: true, colors: true, binary: false | `tests/model/off.luau` |
+3 -1
View File
@@ -205,8 +205,10 @@ function AviFormat.demux(r: Bytes.Reader, _opts: OpenOptions?): (any, Err.Err?)
end
if c.size > 0 then
table.insert(items, { c.offset, k, tick, dur, if c.key then 1 else 0, c.size })
tick += dur
elseif t.kind == "video" then
tick += 1 -- an empty video chunk: a dropped frame keeps its slot (empty audio chunks are padding)
end
tick += dur
end
end
table.sort(items, function(a: { number }, b: { number }): boolean
+5 -2
View File
@@ -163,9 +163,12 @@ end
-- seek(t, v, c, label, at): after seek(at) the next frame is the first at or after `at`
function C.seek(t: any, v: any, c: any, label: string, at: number)
if not c.frames or not Video.canDecode(v.codec) then
if not (c.frames or c.rgba) or not Video.canDecode(v.codec) then
return
end
if v.duration > 0 and at > v.duration * 0.6 then
at = math.floor(v.duration * 50) / 100
end
v:seek(at)
local f, ferr = v:nextFrame()
if not f and ferr and string.find(ferr.message, "inter frames", 1, true) then
@@ -173,7 +176,7 @@ function C.seek(t: any, v: any, c: any, label: string, at: number)
return -- TEMP until ws/video-vp8 merges
end
t:check(f ~= nil and f.pts >= at - 1e-6 and f.pts < at + 0.2, label .. ": seek to " .. at .. " lands at " .. tostring(f and f.pts))
if f and C.EXACT[v.codec] then
if f and C.EXACT[v.codec] and c.frames then
local idx = math.floor(f.pts * v.frameRate + 0.5) + 1
t:eq(Crc32.of(f.image.pixels), c.frames[idx], label .. ": the frame after seeking equals ffmpeg's frame " .. idx)
end
+97
View File
@@ -0,0 +1,97 @@
-- video/avi tests: AVI files from ffmpeg (MJPEG + PCM s16 / u8 / IMA ADPCM, MPEG-1 + MP2, uncompressed BGR24 / BGRA /
-- I420) read through the OpenDML indexes, idx1 alone, and a movi scan: tracks and every packet against ffprobe,
-- frames against ffmpeg, audio through the api hook, seeking; our muxer (MJPEG + PCM) read back; a GIF converted to
-- AVI. Fixtures: tools/fixtures/avi.py.
local T = require("@tests/T")
local C = require("@tests/video/_common")
local F = require("@formats")
local AviFormat = require("@formats/video/avi")
local Bytes = require("@formats/core/Bytes")
local Crc32 = require("@formats/core/Crc32")
local Fx = require("@tests/gen/avi_cases")
local t = T.suite("avi")
t:eq(AviFormat.name, "avi", "name")
t:eq(AviFormat.category, "video", "category")
local EXACT_AUDIO = { pcm_s16le = true, pcm_u8 = true, adpcm_ima_wav = true }
local byName = {}
for _, c in Fx do
byName[c.name] = c
end
for _, c in Fx do
local label = c.name
t:check(AviFormat.sniff(Bytes.reader(buffer.fromstring(c.data))) > 0, label .. ": sniff")
local v, err = C.open(c.data)
if c.truncated then
t:check(v ~= nil or err ~= nil, label .. ": opens or fails cleanly")
else
t:check(v ~= nil, label .. ": open: " .. tostring(err))
if v then
local dmx = v.demuxer
t:eq(#dmx.tracks, #c.streams, label .. ": track count")
C.packets(t, dmx, c, label)
if c.rgba then
v:reset()
local n, bad = 0, 0
while true do
local f = v:nextFrame()
if not f then
break
end
n += 1
if f.image.format ~= "rgba8" or Crc32.of(f.image.pixels) ~= c.rgba[n] then
bad += 1
end
end
t:check(n == #c.rgba and bad == 0, label .. ": " .. n .. " rgba frames equal ffmpeg's (" .. bad .. " differ)")
else
C.frames(t, v, c, label)
end
local at = dmx:track("audio")
if at then
C.audio(t, v, c, label, EXACT_AUDIO[at.codec], 30)
end
C.seek(t, v, c, label, 0.5)
end
end
end
t:eq(C.open(byName["mjpeg_pcm.avi"].data).demuxer.meta.index, "idx1", "ffmpeg's AVI: idx1 used")
t:eq(C.open(byName["odml.avi"].data).demuxer.meta.index, "odml", "OpenDML indexes used")
t:eq(C.open(byName["idx1_only.avi"].data).demuxer.meta.index, "idx1", "idx1 used without OpenDML indexes")
t:eq(C.open(byName["no_index.avi"].data).demuxer.meta.index, "scan", "movi scanned without indexes")
-- our muxer: MJPEG copied + PCM, read back packet for packet
do
local v = C.open(byName["mjpeg_pcm.avi"].data)
local out, err = F.save(v, nil, { format = "avi" })
t:check(out ~= nil, "mux avi: " .. tostring(err))
if out then
local v2 = F.video.open(out)
t:check(v2 ~= nil, "mux avi: reads back")
if v2 then
local a, b = v.demuxer, v2.demuxer
local same = a:count(1) == b:count(1)
for k = 1, a:count(1) do
local p, q = a:get(1, k), b:get(1, k)
if not q or buffer.tostring(p.data) ~= buffer.tostring(q.data) then
same = false
end
end
t:check(same, "mux avi: identical MJPEG packets")
t:eq(v2.frameRate, 10, "mux avi: frame rate")
C.audio(t, v2, byName["mjpeg_pcm.avi"], "mux avi", true)
end
end
end
-- fuzz
local samples = {}
for _, n in { "mjpeg_pcm.avi", "mjpeg_ima.avi", "idx1_only.avi", "i420.avi" } do
local d = byName[n].data
table.insert(samples, string.sub(d, 1, math.min(#d, 40000)))
end
t:fuzz("open", C.fuzzOpen(AviFormat), samples, { mutations = 6, garbage = 100 })
t:done()
+103
View File
@@ -0,0 +1,103 @@
-- video/y4m tests: YUV4MPEG2 streams from ffmpeg (C420jpeg at an odd size, C420mpeg2, C422, C444, Cmono, C420p10)
-- against ffmpeg's yuv420p decode (bit-exact for 4:2:0 8-bit, PSNR for the converted layouts), the header fields,
-- our writer round trip (and from an rgba frames-backed video), errors and the fuzz pass. Fixtures:
-- tools/fixtures/y4m.py.
local T = require("@tests/T")
local C = require("@tests/video/_common")
local F = require("@formats")
local Y4m = require("@formats/video/y4m")
local Bytes = require("@formats/core/Bytes")
local Crc32 = require("@formats/core/Crc32")
local Err = require("@formats/core/Err")
local Types = require("@formats/Types")
local Fx = require("@tests/gen/y4m_cases")
local t = T.suite("y4m")
t:eq(Y4m.name, "y4m", "name")
for _, c in Fx do
local label = c.name
t:check(Y4m.sniff(Bytes.reader(buffer.fromstring(c.data))) == 1, label .. ": sniff")
local v, err = Y4m.open(Bytes.reader(buffer.fromstring(c.data)))
t:check(v ~= nil, label .. ": open " .. tostring(err))
if v then
t:check(v.width == c.width and v.height == c.height, label .. ": size")
t:check(math.abs(v.frameRate - c.rate[1] / c.rate[2]) < 1e-9, label .. ": frame rate")
local n, bad, worst = 0, 0, math.huge
while true do
local f = v:nextFrame()
if not f then
break
end
n += 1
if c.exact then
if Crc32.of(f.image.pixels) ~= c.frames[n] then
bad += 1
end
elseif c.yuv[n] then
worst = math.min(worst, C.psnr(f.image.pixels, buffer.fromstring(c.yuv[n])))
end
end
t:eq(n, #c.frames, label .. ": frame count")
if c.exact then
t:check(bad == 0, label .. ": frames bit-exact with ffmpeg")
else
t:check(worst > 30, string.format("%s: PSNR vs ffmpeg %.1f dB", label, worst))
end
end
end
-- writer: a y4m stream back to y4m is byte-identical in its frames; header as ffmpeg writes it
do
local c = Fx[1]
local v = F.video.open(buffer.fromstring(c.data))
local out, err = F.save(v, nil, { format = "y4m" })
t:check(out ~= nil, "write: " .. tostring(err))
if out then
local s = buffer.tostring(out)
t:check(string.find(s, "YUV4MPEG2 W173 H95 F30000:1001 Ip A1:1 C420jpeg XYSCSS=420JPEG\n", 1, true) == 1, "write: header " .. string.sub(s, 1, 60))
local v2 = Y4m.open(Bytes.reader(out))
local n, same = 0, true
while true do
local f = v2:nextFrame()
if not f then
break
end
n += 1
same = same and Crc32.of(f.image.pixels) == c.frames[n]
end
t:check(n == #c.frames and same, "write: frames round trip")
end
-- an rgba frames-backed video (a 2-frame animation) to y4m
local a = Types.Image.new(4, 2)
buffer.fill(a.pixels, 0, 255)
local b = Types.Image.new(4, 2)
a.frames = { { image = a, delay = 0.5, x = 0, y = 0, dispose = "none", blend = "source" }, { image = b, delay = 0.5, x = 0, y = 0, dispose = "none", blend = "source" } }
local y, yerr = F.save(a, nil, { format = "y4m" })
t:check(y ~= nil, "write from frames: " .. tostring(yerr))
if y then
local v3 = Y4m.open(Bytes.reader(y))
local f1 = v3:nextFrame()
local f2 = v3:nextFrame()
t:check(f1 ~= nil and f2 ~= nil and v3:nextFrame() == nil, "write from frames: 2 frames")
t:eq(v3.frameRate, 2, "write from frames: frame rate from the delays")
t:eq(buffer.readu8(f1.image.pixels, 0), 235, "write from frames: white -> Y 235 (limited range)")
t:eq(buffer.readu8(f2.image.pixels, 0), 16, "write from frames: black -> Y 16")
end
end
-- errors
local function code(s: string): string?
local _, e = Y4m.open(Bytes.reader(buffer.fromstring(s)))
return e and e.code
end
t:eq(code("YUV4MPEG2 W0 H0\n"), Err.CORRUPT, "zero size")
t:eq(code("YUV4MPEG2 W16 H16 Cfoo\n"), Err.UNSUPPORTED, "unknown colour space")
t:eq(code("YUV4MPEG2 W99999999 H99999 C420\n"), Err.CORRUPT, "huge size")
t:eq(code("YUV4MPEG2 W16 H16"), Err.TRUNCATED, "no header end")
local samples = {}
for _, c in Fx do
table.insert(samples, string.sub(c.data, 1, 30000))
end
t:fuzz("open", C.fuzzOpen(Y4m), samples, { mutations = 6, garbage = 100 })
t:done()
+5 -3
View File
@@ -58,9 +58,11 @@ def packets(path):
return out
def yuv_frames(path, w, h, extra=None):
"""the first video stream decoded by ffmpeg to yuv420p: a list of frame bytes"""
raw = ffmpeg(["-i", path] + (extra or []) + ["-map", "0:v:0", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-"])
def yuv_frames(path, w, h, extra=None, codec=None):
"""the first video stream decoded by ffmpeg to yuv420p (yuvj420p for MJPEG: full range, no conversion): a list of
frame bytes"""
pix = "yuvj420p" if codec == "mjpeg" else "yuv420p"
raw = ffmpeg(["-i", path] + (extra or []) + ["-map", "0:v:0", "-f", "rawvideo", "-pix_fmt", pix, "-"])
n = w * h + 2 * ((w + 1) // 2) * ((h + 1) // 2)
return [raw[i:i + n] for i in range(0, len(raw) - n + 1, n)]
+152
View File
@@ -0,0 +1,152 @@
# AVI fixtures (tools/fixtures.py): files made by ffmpeg (MJPEG + PCM with idx1, the same with OpenDML indexes added
# here, MJPEG + IMA
# ADPCM, MPEG-1 + MP2, uncompressed BGR24 / BGRA / I420 video) and edits made here (the OpenDML indexes renamed to
# JUNK so idx1 is used; idx1 renamed too so the movi list is scanned; a truncated file). For each file: ffprobe's
# streams and packets, ffmpeg's frames (CRC-32 of yuv420p, or of rgba for uncompressed RGB; the first frames raw for
# PSNR checks) and ffmpeg's decoded audio (f32).
# tests/gen/avi_cases.luau { { name, data, streams, packets, frames, yuv, rgba, pcm, ... } }
import importlib.util, os, tempfile
_spec = importlib.util.spec_from_file_location("_video_helpers", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_video.py"))
V = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(V)
INPUTS = ["tools/fixtures/_video.py"]
W, H = 160, 120
SRC = ["-f", "lavfi", "-i", "testsrc2=size=%dx%d:rate=10" % (W, H)]
def sine(rate, ch=1):
return ["-f", "lavfi", "-i", "sine=frequency=330:sample_rate=%d" % rate, "-ac", str(ch)]
def rename(data, old, new):
"""every chunk id `old` renamed to `new` (same length), found by walking the RIFF lists"""
b = bytearray(data)
def walk(p, end):
while p + 8 <= end:
cid = bytes(b[p:p + 4])
size = int.from_bytes(b[p + 4:p + 8], "little")
if cid in (b"RIFF", b"LIST"):
walk(p + 12, min(end, p + 8 + size))
elif cid == old:
b[p:p + 4] = new
p += 8 + size + (size & 1)
walk(0, len(b))
return bytes(b)
def chunks(b, p, end):
out = []
while p + 8 <= end:
cid = b[p:p + 4]
size = int.from_bytes(b[p + 4:p + 8], "little")
out.append((cid, p, size))
p += 8 + size + (size & 1)
return out
def ck(cid, body):
return cid + len(body).to_bytes(4, "little") + body + (b"\0" if len(body) & 1 else b"")
def add_odml(data):
"""the same AVI with OpenDML indexes: an indx super index in every strl pointing at an ix## standard index
appended to the movi list (built from idx1, which is kept)"""
b = data
top = chunks(b, 12, len(b))
hdrl = next(c for c in top if c[0] == b"LIST" and b[c[1] + 8:c[1] + 12] == b"hdrl")
movi = next(c for c in top if c[0] == b"LIST" and b[c[1] + 8:c[1] + 12] == b"movi")
idx1 = next(c for c in top if c[0] == b"idx1")
movi_base = movi[1] + 8 # the 'movi' fourcc
streams = {}
for k in range(idx1[2] // 16):
e = idx1[1] + 8 + k * 16
cid = b[e:e + 4]
flags, off, size = (int.from_bytes(b[e + 4 + 4 * i:e + 8 + 4 * i], "little") for i in range(3))
sn = int(cid[:2])
streams.setdefault(sn, (cid, []))[1].append((movi_base + off + 8, size, bool(flags & 0x10)))
n = len([c for c in chunks(b, hdrl[1] + 12, hdrl[1] + 8 + hdrl[2]) if c[0] == b"LIST" and b[c[1] + 8:c[1] + 12] == b"strl"])
INDX = 8 + 24 + 16 # one super index entry
delta = n * INDX
# the ix## chunks at the end of the movi list
ixs = []
pos = movi[1] + 8 + movi[2] + delta # where the first ix chunk starts (movi grows by them)
for sn in range(n):
cid, ents = streams.get(sn, (b"%02dwb" % sn, []))
body = (2).to_bytes(2, "little") + bytes([0, 1]) + len(ents).to_bytes(4, "little") + cid + \
(0).to_bytes(8, "little") + bytes(4)
for off, size, key in ents:
body += (off + delta).to_bytes(4, "little") + (size | (0 if key else 0x80000000)).to_bytes(4, "little")
chunk = ck(b"ix%02d" % sn, body)
ixs.append((pos, len(chunk), len(ents), cid, chunk))
pos += len(chunk)
# hdrl with an indx in every strl
out_h = b""
si = 0
for c in chunks(b, hdrl[1] + 12, hdrl[1] + 8 + hdrl[2]):
raw = b[c[1]:c[1] + 8 + c[2] + (c[2] & 1)]
if c[0] == b"LIST" and b[c[1] + 8:c[1] + 12] == b"strl":
p, ln, cnt, cid, _ = ixs[si]
indx = (4).to_bytes(2, "little") + bytes([0, 0]) + (1).to_bytes(4, "little") + cid + bytes(12) + \
p.to_bytes(8, "little") + ln.to_bytes(4, "little") + cnt.to_bytes(4, "little")
raw = ck(b"LIST", b[c[1] + 8:c[1] + 8 + c[2]] + ck(b"indx", indx))
si += 1
out_h += raw
out = b""
for c in top:
if c is hdrl:
out += ck(b"LIST", b"hdrl" + out_h)
elif c is movi:
out += ck(b"LIST", b[c[1] + 8:c[1] + 8 + c[2]] + b"".join(x[4] for x in ixs))
else:
out += b[c[1]:c[1] + 8 + c[2] + (c[2] & 1)]
res = b"RIFF" + (len(out) + 4).to_bytes(4, "little") + b"AVI " + out
assert res[ixs[0][0]:ixs[0][0] + 2] == b"ix", "odml layout"
return res
def case(tmp, name, rgba=False, raw_frames=2, pcm_frames=8192):
path = os.path.join(tmp, name)
c = {"name": name, "data": open(path, "rb").read(), "streams": V.streams(path), "packets": V.packets(path)}
vs = [s for s in c["streams"] if s["kind"] == "video"]
if vs:
w, h = vs[0]["width"], vs[0]["height"]
if rgba:
raw = V.ffmpeg(["-i", path, "-map", "0:v:0", "-f", "rawvideo", "-pix_fmt", "rgba", "-"])
n = w * h * 4
c["rgba"] = [V.crc(raw[i:i + n]) for i in range(0, len(raw) - n + 1, n)]
else:
frames = V.yuv_frames(path, w, h, codec=vs[0]["codec"])
c["frames"] = [V.crc(f) for f in frames]
c["yuv"] = frames[:raw_frames]
if any(s["kind"] == "audio" for s in c["streams"]):
pcm = V.pcm_f32(path)
c["pcm"] = pcm[:pcm_frames * 4]
c["pcmBytes"] = len(pcm)
return c
def generate(ctx):
tmp = tempfile.mkdtemp(prefix="avifx_")
ff = lambda *a: V.ffmpeg(list(a), cwd=tmp)
ff(*SRC, *sine(44100, 2), "-t", "1", "-c:v", "mjpeg", "-q:v", "3", "-c:a", "pcm_s16le", "mjpeg_pcm.avi")
ff(*SRC, *sine(22050), "-t", "1", "-c:v", "mjpeg", "-q:v", "5", "-c:a", "adpcm_ima_wav", "mjpeg_ima.avi")
ff(*SRC, *sine(44100), "-t", "1", "-r", "25", "-c:v", "mpeg1video", "-b:v", "500k", "-c:a", "mp2", "mpeg1_mp2.avi")
ff(*SRC, "-t", "0.5", "-c:v", "rawvideo", "-pix_fmt", "bgr24", "bgr24.avi")
ff(*SRC, "-t", "0.5", "-c:v", "rawvideo", "-pix_fmt", "bgra", "bgra.avi")
ff(*SRC, "-t", "0.5", "-c:v", "rawvideo", "-pix_fmt", "yuv420p", "i420.avi")
ff(*SRC, *sine(8000), "-t", "1", "-c:v", "mjpeg", "-c:a", "pcm_u8", "pcm_u8.avi")
full = open(os.path.join(tmp, "mjpeg_pcm.avi"), "rb").read()
idx1 = rename(full, b"indx", b"JUNK")
open(os.path.join(tmp, "idx1_only.avi"), "wb").write(idx1)
open(os.path.join(tmp, "no_index.avi"), "wb").write(rename(idx1, b"idx1", b"JUNK"))
open(os.path.join(tmp, "odml.avi"), "wb").write(add_odml(full))
cases = [case(tmp, "mjpeg_pcm.avi"), case(tmp, "mjpeg_ima.avi"), case(tmp, "mpeg1_mp2.avi"),
case(tmp, "bgr24.avi", rgba=True), case(tmp, "bgra.avi", rgba=True), case(tmp, "i420.avi"),
case(tmp, "pcm_u8.avi"), case(tmp, "idx1_only.avi"), case(tmp, "no_index.avi"),
case(tmp, "odml.avi")]
cases.append({"name": "truncated.avi", "data": full[: len(full) * 6 // 10], "truncated": True})
ctx.emit("avi_cases", cases)
+1 -1
View File
@@ -29,7 +29,7 @@ def case(ctx, tmp, name, raw_frames=2, audio=True, video=True, pcm_frames=8192):
c = {"name": name, "data": data, "streams": V.streams(path), "packets": V.packets(path)}
vs = [s for s in c["streams"] if s["kind"] == "video"]
if video and vs:
frames = V.yuv_frames(path, vs[0]["width"], vs[0]["height"])
frames = V.yuv_frames(path, vs[0]["width"], vs[0]["height"], codec=vs[0]["codec"])
c["frames"] = [V.crc(f) for f in frames]
c["yuv"] = frames[:raw_frames]
if audio and any(s["kind"] == "audio" for s in c["streams"]):
+34
View File
@@ -0,0 +1,34 @@
# YUV4MPEG2 fixtures (tools/fixtures.py): streams written by ffmpeg in C420jpeg (odd size 173x95), C420mpeg2, C422,
# C444, Cmono and C420p10 (10-bit) with ffmpeg's yuv420p decode of each (CRC-32 per frame; the first frames raw for
# the converted layouts, which are compared by PSNR).
# tests/gen/y4m_cases.luau { { name, data, width, height, rate = { num, den }, frames = { crc }, yuv = { raw } } }
import importlib.util, os, tempfile
_spec = importlib.util.spec_from_file_location("_video_helpers", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_video.py"))
V = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(V)
INPUTS = ["tools/fixtures/_video.py"]
def generate(ctx):
tmp = tempfile.mkdtemp(prefix="y4mfx_")
cases = []
for name, size, rate, pix, extra in [
("c420jpeg.y4m", "173x95", "30000/1001", "yuv420p", []),
("c420mpeg2.y4m", "160x120", "25", "yuv420p", ["-chroma_sample_location", "left"]),
("c422.y4m", "160x120", "24", "yuv422p", []),
("c444.y4m", "160x120", "10", "yuv444p", []),
("cmono.y4m", "160x120", "10", "gray", []),
("c420p10.y4m", "96x64", "10", "yuv420p10le", ["-strict", "-1"]),
]:
path = os.path.join(tmp, name)
w, h = (int(x) for x in size.split("x"))
V.ffmpeg(["-f", "lavfi", "-i", "testsrc2=size=%s:rate=%s" % (size, rate), "-frames:v", "6", "-vf",
"pad=%d:%d" % (w + 1, h + 1) if w % 2 else "null", "-s", size, "-pix_fmt", pix] + extra + [path])
frames = V.yuv_frames(path, w, h)
num, den = (rate.split("/") + ["1"])[:2]
cases.append({"name": name, "data": open(path, "rb").read(), "width": w, "height": h,
"rate": [int(num), int(den)], "frames": [V.crc(f) for f in frames], "yuv": frames[:2],
"exact": pix == "yuv420p"})
ctx.emit("y4m_cases", cases)