ws-apifix: videos save as animated images (F.save(video, gif | apng | webp), F.convert(avi, "gif"): frames / fps / maxFrames (300) / maxPixels (2^25)); VideoFrame.index restarts at the seek position; F.detect names WebM files "webm"

api: encoderFor finds image formats for a VideoDecoder, videoToImage() collects the frames; F.detect asks a
format's optional variant(r) for a more precise name (video/mkv: Mkv.variant, from Parse.docType).
codecs/video/Video: index after seek = round(pts * frameRate) + 1.
This commit is contained in:
4DBug committed 2026-10-31 14:00:36 -05:00
1 parent 10bd6b021f
commit d73b93c740
8 files changed
+207 -6

No files matched your search

+11 -1
View File
@@ -553,7 +553,9 @@ end
export type Options = { maxPackets: number? }
-- parse(buf, base, limit, opts) -> a Demux | nil, Err
function Parse.parse(buf: buffer, base: number, limit: number, opts: Options?): (any, Err.Err?)
-- docType(buf, base, limit) -> the EBML header's DocType ("matroska" when it has none), the header's size and data
-- offset | nil, Err
function Parse.docType(buf: buffer, base: number, limit: number): (string?, any, number?)
local id, size, data = Ebml.header(buf, base, limit)
if id ~= ID.EBML or not size or not data then
return nil, Err.new(Err.CORRUPT, "not an EBML file", base)
@@ -567,6 +569,14 @@ function Parse.parse(buf: buffer, base: number, limit: number, opts: Options?):
docType = Ebml.string(buf, o, n)
end
end
return docType, size, data
end
function Parse.parse(buf: buffer, base: number, limit: number, opts: Options?): (any, Err.Err?)
local docType, size, data = Parse.docType(buf, base, limit)
if not docType then
return nil, size
end
if docType ~= "matroska" and docType ~= "webm" then
return nil, Err.new(Err.UNSUPPORTED, "EBML document type " .. docType)
end
+9
View File
@@ -67,6 +67,15 @@ function Mkv.sniff(r: Bytes.Reader): number
return 0.5
end
-- variant(r) -> "webm" for a WebM file (DocType webm), else nil: the name F.detect reports (never throws)
function Mkv.variant(r: Bytes.Reader): string?
local ok, docType = pcall(Parse.docType, r.buf, r.pos, r.limit)
if ok and docType == "webm" then
return "webm"
end
return nil
end
-- ------------------------------------------------------------------------------------------------ encode
-- encode(video, opts?) -> buffer | nil, Err: a VideoDecoder (F.load / F.video.open of any video or animated image)
-- or a Demuxer