ws-video-codecs: mjpeg fixtures as base64 / zlib (8.6 -> 1.0 MB); codecs/Jpeg: no type assertion as an assignment target (darklua)
This commit is contained in:
1 parent
2493b9db36
commit
87d22bf67a
3 files changed
+51
-17
No files matched your search
+21
-11
@@ -13,12 +13,22 @@
|
||||
# ff = { yuv, rgba? } } }, fields = { data, width, height, yuv, rgba, src } }
|
||||
# tests/gen/mjpeg_enc.luau yuv420p sources and what tj3CompressFromYUV8 writes for them at a quality (our
|
||||
# encoder must write the same bytes), with djpeg's CRC and ffmpeg's PSNR of that file
|
||||
# tests/gen/mjpeg_bench.luau 320x240 and 640x480 frames (4:2:0, 4:2:2) and a 640x480 yuv420p source
|
||||
import ctypes, math, os, shutil, subprocess, tempfile, zlib
|
||||
# tests/gen/mjpeg_bench.luau 320x240 and 640x480 frames (4:2:0, 4:2:2) and yuv420p sources
|
||||
# Binary fields are base64 (JPEG data) or base64 of zlib data (raw planes / pixels, inflated with codecs/Deflate):
|
||||
# Luau string literals of binary data cost ~3.7 bytes per byte, base64 1.33.
|
||||
import base64, ctypes, math, os, shutil, subprocess, tempfile, zlib
|
||||
|
||||
FF = ["-hide_banner", "-loglevel", "error", "-y"]
|
||||
|
||||
|
||||
def b64(b):
|
||||
return base64.b64encode(b).decode()
|
||||
|
||||
|
||||
def z64(b):
|
||||
return base64.b64encode(zlib.compress(b, 9)).decode()
|
||||
|
||||
|
||||
def tool(ctx, pkg, name):
|
||||
p = shutil.which(name)
|
||||
if p:
|
||||
@@ -206,10 +216,10 @@ def _generate(ctx, work):
|
||||
for fr in frames:
|
||||
ref = fr
|
||||
data = mutate(fr) if mutate else fr
|
||||
entries.append({"data": data, "yuv": zlib.crc32(tj.yuv420(ref)), "rgba": rgba_crc(ref)})
|
||||
ref = {"yuv": ffdecode(frames[0], "yuvj420p")}
|
||||
entries.append({"data": b64(data), "yuv": zlib.crc32(tj.yuv420(ref)), "rgba": rgba_crc(ref)})
|
||||
ref = {"yuv": z64(ffdecode(frames[0], "yuvj420p"))}
|
||||
if w * h <= 30000 or name == "testsrc_420": # keep tests/gen small: rgba for the small ones and one 320x240
|
||||
ref["rgba"] = ffdecode(frames[0], "rgba")
|
||||
ref["rgba"] = z64(ffdecode(frames[0], "rgba"))
|
||||
streams.append({"name": name, "width": w, "height": h, "sampling": pix[4:7], "frames": entries, "ff": ref})
|
||||
|
||||
stream("testsrc_420", "testsrc2", 320, 240, "yuvj420p", 4, ("-q:v", "3"))
|
||||
@@ -267,8 +277,8 @@ def _generate(ctx, work):
|
||||
return rgba_of_pnm(subprocess.run([djpeg, "-dct", "int", "-pnm", p], check=True, capture_output=True).stdout)
|
||||
|
||||
wr = weave(rgba_raw(fields[0]), rgba_raw(fields[1]), fw, hf, 4)
|
||||
ctx.emit("mjpeg_cases", {"streams": streams, "fields": {"data": data, "width": fw, "height": fh,
|
||||
"yuv": zlib.crc32(wy), "rgba": zlib.crc32(wr), "src": fy}})
|
||||
ctx.emit("mjpeg_cases", {"streams": streams, "fields": {"data": b64(data), "width": fw, "height": fh,
|
||||
"yuv": zlib.crc32(wy), "rgba": zlib.crc32(wr), "src": z64(fy)}})
|
||||
|
||||
# the encoder: yuv420p sources, byte-identical with tj3CompressFromYUV8
|
||||
enc = []
|
||||
@@ -289,8 +299,8 @@ def _generate(ctx, work):
|
||||
if got:
|
||||
se = sum((a - b) ** 2 for a, b in zip(got[:w * h], raw[:w * h]))
|
||||
psnr = 99.0 if se == 0 else 10 * math.log10(255 * 255 * w * h / se)
|
||||
enc.append({"name": "%s_q%d" % (name, q), "width": w, "height": h, "quality": q, "yuv": raw,
|
||||
"want": want, "rgba": rgba_crc(want), "ffpsnr": round(psnr, 3)})
|
||||
enc.append({"name": "%s_q%d" % (name, q), "width": w, "height": h, "quality": q, "yuv": z64(raw),
|
||||
"want": b64(want), "rgba": rgba_crc(want), "ffpsnr": round(psnr, 3)})
|
||||
ctx.emit("mjpeg_enc", enc)
|
||||
|
||||
bench = []
|
||||
@@ -299,9 +309,9 @@ def _generate(ctx, work):
|
||||
o = W("bench.mjpeg")
|
||||
ff(*source("testsrc2", w, h, 1), "-pix_fmt", pix, "-c:v", "mjpeg", "-q:v", "3", "-f", "mjpeg", o)
|
||||
fr = split(open(o, "rb").read())[0]
|
||||
bench.append({"name": name, "width": w, "height": h, "data": fr, "yuv": zlib.crc32(tj.yuv420(fr))})
|
||||
bench.append({"name": name, "width": w, "height": h, "data": b64(fr), "yuv": zlib.crc32(tj.yuv420(fr))})
|
||||
srcs = []
|
||||
for w, h in ((320, 240), (640, 480)):
|
||||
ff(*source("testsrc2", w, h, 1), "-pix_fmt", "yuv420p", "-f", "rawvideo", W("b.yuv"))
|
||||
srcs.append({"width": w, "height": h, "yuv": open(W("b.yuv"), "rb").read()})
|
||||
srcs.append({"width": w, "height": h, "yuv": z64(open(W("b.yuv"), "rb").read())})
|
||||
ctx.emit("mjpeg_bench", {"frames": bench, "sources": srcs})
|
||||
Reference in new issue
Block a user