ws-video: bench block (whole pipeline fps for MJPEG AVI / MPEG-1 TS / VP8 WebM / Y4M at 320x240 and 640x480, y4m -> MJPEG AVI), docs/video.md (API, layers, how a codec plugs into the registry), NOTICE row for mpegts-luau

This commit is contained in:
4DBug committed 2026-10-31 10:05:09 -05:00
1 parent 26f4e0cb60
commit 0c9094d28a
4 files changed
+139

No files matched your search

+49
View File
@@ -825,3 +825,52 @@ do
end
end
end
-- ------------------------------------------------------------------------------------------- ws-video: containers
do
local F = require("@formats")
local VB = require("@tests/gen/videobench")
local function clock(n: number, f: () -> number): (number, number)
local frames = f()
local dt = math.huge
for _ = 1, n do
local t0 = os.clock()
frames = f()
dt = math.min(dt, os.clock() - t0)
end
return dt, frames
end
for _, c in VB do
local data = buffer.fromstring(c.data)
local dtOpen = clock(3, function(): number
F.video.open(data, { audio = false })
return 1
end)
for _, rgba in { false, true } do
local ok, dt, frames = pcall(clock, 2, function(): number
local v = assert(F.video.open(data, { audio = false, rgba = rgba }))
local n = 0
while true do
local f, err = v:nextFrame()
if not f then
assert(err == nil, tostring(err))
break
end
n += 1
end
return n
end)
if ok then
print(string.format("%-8s %-30s %8.2f ms %7.1f fps (open %.1f ms)", runtime, string.format("video %s %s %s", c.size, c.name, if rgba then "rgba" else "yuv"), dt * 1000 / frames, frames / dt, dtOpen * 1000))
else
print(string.format("%-8s %-30s %s", runtime, "video " .. c.size .. " " .. c.name, tostring(dt)))
end
end
if c.name == "raw.y4m" then
local dt, frames = clock(2, function(): number
assert(F.convert(data, "avi", { quality = 85 }))
return 8
end)
print(string.format("%-8s %-30s %8.2f ms %7.1f fps", runtime, "video " .. c.size .. " y4m -> mjpeg avi", dt * 1000 / frames, frames / dt))
end
end
end
+27
View File
@@ -0,0 +1,27 @@
# Video bench inputs (tools/fixtures.py, for tools/bench.luau): 1 s of testsrc2 at 320x240 and 640x480, 25 fps, as
# MJPEG AVI, MPEG-1 TS, VP8 WebM (libvpx) and 8 frames of 320x240 Y4M.
# tests/gen/videobench.luau { { name, size, data } }
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="videobench_")
out = []
for size in ("320x240", "640x480"):
src = ["-f", "lavfi", "-i", "testsrc2=size=%s:rate=25" % size, "-t", "1"]
for name, args in (("mjpeg.avi", ["-c:v", "mjpeg", "-q:v", "4"]),
("mpeg1.ts", ["-c:v", "mpeg1video", "-b:v", "2M", "-bf", "2", "-f", "mpegts"]),
("vp8.webm", ["-c:v", "libvpx", "-b:v", "1M", "-g", "50"]),
("raw.y4m", ["-pix_fmt", "yuv420p", "-frames:v", "8"])):
if name == "raw.y4m" and size == "640x480":
continue
path = os.path.join(tmp, size + "_" + name)
V.ffmpeg(src + args + [path])
out.append({"name": name, "size": size, "data": open(path, "rb").read()})
ctx.emit("videobench", out)