merge ws/video2-flv

This commit is contained in:
4DBug committed 2026-10-31 15:59:44 -05:00
commit a02ece071b
18 files changed
+3088 -1

No files matched your search

+2
View File
@@ -50,6 +50,7 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| audio | wavpack | .wv | yes | - | streaming: true, seek: true, lossless: true, hybrid: true, float: true, depths: 8, 12, 16, 20, 24, 32 | `tests/audio/wavpack.luau` |
| video | avi | .avi | yes | yes | streaming: true, video: "mjpeg", "mpeg1", "mpeg2", "rawvideo", audio: true, odml: true | `tests/video/avi.luau` |
| video | fli | .fli .flc .flx | yes | - | streaming: true, video: "flic", depths: 8, 15, 16, 24 | `tests/video/fli.luau` |
| video | flv | .flv | yes | yes | streaming: true, remux: true, video: "flv1", "h264", audio: true, metadata: true | `tests/video/flv.luau` |
| video | h264 | .h264 .264 .avc .jsv .26l .jvt | yes | yes | streaming: true, video: "h264", depths: 8 | `tests/video/h264.luau` |
| video | mkv | .mkv .webm .mka .mk3d | yes | yes | streaming: true, remux: true, video: "vp8", "mjpeg", "mpeg1", "mpeg2", "theora", "rawvideo", audio: true, subtitles: true | `tests/video/mkv.luau` |
| video | mp4 | .mp4 .m4v .mov .qt .3gp .3g2 .mj2 | yes | yes | streaming: true, remux: true, video: "mjpeg", "mpeg1", "mpeg2", "h264", audio: true, fragments: true | `tests/video/mp4.luau` |
@@ -214,6 +215,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- codecs/text/Xml: XML 1.0 parse (DOM and pull events) and serialize, the engine data/xml, SVG, DAE, 3MF, TMX, plist, ...
- **video**
- codecs/video/Dsp: the 8x8 IDCT (bit-exact with ffmpeg -idct int) and half-pel motion compensation of MPEG codecs.
- codecs/video/H263: an H.263 / H.263+ and Sorenson Spark (FLV1) video decoder, bit-exact with ffmpeg -idct int.
- codecs/video/H264: an H.264 / AVC (ITU-T H.264 | ISO/IEC 14496-10) video decoder in pure Luau. A codec (layer 1): the
- codecs/video/Legacy: FLI / FLC, Cinepak, Microsoft Video 1, QuickTime RLE / SMC and Smacker video decoders.
- codecs/video/Mpeg1: the MPEG-1 video decoder (ISO/IEC 11172-2), which is codecs/video/Mpeg2 (an MPEG-2 decoder
+33 -1
View File
@@ -186,6 +186,7 @@ Images and animated images save as videos too.
| ogv | Theora copied (the source must be Theora: ogv or mkv) | Vorbis / Opus copied |
| mkv | any codec copied, else MJPEG | copied, else PCM s16 |
| mp4, mov | H.264 / HEVC / AV1 / MJPEG / MPEG-4 copied, else MJPEG | AAC / ALAC / Opus / FLAC / MP3 copied; PCM in MOV only |
| flv | H.264 (with its avcC) / Sorenson Spark / VP6 / screen video copied; nothing else (no FLV encoder) | AAC / MP3 / PCM / G.711 copied, else PCM s16 at 5512 / 11025 / 22050 / 44100 Hz |
| avi | MJPEG copied, else MJPEG encoded (`quality`) | PCM s16 |
| y4m | raw yuv420p | none |
| h264 | an H.264 track copied as an Annex B stream | none |
@@ -312,6 +313,36 @@ local mkv = assert(F.save(v, nil, { format = "mkv" })) -- Theora + Vorbis copi
assert(F.video.open(mkv).codec == "theora")
```
## FLV and H.263
FLV (Flash Video) opens like any other container. Its onMetaData script tag is `v.meta.metadata` (duration, width,
height, framerate, codec ids, encoder, ...). Sorenson Spark (FLV1) and H.263 (in 3GP / MP4 `s263`, AVI `H263`)
decode bit-exactly as ffmpeg decodes them; H.264 tracks carry their avcC in `track.config` and their B-frame
composition times in the pts. VP6, screen video, Flash ADPCM, Nellymoser and Speex tracks are known (and remuxable)
but not decoded: `nextFrame` / `v.audioError` say UNSUPPORTED. Writing FLV copies H.264 + AAC / MP3 from MP4,
Matroska or FLV sources (FLV has no codec here that encodes).
```luau
local v = assert(F.video.open(flvBytes)) -- Sorenson Spark + MP3
assert(v.format == "flv" and v.codec == "flv1" and v.width == 64 and v.height == 48)
local md = v.meta.metadata -- onMetaData (AMF0)
assert(md.duration > 0 and md.framerate == 10 and md.videocodecid == 2)
local f = assert(v:nextFrame()) -- yuv420p (BT.601, limited range)
assert(f.keyframe and f.image.format == "yuv420p")
local sound = assert(F.ops.audio.toAudio(assert(v.audio, tostring(v.audioError))))
assert(sound.sampleRate == 44100)
local h = assert(F.video.open(h263Bytes)) -- H.263 (QCIF) + AAC in 3GP
assert(h.codec == "h263" and h.width == 176 and h:nextFrame() ~= nil)
local flv = assert(F.convert(mp4Bytes, "flv")) -- remux: H.264 + AAC copied, onMetaData written
local back = assert(F.video.open(flv))
assert(F.detect(flv) == "flv" and back.codec == "h264" and back.demuxer:track("audio").codec == "aac")
```
The H.263 decoder covers baseline H.263 (sub-QCIF .. 16CIF, GOB headers, unrestricted vectors) and the H.263+
picture header ffmpeg's `h263p` encoder writes (custom sizes, the rounding type, unrestricted vectors, slice
structure); advanced prediction, PB-frames, advanced intra coding, the deblocking filter and the other H.263+
options are UNSUPPORTED.
## Playing in a game loop
Decode only the frames that are due, and stop when this frame's time budget is used up; a slow frame then makes
@@ -355,9 +386,10 @@ editable:WritePixelsBuffer(Vector2.zero, editable.Size, v:toRGBA(frame).pixels)
| Format | Read | Write | Video codecs (decode) |
|---|---|---|---|
| mp4 / mov / m4v / 3gp | yes | yes | H.264, MJPEG, MPEG-1, MPEG-2 |
| mp4 / mov / m4v / 3gp | yes | yes | H.264, H.263, MJPEG, MPEG-1, MPEG-2 |
| mkv / webm | yes | yes | VP8, MJPEG, MPEG-1, MPEG-2, raw, Theora (+ H.264) |
| ogv (Ogg Theora) | yes | yes (Theora + Vorbis / Opus copied) | Theora |
| flv | yes | yes (copy) | Sorenson Spark, H.264 (VP6, screen video: known, not decoded) |
| avi | yes | yes | MJPEG, MPEG-1, MPEG-2, raw (+ H.264) |
| mpegts, mpegps | yes | - | MPEG-1, MPEG-2, H.264 |
| y4m | yes | yes | raw |