ws-video: video/avi tests (OpenDML / idx1 / scan, PCM / ADPCM / MP2 audio, raw RGB / I420, mux round trip), video/y4m tests (every C tag, 10-bit, writer), empty audio chunks are padding
This commit is contained in:
1 parent
9411cd97c6
commit
d221bb5327
9 files changed
+402
-9
No files matched your search
@@ -163,9 +163,12 @@ end
|
||||
|
||||
-- seek(t, v, c, label, at): after seek(at) the next frame is the first at or after `at`
|
||||
function C.seek(t: any, v: any, c: any, label: string, at: number)
|
||||
if not c.frames or not Video.canDecode(v.codec) then
|
||||
if not (c.frames or c.rgba) or not Video.canDecode(v.codec) then
|
||||
return
|
||||
end
|
||||
if v.duration > 0 and at > v.duration * 0.6 then
|
||||
at = math.floor(v.duration * 50) / 100
|
||||
end
|
||||
v:seek(at)
|
||||
local f, ferr = v:nextFrame()
|
||||
if not f and ferr and string.find(ferr.message, "inter frames", 1, true) then
|
||||
@@ -173,7 +176,7 @@ function C.seek(t: any, v: any, c: any, label: string, at: number)
|
||||
return -- TEMP until ws/video-vp8 merges
|
||||
end
|
||||
t:check(f ~= nil and f.pts >= at - 1e-6 and f.pts < at + 0.2, label .. ": seek to " .. at .. " lands at " .. tostring(f and f.pts))
|
||||
if f and C.EXACT[v.codec] then
|
||||
if f and C.EXACT[v.codec] and c.frames then
|
||||
local idx = math.floor(f.pts * v.frameRate + 0.5) + 1
|
||||
t:eq(Crc32.of(f.image.pixels), c.frames[idx], label .. ": the frame after seeking equals ffmpeg's frame " .. idx)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
-- video/avi tests: AVI files from ffmpeg (MJPEG + PCM s16 / u8 / IMA ADPCM, MPEG-1 + MP2, uncompressed BGR24 / BGRA /
|
||||
-- I420) read through the OpenDML indexes, idx1 alone, and a movi scan: tracks and every packet against ffprobe,
|
||||
-- frames against ffmpeg, audio through the api hook, seeking; our muxer (MJPEG + PCM) read back; a GIF converted to
|
||||
-- AVI. Fixtures: tools/fixtures/avi.py.
|
||||
local T = require("@tests/T")
|
||||
local C = require("@tests/video/_common")
|
||||
local F = require("@formats")
|
||||
local AviFormat = require("@formats/video/avi")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Fx = require("@tests/gen/avi_cases")
|
||||
|
||||
local t = T.suite("avi")
|
||||
|
||||
t:eq(AviFormat.name, "avi", "name")
|
||||
t:eq(AviFormat.category, "video", "category")
|
||||
|
||||
local EXACT_AUDIO = { pcm_s16le = true, pcm_u8 = true, adpcm_ima_wav = true }
|
||||
local byName = {}
|
||||
for _, c in Fx do
|
||||
byName[c.name] = c
|
||||
end
|
||||
|
||||
for _, c in Fx do
|
||||
local label = c.name
|
||||
t:check(AviFormat.sniff(Bytes.reader(buffer.fromstring(c.data))) > 0, label .. ": sniff")
|
||||
local v, err = C.open(c.data)
|
||||
if c.truncated then
|
||||
t:check(v ~= nil or err ~= nil, label .. ": opens or fails cleanly")
|
||||
else
|
||||
t:check(v ~= nil, label .. ": open: " .. tostring(err))
|
||||
if v then
|
||||
local dmx = v.demuxer
|
||||
t:eq(#dmx.tracks, #c.streams, label .. ": track count")
|
||||
C.packets(t, dmx, c, label)
|
||||
if c.rgba then
|
||||
v:reset()
|
||||
local n, bad = 0, 0
|
||||
while true do
|
||||
local f = v:nextFrame()
|
||||
if not f then
|
||||
break
|
||||
end
|
||||
n += 1
|
||||
if f.image.format ~= "rgba8" or Crc32.of(f.image.pixels) ~= c.rgba[n] then
|
||||
bad += 1
|
||||
end
|
||||
end
|
||||
t:check(n == #c.rgba and bad == 0, label .. ": " .. n .. " rgba frames equal ffmpeg's (" .. bad .. " differ)")
|
||||
else
|
||||
C.frames(t, v, c, label)
|
||||
end
|
||||
local at = dmx:track("audio")
|
||||
if at then
|
||||
C.audio(t, v, c, label, EXACT_AUDIO[at.codec], 30)
|
||||
end
|
||||
C.seek(t, v, c, label, 0.5)
|
||||
end
|
||||
end
|
||||
end
|
||||
t:eq(C.open(byName["mjpeg_pcm.avi"].data).demuxer.meta.index, "idx1", "ffmpeg's AVI: idx1 used")
|
||||
t:eq(C.open(byName["odml.avi"].data).demuxer.meta.index, "odml", "OpenDML indexes used")
|
||||
t:eq(C.open(byName["idx1_only.avi"].data).demuxer.meta.index, "idx1", "idx1 used without OpenDML indexes")
|
||||
t:eq(C.open(byName["no_index.avi"].data).demuxer.meta.index, "scan", "movi scanned without indexes")
|
||||
|
||||
-- our muxer: MJPEG copied + PCM, read back packet for packet
|
||||
do
|
||||
local v = C.open(byName["mjpeg_pcm.avi"].data)
|
||||
local out, err = F.save(v, nil, { format = "avi" })
|
||||
t:check(out ~= nil, "mux avi: " .. tostring(err))
|
||||
if out then
|
||||
local v2 = F.video.open(out)
|
||||
t:check(v2 ~= nil, "mux avi: reads back")
|
||||
if v2 then
|
||||
local a, b = v.demuxer, v2.demuxer
|
||||
local same = a:count(1) == b:count(1)
|
||||
for k = 1, a:count(1) do
|
||||
local p, q = a:get(1, k), b:get(1, k)
|
||||
if not q or buffer.tostring(p.data) ~= buffer.tostring(q.data) then
|
||||
same = false
|
||||
end
|
||||
end
|
||||
t:check(same, "mux avi: identical MJPEG packets")
|
||||
t:eq(v2.frameRate, 10, "mux avi: frame rate")
|
||||
C.audio(t, v2, byName["mjpeg_pcm.avi"], "mux avi", true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- fuzz
|
||||
local samples = {}
|
||||
for _, n in { "mjpeg_pcm.avi", "mjpeg_ima.avi", "idx1_only.avi", "i420.avi" } do
|
||||
local d = byName[n].data
|
||||
table.insert(samples, string.sub(d, 1, math.min(#d, 40000)))
|
||||
end
|
||||
t:fuzz("open", C.fuzzOpen(AviFormat), samples, { mutations = 6, garbage = 100 })
|
||||
t:done()
|
||||
@@ -0,0 +1,103 @@
|
||||
-- video/y4m tests: YUV4MPEG2 streams from ffmpeg (C420jpeg at an odd size, C420mpeg2, C422, C444, Cmono, C420p10)
|
||||
-- against ffmpeg's yuv420p decode (bit-exact for 4:2:0 8-bit, PSNR for the converted layouts), the header fields,
|
||||
-- our writer round trip (and from an rgba frames-backed video), errors and the fuzz pass. Fixtures:
|
||||
-- tools/fixtures/y4m.py.
|
||||
local T = require("@tests/T")
|
||||
local C = require("@tests/video/_common")
|
||||
local F = require("@formats")
|
||||
local Y4m = require("@formats/video/y4m")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Err = require("@formats/core/Err")
|
||||
local Types = require("@formats/Types")
|
||||
local Fx = require("@tests/gen/y4m_cases")
|
||||
|
||||
local t = T.suite("y4m")
|
||||
t:eq(Y4m.name, "y4m", "name")
|
||||
|
||||
for _, c in Fx do
|
||||
local label = c.name
|
||||
t:check(Y4m.sniff(Bytes.reader(buffer.fromstring(c.data))) == 1, label .. ": sniff")
|
||||
local v, err = Y4m.open(Bytes.reader(buffer.fromstring(c.data)))
|
||||
t:check(v ~= nil, label .. ": open " .. tostring(err))
|
||||
if v then
|
||||
t:check(v.width == c.width and v.height == c.height, label .. ": size")
|
||||
t:check(math.abs(v.frameRate - c.rate[1] / c.rate[2]) < 1e-9, label .. ": frame rate")
|
||||
local n, bad, worst = 0, 0, math.huge
|
||||
while true do
|
||||
local f = v:nextFrame()
|
||||
if not f then
|
||||
break
|
||||
end
|
||||
n += 1
|
||||
if c.exact then
|
||||
if Crc32.of(f.image.pixels) ~= c.frames[n] then
|
||||
bad += 1
|
||||
end
|
||||
elseif c.yuv[n] then
|
||||
worst = math.min(worst, C.psnr(f.image.pixels, buffer.fromstring(c.yuv[n])))
|
||||
end
|
||||
end
|
||||
t:eq(n, #c.frames, label .. ": frame count")
|
||||
if c.exact then
|
||||
t:check(bad == 0, label .. ": frames bit-exact with ffmpeg")
|
||||
else
|
||||
t:check(worst > 30, string.format("%s: PSNR vs ffmpeg %.1f dB", label, worst))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- writer: a y4m stream back to y4m is byte-identical in its frames; header as ffmpeg writes it
|
||||
do
|
||||
local c = Fx[1]
|
||||
local v = F.video.open(buffer.fromstring(c.data))
|
||||
local out, err = F.save(v, nil, { format = "y4m" })
|
||||
t:check(out ~= nil, "write: " .. tostring(err))
|
||||
if out then
|
||||
local s = buffer.tostring(out)
|
||||
t:check(string.find(s, "YUV4MPEG2 W173 H95 F30000:1001 Ip A1:1 C420jpeg XYSCSS=420JPEG\n", 1, true) == 1, "write: header " .. string.sub(s, 1, 60))
|
||||
local v2 = Y4m.open(Bytes.reader(out))
|
||||
local n, same = 0, true
|
||||
while true do
|
||||
local f = v2:nextFrame()
|
||||
if not f then
|
||||
break
|
||||
end
|
||||
n += 1
|
||||
same = same and Crc32.of(f.image.pixels) == c.frames[n]
|
||||
end
|
||||
t:check(n == #c.frames and same, "write: frames round trip")
|
||||
end
|
||||
-- an rgba frames-backed video (a 2-frame animation) to y4m
|
||||
local a = Types.Image.new(4, 2)
|
||||
buffer.fill(a.pixels, 0, 255)
|
||||
local b = Types.Image.new(4, 2)
|
||||
a.frames = { { image = a, delay = 0.5, x = 0, y = 0, dispose = "none", blend = "source" }, { image = b, delay = 0.5, x = 0, y = 0, dispose = "none", blend = "source" } }
|
||||
local y, yerr = F.save(a, nil, { format = "y4m" })
|
||||
t:check(y ~= nil, "write from frames: " .. tostring(yerr))
|
||||
if y then
|
||||
local v3 = Y4m.open(Bytes.reader(y))
|
||||
local f1 = v3:nextFrame()
|
||||
local f2 = v3:nextFrame()
|
||||
t:check(f1 ~= nil and f2 ~= nil and v3:nextFrame() == nil, "write from frames: 2 frames")
|
||||
t:eq(v3.frameRate, 2, "write from frames: frame rate from the delays")
|
||||
t:eq(buffer.readu8(f1.image.pixels, 0), 235, "write from frames: white -> Y 235 (limited range)")
|
||||
t:eq(buffer.readu8(f2.image.pixels, 0), 16, "write from frames: black -> Y 16")
|
||||
end
|
||||
end
|
||||
|
||||
-- errors
|
||||
local function code(s: string): string?
|
||||
local _, e = Y4m.open(Bytes.reader(buffer.fromstring(s)))
|
||||
return e and e.code
|
||||
end
|
||||
t:eq(code("YUV4MPEG2 W0 H0\n"), Err.CORRUPT, "zero size")
|
||||
t:eq(code("YUV4MPEG2 W16 H16 Cfoo\n"), Err.UNSUPPORTED, "unknown colour space")
|
||||
t:eq(code("YUV4MPEG2 W99999999 H99999 C420\n"), Err.CORRUPT, "huge size")
|
||||
t:eq(code("YUV4MPEG2 W16 H16"), Err.TRUNCATED, "no header end")
|
||||
local samples = {}
|
||||
for _, c in Fx do
|
||||
table.insert(samples, string.sub(c.data, 1, 30000))
|
||||
end
|
||||
t:fuzz("open", C.fuzzOpen(Y4m), samples, { mutations = 6, garbage = 100 })
|
||||
t:done()
|
||||
Reference in new issue
Block a user