ws-video2: MPEG-1 tests bit-exact against ffmpeg -idct int (308 of 312 frames; 4 with concealed macroblocks)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
4DBugandClaude Opus 5.5 committed 2026-10-31 14:30:45 -05:00
1 parent e0b1f5710d
commit f90fcbb029
2 files changed
+36 -6

No files matched your search

+25 -2
View File
@@ -1,4 +1,5 @@
-- codecs/video/Mpeg1 tests, ported from mpeg1-luau tests/decode.luau and tests/robust.luau. Against ffmpeg
-- codecs/video/Mpeg1 tests, ported from mpeg1-luau tests/decode.luau and tests/robust.luau. Every frame bit-exact with
-- `ffmpeg -idct int` (the IDCT codecs/video/Dsp reproduces; frames with concealed macroblocks excepted). Against ffmpeg
-- (tools/fixtures/mpeg1.py): every stream decodes, one access unit at a time, to as many frames as ffmpeg's decode,
-- in display order; each frame's RGBA channel means within 1.5 of ffmpeg's; whole sampled frames within 2 MAE per
-- channel (IDCT and colour rounding) and, as yuv420p (frameImage), within a PSNR floor of ffmpeg -pix_fmt yuv420p;
@@ -11,6 +12,7 @@ local Mpeg1 = require("@formats/codecs/video/Mpeg1")
local Base64 = require("@formats/core/Base64")
local Deflate = require("@formats/codecs/compress/Deflate")
local Types = require("@formats/Types")
local Crc32 = require("@formats/core/Crc32")
local STREAMS = {
require("@tests/gen/mpeg1_qcif_200k"),
@@ -81,6 +83,7 @@ local function psnr(a: buffer, ao: number, b: buffer, bo: number, n: number): nu
end
local MAE_LIMIT = 2
local totalExact, totalConcealed = 0, 0
local MEAN_LIMIT = 1.5
-- 1. every stream against ffmpeg
@@ -101,6 +104,7 @@ for _, fx in STREAMS do
local hasB = string.find(name, "bframes") ~= nil
local dec = Mpeg1.new({ reorder = hasB })
local frames = 0
local exact, concealed = 0, 0
local maxMae, maxMeanErr = 0, 0
local sums = {}
local function onFrame(f: any)
@@ -136,6 +140,21 @@ for _, fx in STREAMS do
end
t:check(buffer.readu8(px, 3) == 255 and buffer.readu8(px, n * 4 - 1) == 255, "alpha 255")
sums[frames] = buffer.tostring(px)
-- bit-exact against ffmpeg -idct int (outside macroblocks the decoder had to conceal)
local ex = fx.exact[frames]
if ex then
local img = Mpeg1.frameImage(f) :: Types.Image
local yc = Crc32.of(img.pixels, 0, n)
local uc = Crc32.of(img.pixels, n, cw * ch)
local vc = Crc32.of(img.pixels, n + cw * ch, cw * ch)
if yc == ex[1] and uc == ex[2] and vc == ex[3] then
exact += 1
elseif next(f.concealed) ~= nil then
concealed += 1
else
t:check(false, string.format("%s frame %d (type %d): differs from ffmpeg -idct int", name, frames, f.pictureType))
end
end
end
local t0 = os.clock()
for _, u in fx.units do
@@ -155,7 +174,10 @@ for _, fx in STREAMS do
t:eq(frames, fx.frames, name .. ": frames (ffmpeg's count)")
t:eq(dec.stats.errors, 0, name .. ": no bitstream errors")
worst = math.max(worst, maxMae)
t:note("%-13s %4dx%-4d %3d frames worst MAE %.3f means err %.3f %6.1f fps (with the checks)", name, w, h, frames, maxMae, maxMeanErr, frames / dt)
t:note("%-13s %4dx%-4d %3d frames %3d bit-exact worst MAE %.3f means err %.3f %6.1f fps (with the checks)", name, w, h, frames, exact, maxMae, maxMeanErr, frames / dt)
t:eq(exact + concealed, frames, name .. ": frames equal to ffmpeg -idct int (or with concealed macroblocks)")
totalExact += exact
totalConcealed += concealed
-- streamed: random pieces through write / decodeFrame, then flush
local d2 = Mpeg1.new({ reorder = hasB })
@@ -187,6 +209,7 @@ for _, fx in STREAMS do
t:eq(got, frames, name .. ": streamed frame count")
end
t:note("worst sampled-frame MAE %.3f (limit %d); worst yuv420p PSNR luma %.1f, chroma %.1f dB", worst, MAE_LIMIT, worstY, worstC)
t:note("%d frames bit-exact with ffmpeg -idct int, %d with concealed macroblocks (ffmpeg error concealment)", totalExact, totalConcealed)
-- 2. a size change mid-stream
do