ws-video2-theora: video/ogv, Ogg video (Theora + Vorbis / Opus / FLAC)
Demuxes every logical stream of the first Ogg group into containers/Demux: Theora (frame times from granules, Xiph-laced headers as track.config, comment tags in meta.tags), Vorbis / Opus / FLAC audio (headers in track.config) for the api's openAudio hook; open = Video.open. Sniff claims only Ogg files with a Theora BOS page. encode remuxes Theora (+ Vorbis / Opus pages from AudioWrap, interleaved by time). codecs/video/Theora gains info / comment helpers.
This commit is contained in:
1 parent
8183f4d2d7
commit
4dcb005180
6 files changed
+667
-7
No files matched your search
@@ -23,6 +23,8 @@ local Decoder = require("@formats/codecs/video/Theora/Decoder")
|
||||
|
||||
local Theora = {}
|
||||
|
||||
export type Info = Header.Info
|
||||
|
||||
export type Options = {
|
||||
maxPixels: number?, -- larger coded frames are refused (default 4096 * 2304)
|
||||
}
|
||||
@@ -75,6 +77,24 @@ function Theora.splitConfig(c: buffer): { buffer }?
|
||||
return out
|
||||
end
|
||||
|
||||
-- info(idHeader) -> Header.Info (frame / picture size, frame rate, granule shift, pixel format, ...) | nil, Err
|
||||
function Theora.info(h: buffer): (Header.Info?, Err.Err?)
|
||||
local ok, info, err = pcall(Header.info, h, 0, buffer.len(h))
|
||||
if not ok or not info then
|
||||
return nil, Err.from(if ok then err else tostring(info))
|
||||
end
|
||||
return info, nil
|
||||
end
|
||||
|
||||
-- comment(commentHeader) -> vendor, { "KEY=value" }, tags (lower-case keys) | nil, nil, nil, Err
|
||||
function Theora.comment(h: buffer): (string?, { string }?, { [string]: string }?, Err.Err?)
|
||||
local ok, vendor, list, err = pcall(Header.comment, h, 0, buffer.len(h))
|
||||
if not ok or not vendor or not list then
|
||||
return nil, nil, nil, Err.from(if ok then err else tostring(vendor))
|
||||
end
|
||||
return vendor, list, (VorbisComment.tags(list)), nil
|
||||
end
|
||||
|
||||
-- granuleFrame(info, granulepos) -> the 0-based index of the frame a granule position ends on (-1 for none)
|
||||
function Theora.granuleFrame(info: Header.Info, g: number): number
|
||||
if g < 0 then
|
||||
@@ -124,24 +144,23 @@ function Theora.new(headers: { buffer } | buffer, opts: Options?): (TheoraDecode
|
||||
if not list or #list < 3 or type(list[1]) ~= "buffer" or type(list[2]) ~= "buffer" or type(list[3]) ~= "buffer" then
|
||||
return nil, Err.new(Err.CORRUPT, "missing Theora headers")
|
||||
end
|
||||
local ok, info, ierr = pcall(Header.info, list[1], 0, buffer.len(list[1]))
|
||||
if not ok or not info then
|
||||
return nil, Err.from(if ok then ierr else tostring(info))
|
||||
local info, ierr = Theora.info(list[1])
|
||||
if not info then
|
||||
return nil, ierr
|
||||
end
|
||||
local maxPixels = opts and opts.maxPixels or 4096 * 2304
|
||||
if info.frameWidth * info.frameHeight > maxPixels then
|
||||
return nil, Err.new(Err.LIMIT, "frame of " .. info.frameWidth .. "x" .. info.frameHeight .. " is over maxPixels")
|
||||
end
|
||||
local ok2, vendor, comments, cerr = pcall(Header.comment, list[2], 0, buffer.len(list[2]))
|
||||
if not ok2 or not vendor or not comments then
|
||||
return nil, Err.from(if ok2 then cerr else tostring(vendor))
|
||||
local vendor, comments, tags, cerr = Theora.comment(list[2])
|
||||
if not vendor or not comments or not tags then
|
||||
return nil, cerr
|
||||
end
|
||||
local ok3, setup, serr = pcall(Header.setup, list[3], 0, buffer.len(list[3]))
|
||||
if not ok3 or not setup then
|
||||
return nil, Err.from(if ok3 then serr else tostring(setup))
|
||||
end
|
||||
local st = Decoder.new(info, setup)
|
||||
local tags = VorbisComment.tags(comments)
|
||||
return setmetatable({
|
||||
info = info,
|
||||
vendor = vendor,
|
||||
|
||||
Reference in new issue
Block a user