Files
rosetta/tools/fixtures/y4m.py
T

35 lines
1.9 KiB
Python

# 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)