ws-video: video/mkv tests (ffprobe packets, ffmpeg audio, lacing / zlib / unknown clusters / subtitles, WebM remux), zlib content compression, codec-delay trimming of non-Opus audio (AudioWrap.trim), video/y4m, containers/Avi + video/avi (WIP tests)

This commit is contained in:
4DBug committed 2026-10-31 09:41:22 -05:00
1 parent 967703a4d4
commit 3ae152ac81
14 files changed
+1862 -20

No files matched your search

+28 -5
View File
@@ -9,6 +9,7 @@ local Types = require("@formats/Types")
local Ebml = require("@formats/containers/Ebml")
local Demux = require("@formats/containers/Demux")
local Video = require("@formats/codecs/Video")
local Deflate = require("@formats/codecs/Deflate")
local Parse = {}
@@ -56,6 +57,7 @@ local ID = {
ContentEncodings = 0x6D80,
ContentEncoding = 0x6240,
ContentEncodingType = 0x5033,
ContentEncodingScope = 0x5032,
ContentCompression = 0x5034,
ContentCompAlgo = 0x4254,
ContentCompSettings = 0x4255,
@@ -182,13 +184,17 @@ local function parseAudio(buf: buffer, off: number, len: number, t: any)
end
end
-- ContentEncodings: header stripping (algo 3) is supported; zlib / bzip / lzo compression and encryption are not
-- ContentEncodings: header stripping (algo 3) and zlib (algo 0) are supported; bzip / lzo compression and encryption
-- are not
local function parseEncodings(buf: buffer, off: number, len: number, t: any): string?
for id, o, n in Ebml.children(buf, off, off + len) do
if id == ID.ContentEncoding then
local etype = 0
local scope = 1
for id2, o2, n2 in Ebml.children(buf, o, o + n) do
if id2 == ID.ContentEncodingType then
if id2 == ID.ContentEncodingScope then
scope = Ebml.uint(buf, o2, n2)
elseif id2 == ID.ContentEncodingType then
etype = Ebml.uint(buf, o2, n2)
elseif id2 == ID.ContentCompression then
local algo, settings = 0, nil
@@ -201,6 +207,8 @@ local function parseEncodings(buf: buffer, off: number, len: number, t: any): st
end
if algo == 3 then
t.strip = settings
elseif algo == 0 then
t.zlib = scope -- 1: frames, 2: CodecPrivate
else
return "content compression algorithm " .. algo
end
@@ -259,6 +267,14 @@ local function parseTracks(buf: buffer, off: number, len: number, scaleNs: numbe
problem = parseEncodings(buf, o2, n2, t)
end
end
if t.zlib and bit32.band(t.zlib, 2) ~= 0 and t.config then
local c = Deflate.zlib(t.config)
if c then
t.config = c
else
problem = "bad zlib-compressed CodecPrivate"
end
end
t.kind = if ttype == 1 then "video" elseif ttype == 2 then "audio" elseif ttype == 17 then "subtitle" else "data"
t.codecTag = codecId
t.codec = codecFor(codecId, t.kind, t.bitsPerSample)
@@ -465,14 +481,21 @@ local function block(ctx: Ctx, off: number, len: number, clusterTime: number, si
return
end
local d = if #sizes == 1 then durTicks else (if stepTicks > 0 then stepTicks else nil)
local kf = key and (k == 1 or t.kind ~= "video")
local strip = t.strip
if strip then
local z = (t :: any).zlib
if z and bit32.band(z, 1) ~= 0 then
local out = Deflate.zlib(buf, p, s)
if out then
dmx:addData(tn, pts + (k - 1) * stepTicks, nil, d, kf, out)
end
elseif strip then
local nb = buffer.create(buffer.len(strip) + s)
buffer.copy(nb, 0, strip)
buffer.copy(nb, buffer.len(strip), buf, p, s)
dmx:addData(tn, pts + (k - 1) * stepTicks, nil, d, key and k == 1, nb)
dmx:addData(tn, pts + (k - 1) * stepTicks, nil, d, kf, nb)
else
dmx:add(tn, pts + (k - 1) * stepTicks, nil, d, key and (k == 1 or t.kind ~= "video"), p, s)
dmx:add(tn, pts + (k - 1) * stepTicks, nil, d, kf, p, s)
end
if discardNs and k == #sizes then
dmx:setExtra("discardPadding", discardNs / 1e9)
+3 -3
View File
@@ -2,14 +2,14 @@
-- video/mkv: Matroska and WebM (the Matroska specification / RFC 9559, the WebM container guidelines). New in
-- formats-luau, on containers/Ebml.
-- Read: open() demuxes the whole file into a packet index (SimpleBlock / BlockGroup, Xiph / EBML / fixed lacing,
-- header-stripping compression, unknown-size clusters, Cues and Tags in meta) and returns a VideoDecoder: video
-- header-stripping and zlib compression, unknown-size clusters, Cues and Tags in meta) and returns a VideoDecoder: video
-- through the codecs/Video registry (VP8 with inter frames, MJPEG, MPEG-1, raw; H.264 when registered), audio
-- through the api's opts.openAudio hook (Opus, Vorbis, FLAC, MP3, PCM, AAC, ... reach the audio formats), text
-- subtitle tracks as cues (Mkv.subtitles). Mkv.demux(r) gives the Demuxer alone.
-- Write: WebM (opts.format = "webm" or a .webm destination: VP8 / VP9 / AV1 video and Opus / Vorbis audio, copied
-- from the source since VP8 is decode-only) and Matroska (any registered video codec copied, else MJPEG encoded from
-- the frames; audio copied, else PCM s16), with SeekHead, Cues and Duration.
-- Not supported: zlib / bzip2 / lzo content compression and encryption (the track's packets are left as stored,
-- Not supported: bzip2 / lzo content compression and encryption (the track's packets are left as stored,
-- track.unsupported says why), chapters / attachments (skipped), writing subtitles.
-- ------------------------------------------------------------------------------------------------ requires
@@ -27,7 +27,7 @@ local Mkv = {
category = "video",
extensions = { "mkv", "webm", "mka", "mk3d" },
mime = { "video/x-matroska", "video/webm", "audio/x-matroska", "audio/webm" },
deps = { "core/Err", "core/Bytes", "Types", "containers/Ebml", "containers/Demux", "codecs/Video", "codecs/Video/Source" },
deps = { "core/Err", "core/Bytes", "Types", "containers/Ebml", "containers/Demux", "codecs/Deflate", "codecs/Video", "codecs/Video/Source" },
caps = { decode = true, encode = true, streaming = true, remux = true, video = { "vp8", "mjpeg", "mpeg1", "rawvideo" }, audio = true, subtitles = true },
}