Files

63 lines
2.1 KiB
Luau

-- video/mpegts tests: transport streams from ffmpeg against ffprobe (video packets) and ffmpeg (frames, audio).
-- Fixtures: tools/fixtures/mpegts.py.
local T = require("@tests/T")
local C = require("@tests/video/_common")
local Ts = require("@rosetta/video/mpegts")
local Bytes = require("@rosetta/core/Bytes")
local Fx = require("@tests/gen/mpegts_cases")
local t = T.suite("mpegts")
t:eq(Ts.name, "mpegts", "name")
local byName = {}
for _, c in Fx do
byName[c.name] = c
end
local function audioStream(want: any, tr: any): boolean
return tr == nil or tr.kind ~= "video" -- ffmpeg's parser re-splits PES audio into frames
end
for _, c in Fx do
local label = c.name
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(Ts.sniff(Bytes.reader(buffer.fromstring(c.data))) > 0 or label == "garbage.ts", label .. ": sniff")
t:check(v ~= nil, label .. ": open " .. tostring(err))
if v then
local dmx = v.demuxer
t:eq(#dmx.tracks, #c.streams, label .. ": track count")
for i, s in c.streams do
local tr = dmx.tracks[i]
t:check(tr ~= nil and tr.kind == s.kind, label .. ": track " .. i .. " kind")
if tr and s.width and tr.width then -- (H.264 sizes come from its SPS, read by the codec)
t:check(tr.width == s.width and tr.height == s.height, label .. ": track " .. i .. " size")
end
end
if c.packets then
C.packets(t, dmx, c, label, { skipStream = audioStream })
end
C.frames(t, v, c, label, 36)
if dmx:track("audio") then
C.audio(t, v, c, label, false, 30)
end
C.seek(t, v, c, label, 0.5)
end
end
end
do
local v = C.open(byName["mpeg1_mp2.ts"].data)
t:eq(v.codec, "mpeg1", "stream type 0x02 without a sequence extension is MPEG-1")
t:eq(v.demuxer.tracks[2].codec, "mp2", "MPEG audio layer II")
t:eq(C.open(byName["h264_aac.ts"].data).codec, "h264", "H.264 track")
end
local samples = {}
for _, n in { "mpeg1_mp2.ts", "bframes.ts", "h264_aac.ts" } do
table.insert(samples, string.sub(byName[n].data, 1, 188 * 120))
end
t:fuzz("open", C.fuzzOpen(Ts), samples, { mutations = 6, garbage = 100 })
t:done()