ws-video: merge ws/video-vp8 (final); F.open wraps images as videos only for category video (F.video.open); F.video.fromFrames for image sequences
This commit is contained in:
commit
5161fb3371
5 files changed
+92
-10
No files matched your search
@@ -146,6 +146,8 @@ export type State = {
|
||||
miMvC: { number },
|
||||
miSubR: { number }, -- 16 per macroblock
|
||||
miSubC: { number },
|
||||
miN: number, -- the size of the mode info arrays (allocated by the first inter frame)
|
||||
pred: buffer?, -- the inter predictions of a row
|
||||
}
|
||||
|
||||
function Decode.new(): State
|
||||
@@ -179,6 +181,8 @@ function Decode.new(): State
|
||||
miMvC = {},
|
||||
miSubR = {},
|
||||
miSubC = {},
|
||||
miN = 0,
|
||||
pred = nil,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -1269,10 +1273,7 @@ function Decode.decodeFrame(st: State, buf: buffer, off: number, len: number, ma
|
||||
if width ~= st.width or height ~= st.height then
|
||||
st.width, st.height, st.mbw, st.mbh = width, height, mbw, mbh
|
||||
st.last, st.golden, st.alt, st.pool = nil, nil, nil, {}
|
||||
local nmi = (mbw + 1) * (mbh + 1)
|
||||
st.miRef, st.miMode = table.create(nmi, 0), table.create(nmi, 0)
|
||||
st.miMvR, st.miMvC = table.create(nmi, 0), table.create(nmi, 0)
|
||||
st.miSubR, st.miSubC = table.create(nmi * 16, 0), table.create(nmi * 16, 0)
|
||||
st.miN, st.pred = 0, nil
|
||||
st.segMap = table.create(mbw * mbh, 0)
|
||||
end
|
||||
-- key frames reset the frame context, the segment and loop filter deltas
|
||||
@@ -1520,7 +1521,19 @@ function Decode.decodeFrame(st: State, buf: buffer, off: number, len: number, ma
|
||||
end
|
||||
local topY, topU, topV = bcreate(mbw * 16), bcreate(mbw * 8), bcreate(mbw * 8)
|
||||
local yuv = bcreate(YUV_SIZE)
|
||||
local pred = if key then yuv else bcreate(YUV_SIZE * mbw) -- the inter predictions of a row
|
||||
local pred = yuv
|
||||
if not key then
|
||||
local nmi = (mbw + 1) * (mbh + 1)
|
||||
if st.miN ~= nmi then
|
||||
-- zero top row and left column: never written, they read as intra macroblocks without motion
|
||||
st.miRef, st.miMode = table.create(nmi, 0), table.create(nmi, 0)
|
||||
st.miMvR, st.miMvC = table.create(nmi, 0), table.create(nmi, 0)
|
||||
st.miSubR, st.miSubC = table.create(nmi * 16, 0), table.create(nmi * 16, 0)
|
||||
st.miN = nmi
|
||||
st.pred = bcreate(YUV_SIZE * mbw)
|
||||
end
|
||||
pred = st.pred :: buffer
|
||||
end
|
||||
local coeffs = bcreate(mbw * 768)
|
||||
local dcb = bcreate(32)
|
||||
-- per macroblock column / row state
|
||||
@@ -1758,7 +1771,7 @@ function Decode.decodeFrame(st: State, buf: buffer, off: number, len: number, ma
|
||||
|
||||
-- reconstruct the row (libwebp ReconstructRow; inter macroblocks predict from the references)
|
||||
if not key then
|
||||
Predict.row(refs, mby, mbw, mbRef, mbPart, miMvR, miMvC, miSubR, miSubC, (mby + 1) * (mbw + 1) + 1, pred, YUV_SIZE, Y_OFF, U_OFF, V_OFF, bil, full)
|
||||
Predict.row(refs :: any, mby, mbw, mbRef, mbPart, miMvR, miMvC, miSubR, miSubC, (mby + 1) * (mbw + 1) + 1, pred, YUV_SIZE, Y_OFF, U_OFF, V_OFF, bil, full)
|
||||
end
|
||||
for j = 0, 15 do
|
||||
writeu8(yuv, Y_OFF + j * BPS - 1, 129)
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
-- sign bias, hidden (altref) frames, token partitions, segments, loop filter deltas, probability context save /
|
||||
-- restore. Not supported: the horizontal / vertical scale bits (ignored, as libwebp and ffmpeg do), error
|
||||
-- concealment (a damaged frame returns an Err).
|
||||
-- Speed (one Zen 5 core): 640x480 inter frames ~190 fps under luau --codegen, ~220 fps under LuaJIT with the trace
|
||||
-- limits the host module sets (maxtrace=8000; with LuaJIT's default 1000 traces the decoder thrashes: ~70 fps).
|
||||
--
|
||||
-- local Vp8 = require("@formats/codecs/Vp8")
|
||||
-- local frame, err = Vp8.decodeFrame(buf, off, len) -- one key frame: a yuv420p Types.Image
|
||||
|
||||
@@ -368,7 +368,7 @@ function F.open(src: any, opts: Options?): (any, Err.Err?)
|
||||
if not m then
|
||||
return nil, merr
|
||||
end
|
||||
if not m.open and entry.category == "image" and (o.category == nil or o.category == "video") then
|
||||
if not m.open and entry.category == "image" and o.category == "video" then
|
||||
local io = table.clone(o)
|
||||
io.category = "image"
|
||||
io.format = entry.name
|
||||
@@ -614,6 +614,11 @@ F.video.fromImage = function(img: any, opts: Options?): (any, Err.Err?)
|
||||
local src = type(img.meta) == "table" and img.meta.source
|
||||
return Video.fromFrames(frames, delays, { format = type(src) == "table" and src.format or "image", loops = img.loops, meta = img.meta })
|
||||
end
|
||||
-- F.video.fromFrames(images, delays?, opts?) -> a VideoDecoder over a list of same-size images (an image sequence:
|
||||
-- F.save(F.video.fromFrames(list, 1 / 25), "out.avi")); delays in seconds (a number = every frame, default 0.1)
|
||||
F.video.fromFrames = function(images: any, delays: any?, opts: Options?): (any, Err.Err?)
|
||||
return Video.fromFrames(images, delays, opts)
|
||||
end
|
||||
-- F.video.codecs: the video codec registry (codecs/Video: register / entry / fromFourcc / fromMatroska / decoder)
|
||||
F.video.codecs = Video
|
||||
|
||||
|
||||
Reference in new issue
Block a user