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
+3
-1
@@ -44,7 +44,9 @@ VideoDecoder saved to an image format (`gif`, `apng`, `webp`) becomes an animate
|
||||
`F.subtitle`, `F.music`, `F.playlist` each have `load`, `open`, `save` and `formats`: the calls above restricted to
|
||||
one category. Extras:
|
||||
|
||||
- `F.video.open(src)` also opens animated images (GIF / APNG / WebP) as videos; `F.video.fromImage(img)`,
|
||||
- `F.video.open(src, opts?)`: `opts.maxSide` shrinks the frames (longer side at most n pixels), `opts.yield` is a
|
||||
cooperative yield point for slow codecs (H.264; see the video guide), `opts.audio = false` skips the audio track.
|
||||
It also opens animated images (GIF / APNG / WebP) as videos; `F.video.fromImage(img)`,
|
||||
`F.video.fromFrames(images, delays?)` (an image sequence: `F.save(F.video.fromFrames(list, 1 / 25), "out.avi")`),
|
||||
`F.video.codecs` (the codec registry `codecs/video/Video`).
|
||||
- `F.model.loadTextures(scene, opts?)`: decodes embedded / referenced textures into `texture.image`.
|
||||
|
||||
@@ -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