ws-video2: MPEG-2 in MPEG-TS (0x02 / private 0x80), MPEG-PS, MKV, AVI, MP4 caps; tests/video/mpeg2.luau
This commit is contained in:
1 parent
3146ec0936
commit
22db57f348
8 files changed
+103
-21
No files matched your search
@@ -0,0 +1,80 @@
|
||||
-- MPEG-2 video in the containers (tools/fixtures/mpeg2.py, "mpeg2_containers"): the same elementary stream copied by
|
||||
-- ffmpeg into MPEG-TS (stream type 0x02, and the PMT patched to 0x80, private / DigiCipher II video), MPEG-PS (VOB),
|
||||
-- Matroska (V_MPEG2) and AVI: each opens through F.video.open with codec "mpeg2", its frames equal ffmpeg's
|
||||
-- `-idct int` decode (luma CRC per frame, display order), seeking lands on a frame; the raw .m2v opens too.
|
||||
local T = require("@tests/T")
|
||||
local F = require("@formats")
|
||||
local Base64 = require("@formats/core/Base64")
|
||||
local Crc32 = require("@formats/core/Crc32")
|
||||
local Fx = require("@tests/gen/mpeg2_containers")
|
||||
local Prog = require("@tests/gen/mpeg2_prog")
|
||||
|
||||
local t = T.suite("video/mpeg2")
|
||||
|
||||
local function lumaCrc(img: any): number
|
||||
return Crc32.of(img.pixels, 0, img.width * img.height)
|
||||
end
|
||||
|
||||
local CASES = {
|
||||
{ "ts", "mpegts" },
|
||||
{ "ts80", "mpegts" },
|
||||
{ "mpg", "mpegps" },
|
||||
{ "mkv", "mkv" },
|
||||
{ "avi", "avi" },
|
||||
}
|
||||
for _, c in CASES do
|
||||
local key, format = c[1], c[2]
|
||||
local data = Base64.decode(Fx[key]) :: buffer
|
||||
local v, err = F.video.open(data)
|
||||
t:check(v ~= nil, key .. ": opens: " .. tostring(err))
|
||||
if v then
|
||||
t:eq(v.format, format, key .. ": format")
|
||||
t:eq(v.codec, "mpeg2", key .. ": codec")
|
||||
t:check(v.width == Prog.width and v.height == Prog.height, key .. ": size")
|
||||
local frames, exact = 0, 0
|
||||
while true do
|
||||
local f, ferr = v:nextFrame()
|
||||
t:check(ferr == nil, key .. ": frame error " .. tostring(ferr))
|
||||
if not f then
|
||||
break
|
||||
end
|
||||
frames += 1
|
||||
local ref = Fx.crcs[frames]
|
||||
if ref and lumaCrc(f.image) == ref[1] then
|
||||
exact += 1
|
||||
end
|
||||
end
|
||||
t:eq(frames, #Fx.crcs, key .. ": frame count")
|
||||
-- the frames ffmpeg's encoder left with an uncoded macroblock are concealed differently (tests/codecs/mpeg2)
|
||||
t:check(exact >= frames - 2, string.format("%s: %d of %d frames equal ffmpeg's", key, exact, frames))
|
||||
v:seek(0.4)
|
||||
local f = v:nextFrame()
|
||||
t:check(f ~= nil and math.abs(f.pts - 0.4) < 0.05, key .. ": seek")
|
||||
t:note(" %-5s %-7s %d frames, %d bit-exact", key, format, frames, exact)
|
||||
end
|
||||
end
|
||||
|
||||
-- the elementary stream itself
|
||||
do
|
||||
local v, err = F.video.open(Base64.decode(Prog.file) :: buffer)
|
||||
t:check(v ~= nil and v.codec == "mpeg2", "m2v: opens as mpeg2: " .. tostring(err))
|
||||
if v then
|
||||
local n = 0
|
||||
while v:nextFrame() do
|
||||
n += 1
|
||||
end
|
||||
t:eq(n, Prog.frames, "m2v: frame count")
|
||||
end
|
||||
end
|
||||
|
||||
t:fuzz("open", function(b: buffer)
|
||||
local v = F.video.open(b)
|
||||
if v then
|
||||
for _ = 1, 3 do
|
||||
v:nextFrame()
|
||||
end
|
||||
end
|
||||
return v
|
||||
end, { Base64.decode(Fx.ts) :: buffer, Base64.decode(Fx.mpg) :: buffer }, { mutations = 30, garbage = 5 })
|
||||
|
||||
t:done()
|
||||
Reference in new issue
Block a user