84 lines
3.1 KiB
Luau
84 lines
3.1 KiB
Luau
-- video writer tests: files our muxers wrote (tools/fixtures/_video_encode.luau: WebM remux, MJPEG Matroska / AVI
|
|
-- copied and re-encoded from VP8 / MPEG-1, an animated GIF with uneven delays to AVI / Matroska / Y4M, WebM to Y4M)
|
|
-- were probed by ffprobe and decoded by ffmpeg at fixture time; here our demuxers must see the same packets, our
|
|
-- decoders the same frames (CRC for VP8 / raw, PSNR for MJPEG) and audio; the writers are rerun and must give the same
|
|
-- bytes. Fixtures: tools/fixtures/videoenc.py.
|
|
local T = require("@tests/T")
|
|
local C = require("@tests/video/_common")
|
|
local F = require("@formats")
|
|
local Fx = require("@tests/gen/videoenc_cases")
|
|
local Src = require("@tests/gen/videoenc_src")
|
|
|
|
local t = T.suite("video encode")
|
|
|
|
local byName = {}
|
|
for _, c in Fx do
|
|
byName[c.name] = c
|
|
end
|
|
|
|
for _, c in Fx do
|
|
local label = c.name
|
|
if c.err then
|
|
t:note("%s: not written at fixture time: %s", label, c.err)
|
|
else
|
|
local v, err = C.open(c.data)
|
|
t:check(v ~= nil, label .. ": opens: " .. tostring(err))
|
|
if v then
|
|
t:eq(#v.demuxer.tracks, #c.streams, label .. ": track count (ffprobe)")
|
|
-- (ffmpeg's AVI demuxer cuts PCM chunks into 1024-sample packets: AVI audio is compared decoded)
|
|
local avi = string.sub(label, -4) == ".avi"
|
|
C.packets(t, v.demuxer, c, label, { skipStream = function(_: any, tr: any): boolean
|
|
return avi and tr ~= nil and tr.kind == "audio"
|
|
end })
|
|
C.frames(t, v, c, label, 40)
|
|
local at = v.demuxer:track("audio")
|
|
if at then
|
|
C.audio(t, v, c, label, string.sub(at.codec, 1, 4) == "pcm_", 30)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
-- the GIF (100 / 50 / 200 / 100 ms) at a constant 20 fps: 2 + 1 + 4 + 2 frames
|
|
do
|
|
local c = byName["gif.avi"]
|
|
if c and c.frames then
|
|
t:eq(#c.frames, 9, "gif.avi: 9 frames at 20 fps (ffmpeg)")
|
|
local v = C.open(c.data)
|
|
t:eq(v.frameRate, 20, "gif.avi: 20 fps")
|
|
end
|
|
local y = byName["gif.y4m"]
|
|
if y and y.frames then
|
|
t:eq(#y.frames, 9, "gif.y4m: 9 frames (ffmpeg)")
|
|
end
|
|
-- F.video.open on the GIF itself: a frames-backed video
|
|
local g = F.video.open(buffer.fromstring(Src.gif))
|
|
t:check(g ~= nil and g.codec == "frames" and g.frames == 4, "F.video.open(gif): 4 frames")
|
|
if g then
|
|
local f1 = g:nextFrame()
|
|
local f2 = g:nextFrame()
|
|
t:check(f1 and f1.image.format == "rgba8" and f1.duration == 0.1 and f2 and f2.pts == 0.1 and f2.duration == 0.05, "gif frames: rgba8 with the GIF's times")
|
|
g:seek(0.2)
|
|
local f3 = g:nextFrame()
|
|
t:check(f3 ~= nil and f3.index == 3, "gif seek: frame 3 at 0.15 s holds 0.2 s")
|
|
end
|
|
end
|
|
|
|
-- the writers are deterministic: the same bytes again
|
|
do
|
|
local Mkv = require("@tests/gen/mkv_cases")
|
|
local remux = byName["remux.webm"]
|
|
for _, m in Mkv do
|
|
if m.name == "vp8_opus.webm" and remux and remux.data then
|
|
local out = F.convert(buffer.fromstring(m.data), "webm")
|
|
t:check(out ~= nil and buffer.tostring(out) == remux.data, "remux.webm: written again byte for byte")
|
|
end
|
|
end
|
|
local gifAvi = byName["gif.avi"]
|
|
if gifAvi and gifAvi.data then
|
|
local out = F.convert(buffer.fromstring(Src.gif), "avi", { quality = 95 })
|
|
t:check(out ~= nil and buffer.tostring(out) == gifAvi.data, "gif.avi: F.convert(gif, 'avi') again byte for byte")
|
|
end
|
|
end
|
|
t:done()
|