ws-video-vp8: VP8 inter frames (libvpx 1.17 port): references, modes / motion vectors, split, six-tap / bilinear prediction, inter loop filter levels, hidden frames, reset; tests vs ffmpeg on 27 test vectors + 24 libvpx clips
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
75c677074a
commit
aff15e7cc9
36 files changed
+1338
-161
No files matched your search
@@ -56,7 +56,7 @@ do
|
||||
local inter = buffer.fromstring(frames[1])
|
||||
buffer.writeu8(inter, 0, bit32.bor(buffer.readu8(inter, 0), 1))
|
||||
local _, e1 = Vp8.decodeFrame(inter)
|
||||
t:check(e1 and e1.code == Err.UNSUPPORTED, "inter frame: " .. tostring(e1))
|
||||
t:check(e1 and e1.code == Err.CORRUPT, "inter frame without a key frame: " .. tostring(e1))
|
||||
local bad = buffer.fromstring(frames[1])
|
||||
buffer.writeu8(bad, 3, 0)
|
||||
local _, e2 = Vp8.decodeFrame(bad)
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
-- codecs/Vp8 video tests: whole IVF streams through one decoder object, every shown frame bit-exact against ffmpeg's
|
||||
-- native vp8 decoder (yuv420p CRC32): the official VP8 test vectors (vp80-00-comprehensive-001..018 and others) and
|
||||
-- libvpx clips at many settings (alt-ref / hidden frames, golden, token partitions, error resilience, profiles 1-3,
|
||||
-- sharpness, segmentation, q extremes, short key frame intervals, motion off the frame, odd sizes). Also hidden
|
||||
-- frames, reset() and inter frames without a key frame, and the fuzz no-throw pass over damaged streams.
|
||||
-- Fixtures: tools/fixtures/vp8video.py.
|
||||
local T = require("@tests/T")
|
||||
local Vp8 = require("@formats/codecs/Vp8")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Cases = require("@tests/gen/vp8video_cases")
|
||||
|
||||
local t = T.suite("vp8video")
|
||||
|
||||
-- the frames of an IVF file: { offset, length }
|
||||
local function ivfFrames(b: buffer): { { number } }
|
||||
local out = {}
|
||||
local p = buffer.readu16(b, 6) -- header length (32)
|
||||
while p + 12 <= buffer.len(b) do
|
||||
local n = buffer.readu32(b, p)
|
||||
if p + 12 + n > buffer.len(b) then
|
||||
break
|
||||
end
|
||||
table.insert(out, { p + 12, n })
|
||||
p += 12 + n
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
local total, hidden, vectors = 0, 0, 0
|
||||
local samples: { buffer } = {}
|
||||
for _, c in Cases do
|
||||
local b = buffer.fromstring(c.ivf)
|
||||
local fr = ivfFrames(b)
|
||||
local dec = Vp8.newDecoder()
|
||||
local shown, bad, firstBad = 0, 0, ""
|
||||
local ok = true
|
||||
for i, f in fr do
|
||||
local img, err = dec:decodeFrame(b, f[1], f[2])
|
||||
if not img then
|
||||
ok = false
|
||||
firstBad = "frame " .. i .. ": " .. tostring(err)
|
||||
break
|
||||
end
|
||||
local src = img.meta.source
|
||||
if src.show then
|
||||
shown += 1
|
||||
if buffer.len(img.pixels) ~= c.sizes[shown] or Crc32.of(img.pixels) ~= c.crcs[shown] then
|
||||
bad += 1
|
||||
if bad == 1 then
|
||||
firstBad = string.format("frame %d (shown %d, %s)", i, shown, if src.keyFrame then "key" else "inter")
|
||||
end
|
||||
end
|
||||
else
|
||||
hidden += 1
|
||||
end
|
||||
end
|
||||
t:check(ok and bad == 0 and shown == #c.crcs, string.format("%s: %d / %d frames bit-exact, %d shown of %d; first bad: %s", c.name, shown - bad, #c.crcs, shown, #fr, firstBad))
|
||||
total += shown
|
||||
if string.sub(c.name, 1, 5) == "vp80-" then
|
||||
vectors += 1
|
||||
end
|
||||
if #samples < 6 and #c.ivf < 40000 then
|
||||
table.insert(samples, b)
|
||||
end
|
||||
end
|
||||
t:note("%d streams (%d official test vectors), %d shown frames bit-exact with ffmpeg, %d hidden frames", #Cases, vectors, total, hidden)
|
||||
|
||||
-- hidden frames, reset(), inter frames without a key frame
|
||||
do
|
||||
local c
|
||||
for _, x in Cases do
|
||||
if x.name == "altref_352x288" then
|
||||
c = x
|
||||
end
|
||||
end
|
||||
local b = buffer.fromstring(c.ivf)
|
||||
local fr = ivfFrames(b)
|
||||
local dec = Vp8.newDecoder()
|
||||
local _, e0 = dec:decodeFrame(b, fr[2][1], fr[2][2])
|
||||
t:check(e0 and e0.code == Err.CORRUPT, "inter frame first: " .. tostring(e0))
|
||||
local key = dec:decodeFrame(b, fr[1][1], fr[1][2]) :: any
|
||||
t:check(key and key.meta.source.keyFrame and key.meta.source.show and key.meta.source.format == "vp8", "key frame meta")
|
||||
local sawHidden = false
|
||||
for i = 2, #fr do
|
||||
local img = dec:decodeFrame(b, fr[i][1], fr[i][2]) :: any
|
||||
if img and not img.meta.source.show then
|
||||
sawHidden = true
|
||||
t:check(not img.meta.source.keyFrame and img.width == c.width, "hidden frame is an Image")
|
||||
end
|
||||
end
|
||||
t:check(sawHidden, "the alt-ref stream has a hidden frame")
|
||||
-- the returned planes are a copy: decoding more frames leaves an earlier image alone
|
||||
local d2 = Vp8.newDecoder()
|
||||
local first = d2:decodeFrame(b, fr[1][1], fr[1][2]) :: any
|
||||
local crc = Crc32.of(first.pixels)
|
||||
d2:decodeFrame(b, fr[2][1], fr[2][2])
|
||||
d2:decodeFrame(b, fr[3][1], fr[3][2])
|
||||
t:eq(Crc32.of(first.pixels), crc, "images are fresh buffers")
|
||||
dec:reset()
|
||||
local _, e1 = dec:decodeFrame(b, fr[3][1], fr[3][2])
|
||||
t:check(e1 and e1.code == Err.CORRUPT, "inter frame after reset: " .. tostring(e1))
|
||||
local again = dec:decodeFrame(b, fr[1][1], fr[1][2]) :: any
|
||||
t:eq(again and Crc32.of(again.pixels), c.crcs[1], "key frame after reset")
|
||||
local nxt = dec:decodeFrame(b, fr[2][1], fr[2][2]) :: any
|
||||
t:check(nxt ~= nil, "inter frame after the key frame")
|
||||
local _, e2 = Vp8.decodeFrame(b, fr[2][1], fr[2][2])
|
||||
t:check(e2 and e2.code == Err.CORRUPT, "one-shot decodeFrame of an inter frame")
|
||||
local _, e3 = dec:decodeFrame(b, fr[2][1], 2)
|
||||
t:check(e3 and e3.code == Err.TRUNCATED, "truncated frame tag: " .. tostring(e3))
|
||||
end
|
||||
|
||||
-- fuzz: whole damaged streams through one decoder (truncated / mutated frames after valid ones)
|
||||
local function feed(b: buffer)
|
||||
local dec = Vp8.newDecoder()
|
||||
local any = false
|
||||
local p, n = 32, buffer.len(b)
|
||||
while p + 12 <= n do
|
||||
local len = math.min(buffer.readu32(b, p), n - p - 12)
|
||||
local img = dec:decodeFrame(b, p + 12, len, { maxPixels = 2 ^ 20 })
|
||||
any = any or img ~= nil
|
||||
p += 12 + len
|
||||
end
|
||||
return any, nil
|
||||
end
|
||||
t:fuzz("stream", feed, samples, { mutations = 6, keepHeader = 32 })
|
||||
t:fuzz("stream (more damage)", feed, samples, { mutations = 30, keepHeader = 32, garbage = 20 })
|
||||
|
||||
t:done()
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Reference in new issue
Block a user