ws-video: writers checked by ffprobe / ffmpeg (tools/fixtures/videoenc.py + _video_encode.luau, tests/video/encode.luau); constant-rate output for AVI / Y4M shared in Source.constantRate (uneven GIF delays repeat frames)
This commit is contained in:
1 parent
bd06545e2e
commit
8d2deb13ab
6 files changed
+248
-59
No files matched your search
@@ -0,0 +1,46 @@
|
||||
-- tools/fixtures/_video_encode: run by tools/fixtures/videoenc.py (luau, from the repo root) so ffprobe / ffmpeg can
|
||||
-- check our video writers: remuxes and re-encodes the container fixtures (tests/gen/mkv_cases, avi_cases) and the
|
||||
-- animated GIF of tests/gen/videoenc_src, and prints "<name> <hex>" lines (or "<name> ERR <message>").
|
||||
local F = require("@formats")
|
||||
local Mkv = require("@tests/gen/mkv_cases")
|
||||
local Avi = require("@tests/gen/avi_cases")
|
||||
local Src = require("@tests/gen/videoenc_src")
|
||||
|
||||
local function hex(b: buffer): string
|
||||
local t = table.create(buffer.len(b))
|
||||
for i = 0, buffer.len(b) - 1 do
|
||||
t[i + 1] = string.format("%02x", buffer.readu8(b, i))
|
||||
end
|
||||
return table.concat(t)
|
||||
end
|
||||
|
||||
local function find(list: any, name: string): string
|
||||
for _, c in list do
|
||||
if c.name == name then
|
||||
return c.data
|
||||
end
|
||||
end
|
||||
error("no fixture " .. name)
|
||||
end
|
||||
|
||||
local JOBS = {
|
||||
{ "remux.webm", find(Mkv, "vp8_opus.webm"), "webm", {} },
|
||||
{ "copy.mkv", find(Mkv, "mjpeg_pcm.mkv"), "mkv", {} },
|
||||
{ "vp8_mjpeg.mkv", find(Mkv, "vp8_opus.webm"), "mkv", { reencode = true, quality = 92 } },
|
||||
{ "copy.avi", find(Avi, "mjpeg_pcm.avi"), "avi", {} },
|
||||
{ "vp8_mjpeg.avi", find(Mkv, "vp8_opus.webm"), "avi", { quality = 92 } },
|
||||
{ "mpeg1_mjpeg.avi", find(Mkv, "mpeg1_mp2.mkv"), "avi", { quality = 92 } },
|
||||
{ "gif.avi", Src.gif, "avi", { quality = 95 } },
|
||||
{ "gif.mkv", Src.gif, "mkv", { quality = 95 } },
|
||||
{ "gif.y4m", Src.gif, "y4m", {} },
|
||||
{ "webm.y4m", find(Mkv, "vp8_opus.webm"), "y4m", {} },
|
||||
}
|
||||
for _, j in JOBS do
|
||||
local name, data, fmt, opts = j[1], j[2], j[3], j[4]
|
||||
local out, err = F.convert(buffer.fromstring(data), fmt, opts)
|
||||
if out then
|
||||
print(name .. " " .. hex(out))
|
||||
else
|
||||
print(name .. " ERR " .. string.gsub(tostring(err), "%s", "_"))
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,62 @@
|
||||
# Our video writers checked by ffprobe / ffmpeg (tools/fixtures.py): tools/fixtures/_video_encode.luau remuxes /
|
||||
# re-encodes the container fixtures (WebM remux, MJPEG Matroska / AVI from VP8 and MPEG-1, MJPEG copies, an animated
|
||||
# GIF with uneven delays to AVI / Matroska / Y4M, WebM to Y4M); each output must probe in ffprobe and decode in
|
||||
# ffmpeg. Emitted per file: our bytes, ffprobe's streams and packets, ffmpeg's frames (CRC-32; the first raw) and
|
||||
# audio, so the test can decode our file with our decoders and compare.
|
||||
# tests/gen/videoenc_src.luau { gif = <animated GIF made by Pillow: 4 frames, 100 / 50 / 200 / 100 ms> }
|
||||
# tests/gen/videoenc_cases.luau { { name, data, streams, packets, frames, yuv, pcm, pcmBytes } | { name, err } }
|
||||
import importlib.util, os, shutil, subprocess, 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", "tools/fixtures/_video_encode.luau", "tools/fixtures/mkv.py", "tools/fixtures/avi.py",
|
||||
"src/Formats/video", "src/Formats/codecs/Video", "src/Formats/containers/Ebml", "src/Formats/containers/Avi",
|
||||
"src/Formats/codecs/Jpeg", "src/Formats/codecs/Vp8"]
|
||||
|
||||
GIF = r"""
|
||||
import io, sys
|
||||
from PIL import Image, ImageDraw
|
||||
frames = []
|
||||
for i, c in enumerate([(255, 0, 0), (0, 160, 0), (0, 0, 255), (240, 200, 0)]):
|
||||
im = Image.new("RGB", (64, 48), (20, 20, 20))
|
||||
d = ImageDraw.Draw(im)
|
||||
d.rectangle([4 + i * 10, 8, 24 + i * 10, 40], fill=c)
|
||||
d.ellipse([40, 4 + i * 6, 60, 20 + i * 6], fill=(255, 255, 255))
|
||||
frames.append(im)
|
||||
b = io.BytesIO()
|
||||
frames[0].save(b, "GIF", save_all=True, append_images=frames[1:], duration=[100, 50, 200, 100], loop=0)
|
||||
sys.stdout.buffer.write(b.getvalue())
|
||||
"""
|
||||
|
||||
|
||||
def generate(ctx):
|
||||
tmp = tempfile.mkdtemp(prefix="videoenc_")
|
||||
gif = ctx.python(["pillow"], GIF)
|
||||
ctx.emit("videoenc_src", {"gif": gif})
|
||||
luau = os.environ.get("LUAU") or shutil.which("luau")
|
||||
cmd = [luau, "tools/fixtures/_video_encode.luau"] if luau else ["nix", "shell", "nixpkgs#luau", "-c", "luau", "tools/fixtures/_video_encode.luau"]
|
||||
out = subprocess.run(cmd, capture_output=True, check=True, cwd=ctx.root).stdout.decode()
|
||||
cases = []
|
||||
for line in out.split("\n"):
|
||||
if not line.strip():
|
||||
continue
|
||||
name, rest = line.split(" ", 1)
|
||||
if rest.startswith("ERR "):
|
||||
cases.append({"name": name, "err": rest[4:]})
|
||||
continue
|
||||
path = os.path.join(tmp, name)
|
||||
open(path, "wb").write(bytes.fromhex(rest))
|
||||
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:
|
||||
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[:3]
|
||||
if any(s["kind"] == "audio" for s in c["streams"]):
|
||||
pcm = V.pcm_f32(path)
|
||||
c["pcm"] = pcm[:8192 * 4]
|
||||
c["pcmBytes"] = len(pcm)
|
||||
cases.append(c)
|
||||
ctx.emit("videoenc_cases", cases)
|
||||
Reference in new issue
Block a user