codecs: H.264 / Yuv / video registry work, docs/API + guide/video, yuv + mp4 tests (uncommitted work found in the checkout, owner unknown; tests pass on both runtimes)
This commit is contained in:
1 parent
05eedbc8cf
commit
2956576d7f
12 files changed
+252
-3
No files matched your search
@@ -383,6 +383,35 @@ local editable = assert(F.host.toEditableImage(v:toRGBA(first)))
|
||||
editable:WritePixelsBuffer(Vector2.zero, editable.Size, v:toRGBA(frame).pixels)
|
||||
```
|
||||
|
||||
### Slow codecs: a yield hook and smaller frames
|
||||
|
||||
One H.264 picture can take longer than a game frame. `F.video.open(src, { yield = fn })` hands the codec a cooperative
|
||||
yield point: H.264 calls `fn` (through `pcall`) every 16 macroblocks and every macroblock row of the loop filter, so
|
||||
decoding inside a coroutine whose `fn` calls `coroutine.yield()` once a time budget is spent spreads a picture over
|
||||
several frames (a game's worker Actor, or the main thread). While a decode is suspended, run no other H.264 decode in
|
||||
the same Luau VM. `maxSide = n` shrinks the yuv420p frames (bilinear, aspect kept) so the longer side is at most `n`
|
||||
pixels, before any rgba conversion; `v.width` / `v.height` stay the source size.
|
||||
|
||||
```luau
|
||||
local deadline = 0
|
||||
local v = assert(F.video.open(mp4Bytes, { audio = false, maxSide = 32, yield = function()
|
||||
if os.clock() >= deadline then
|
||||
coroutine.yield()
|
||||
end
|
||||
end }))
|
||||
local frames = 0
|
||||
local job = coroutine.create(function()
|
||||
while v:nextFrame() do
|
||||
frames += 1
|
||||
end
|
||||
end)
|
||||
while coroutine.status(job) ~= "dead" do -- one step per game frame
|
||||
deadline = os.clock() + 0.002
|
||||
assert(coroutine.resume(job))
|
||||
end
|
||||
assert(frames > 0)
|
||||
```
|
||||
|
||||
## Formats
|
||||
|
||||
| Format | Read | Write | Video codecs (decode) |
|
||||
|
||||
Reference in new issue
Block a user