From b7af1cad75f746bf47e37950c266188e0b199b08 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sat, 31 Oct 2026 10:05:40 -0500 Subject: [PATCH] ws-video: animated WebP through F.video.open checked against Pillow's canvases --- tests/video/encode.luau | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/video/encode.luau b/tests/video/encode.luau index a81e4b0..ef009a7 100644 --- a/tests/video/encode.luau +++ b/tests/video/encode.luau @@ -64,6 +64,39 @@ do end end +-- animated WebP through F.video.open: frames-backed, the canvases equal Pillow's (libwebp's WebPAnimDecoder) +do + local Crc32 = require("@formats/core/Crc32") + local Anims = require("@tests/gen/webp_anim") + for _, a in Anims do + local v = F.video.open(buffer.fromstring(a.data)) + t:check(v ~= nil and v.codec == "frames" and v.frames == #a.frames, a.name .. ": opens as a " .. #a.frames .. "-frame video") + if v then + local bad, n, t0 = 0, 0, 0 + while true do + local f = v:nextFrame() + if not f then + break + end + n += 1 + local px = f.image.pixels + if a.rgba == false then + px = buffer.create(buffer.len(f.image.pixels)) + buffer.copy(px, 0, f.image.pixels) + for i = 3, buffer.len(px) - 1, 4 do + buffer.writeu8(px, i, 255) + end + end + if Crc32.of(px) ~= a.frames[n].crc or math.abs(f.pts - t0) > 1e-6 then + bad += 1 + end + t0 += a.frames[n].ms / 1000 + end + t:check(n == #a.frames and bad == 0, a.name .. ": video frames equal Pillow's canvases and times (" .. bad .. " differ)") + end + end +end + -- the writers are deterministic: the same bytes again do local Mkv = require("@tests/gen/mkv_cases")