ws-video: video/mpegts (containers/MpegTs absorbed from mpegts-luau 6e16197, its unit queue fixed for LuaJIT; M2TS, resync before the first packet, private stream types by PES id), video/mpegps (containers/MpegPs: MPEG-1 / MPEG-2 packs, PSM, private stream 1; pictures cut from the joined ES, PTS from PES / GOP temporal references; raw .m1v), containers/MpegEs; tests vs ffprobe / ffmpeg
This commit is contained in:
1 parent
a2763bee35
commit
aa4963dc27
11 files changed
+1852
-15
No files matched your search
+18
-15
@@ -41,45 +41,48 @@ function C.snr(ours: buffer, ref: string, n: number): number
|
||||
return 10 * math.log10(sig / err)
|
||||
end
|
||||
|
||||
-- packets(t, dmx, c, opts): every packet (file order) against ffprobe's: track, time, size, keyframe, CRC
|
||||
-- packets(t, dmx, c, label, opts?): every track's packets against ffprobe's (in order): size, CRC, time, keyframe.
|
||||
-- opts.skipStream(ffprobePacket, track) -> true skips a stream (ffmpeg's parsers re-split some, e.g. MPEG audio in TS)
|
||||
function C.packets(t: any, dmx: any, c: any, label: string, opts: any?)
|
||||
local o = opts or {}
|
||||
local trackOf = {} -- ffprobe stream index -> our track
|
||||
for i, s in c.streams do
|
||||
trackOf[s.index] = o.trackFor and o.trackFor(dmx, s) or dmx.tracks[i]
|
||||
end
|
||||
dmx:rewind()
|
||||
local k, bad = 0, 0
|
||||
local k: { [number]: number } = {}
|
||||
local total, bad = 0, 0
|
||||
local first = nil
|
||||
for _, want in c.packets do
|
||||
local tr = trackOf[want.stream]
|
||||
if not (o.skipStream and o.skipStream(want, tr)) then
|
||||
local p = dmx:read()
|
||||
k += 1
|
||||
if not p then
|
||||
t:check(false, label .. ": packet " .. k .. " missing")
|
||||
return
|
||||
end
|
||||
local ok = tr ~= nil and p.track == tr.id and buffer.len(p.data) == want.size and Crc32.of(p.data) == want.crc
|
||||
total += 1
|
||||
local id = if tr then tr.id else -1
|
||||
k[id] = (k[id] or 0) + 1
|
||||
local p = if tr then dmx:get(id, k[id]) else nil
|
||||
local ok = p ~= nil and buffer.len(p.data) == want.size and Crc32.of(p.data) == want.crc
|
||||
local s = c.streams[want.stream + 1]
|
||||
if ok and want.pts and s and not o.noPts then
|
||||
if ok and p and want.pts and s and not o.noPts then
|
||||
local ours = p.pts / tr.timescale - (tr.codecDelay or 0) -- ffmpeg shifts by Matroska's CodecDelay
|
||||
local theirs = want.pts * s.tbn / s.tbd
|
||||
ok = math.abs(ours - theirs) < 0.0015
|
||||
end
|
||||
if ok and not o.noKey and tr and tr.kind == "video" then
|
||||
if ok and p and not o.noKey and tr and tr.kind == "video" then
|
||||
ok = p.keyframe == want.key
|
||||
end
|
||||
if not ok then
|
||||
bad += 1
|
||||
if not first then
|
||||
first = string.format("packet %d: track %s/%s size %d/%d pts %s/%s key %s/%s crc %s", k, tostring(p.track), tostring(tr and tr.id), buffer.len(p.data), want.size, tostring(p.pts), tostring(want.pts), tostring(p.keyframe), tostring(want.key), tostring(Crc32.of(p.data) == want.crc))
|
||||
first = string.format("track %s packet %d: size %s/%d pts %s/%s key %s/%s crc %s", tostring(id), k[id], tostring(p and buffer.len(p.data)), want.size, tostring(p and p.pts), tostring(want.pts), tostring(p and p.keyframe), tostring(want.key), tostring(p and Crc32.of(p.data) == want.crc))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
t:check(bad == 0, label .. ": " .. k .. " packets equal ffprobe's (" .. bad .. " differ" .. (if first then "; first: " .. first else "") .. ")")
|
||||
t:check(dmx:read() == nil, label .. ": no extra packets")
|
||||
local extra = 0
|
||||
for id, n in k do
|
||||
extra += math.max(0, dmx:count(id) - n)
|
||||
end
|
||||
t:check(bad == 0, label .. ": " .. total .. " packets equal ffprobe's (" .. bad .. " differ" .. (if first then "; first: " .. first else "") .. ")")
|
||||
t:check(extra == 0, label .. ": no extra packets (" .. extra .. ")")
|
||||
end
|
||||
|
||||
-- frames(t, v, c, label): every decoded frame against ffmpeg's (CRC for EXACT codecs, else PSNR of the raw ones)
|
||||
|
||||
Reference in new issue
Block a user