merge ws/video2-legacy (FLIC, Cinepak, MSV1, QT RLE / SMC, Smacker; video/fli, video/smk)

This commit is contained in:
4DBug committed 2026-10-31 15:23:13 -05:00
commit 9694c652ec
32 files changed
+4786 -5

No files matched your search

+4 -1
View File
@@ -28,12 +28,14 @@ is tested under both runtimes (luau `--codegen -O2` and LuaJIT through the build
| audio | vorbis | .ogg .oga | yes | yes | streaming: true, seek: true, lossy: true, channels: 255 | `tests/audio/vorbis.luau` |
| audio | wav | .wav .wave .rf64 .bw64 | yes | yes | streaming: true, depths: 8, 16, 24, 32, float: true, rf64: true | `tests/audio/wav.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 | 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", "rawvideo", audio: true, subtitles: true | `tests/video/mkv.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` |
| video | mpegps | .mpg .mpeg .vob .m1v .mpv .dat | yes | - | streaming: true, video: "mpeg1", "mpeg2", audio: true | `tests/video/mpegps.luau` |
| video | mpegts | .ts .m2ts .mts .tsv | yes | - | streaming: true, video: "mpeg1", "mpeg2", "h264", audio: true | `tests/video/mpegts.luau` |
| video | ogv | .ogv .ogg | yes | yes | streaming: true, remux: true, video: "theora", audio: true | `tests/video/ogv.luau` |
| video | smk | .smk | yes | - | streaming: true, video: "smackvid", audio: "smackaudio", "pcm_u8", "pcm_s16le" | `tests/video/smk.luau` |
| video | y4m | .y4m | yes | yes | streaming: true, video: "rawvideo", depths: 8, 10, 12, 16 | `tests/video/y4m.luau` |
| model | 3mf | .3mf | yes | yes | materials: true, vertexColors: true, textures: true, units: true | `tests/model/3mf.luau` |
| model | dae | .dae .zae | yes | yes | materials: true, polygons: true, skins: true, morphTargets: true, animation: true, cameras: true, lights: true, zae: true | `tests/model/dae.luau` |
@@ -135,6 +137,7 @@ Codecs (layer 3, shared by formats; not loadable on their own), by domain:
- **video**
- codecs/video/Dsp: the 8x8 IDCT (bit-exact with ffmpeg -idct int) and half-pel motion compensation of MPEG codecs.
- 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
- codecs/video/Mpeg2: an MPEG-1 / MPEG-2 video decoder (ISO/IEC 11172-2, ISO/IEC 13818-2 Main profile).
- codecs/video/Theora: a Theora video decoder (the Theora I specification, Xiph.Org), for Ogg (video/ogv) and Matroska
+71
View File
@@ -366,6 +366,77 @@ editable:WritePixelsBuffer(Vector2.zero, editable.Size, v:toRGBA(frame).pixels)
See [FORMATS.md](../FORMATS.md). Subtitle tracks of Matroska files are read as cues by `F.format("mkv").subtitles`.
<!-- ws-video2-legacy: formats table addition -->
| fli / flc / flx | yes | - | FLIC (8-bit palettised, 15 / 16 / 24-bit) |
| smk | yes | - | Smacker video (SMK2 / SMK4) + Smacker audio / PCM |
AVI, MOV / MP4 and MKV (V_MS/VFW/FOURCC, V_QUICKTIME) also decode the legacy codecs: Cinepak, Microsoft Video 1,
QuickTime Animation (RLE) and QuickTime Graphics (SMC). See [Legacy video](#legacy-video).
<!-- ws-video2-legacy: section -->
## Legacy video
The 1990s formats and codecs decode to **rgba8** frames (they are palettised or RGB, not YUV), each frame painted
over the previous one, as the codecs define. Decoding is bit-exact with ffmpeg's.
| Codec id | Name | Containers | Depths |
|---|---|---|---|
| `flic` | Autodesk FLI / FLC | fli | 8-bit palettised, 15 / 16 / 24-bit |
| `smackvid` | Smacker video | smk | 8-bit palettised |
| `cinepak` | Cinepak (`cvid`) | avi, mov, mkv | 24-bit, grey, 8-bit palettised |
| `msvideo1` | Microsoft Video 1 (`CRAM`, `MSVC`, `WHAM`) | avi, mov, mkv | 16-bit (5-5-5), 8-bit palettised |
| `qtrle` | QuickTime Animation (`rle `) | mov, mkv | 1, 2, 4, 8 (palettised or grey), 16, 24, 32 (alpha) |
| `smc` | QuickTime Graphics (`smc `) | mov, mkv | 8-bit palettised |
Palettes come from the container: `track.palette` (256 entries, 4 bytes each: R, G, B, A) holds the AVI
BITMAPINFO palette or the QuickTime colour table (or the Macintosh default table it refers to); FLIC and Smacker
frames carry their own palette changes.
```luau
local v = assert(F.video.open(cinepakBytes)) -- Cinepak in a QuickTime movie
assert(v.format == "mov" and v.codec == "cinepak")
local frames = 0
while true do
local f = v:nextFrame()
if not f then break end
assert(f.image.format == "rgba8" and f.image.width == 64)
frames += 1
end
assert(frames == v.frames)
```
FLIC files (`.fli` at 70 Hz ticks, `.flc` / `.flx` in milliseconds) open as videos; the ring frame (an extra frame
leading back to the first, for looping) is not shown unless you ask for it.
```luau
local v = assert(F.video.open(flcBytes))
print(v.format, v.codec, v.width, v.height, v.frameRate) -- fli flic 64 48 10
assert(v.track.bitsPerPixel == 8 and v.frames == 10)
local f = assert(v:nextFrame())
local r, g, b, a = F.ops.image.getPixel(f.image, 0, 0) -- palette colours, opaque
assert(r and g and b and a == 255)
local all = assert(F.format("fli").open(F.Bytes.reader(flcBytes), { ringFrame = true }))
assert(all.codec == "flic")
```
Smacker files carry up to seven audio tracks. The format decodes Smacker's packed audio (and raw PCM tracks) itself:
`v.audio` is the first track, `F.format("smk").openAudio(demuxer, track)` opens any of them.
```luau
local v = assert(F.video.open(smkBytes))
assert(v.format == "smk" and v.codec == "smackvid")
local a = assert(v.audio, tostring(v.audioError)) -- packed 16-bit stereo, 22050 Hz
assert(a.sampleRate == 22050 and a.channels == 2)
local Smk = F.format("smk")
for _, t in v.demuxer.tracks do
if t.kind == "audio" then
local dec = assert(Smk.openAudio(v.demuxer, t)) -- smackaudio, pcm_u8 or pcm_s16le
local pcm, n = dec:read(1000)
assert(n == 1000 and buffer.len(pcm) == n * dec.channels * 4)
end
end
```
## Gotchas
- Pure-Luau decoding is CPU-bound: H.264 and VP8 are practical at low resolutions. Measure with `tools/bench.luau`
+1
View File
@@ -30,6 +30,7 @@ F.convert(gif, "avi") -- animated images become videos (un
| `codecs/image/Vp8`, `Jpeg`, `Mpeg1` | the decoders (and the JPEG encoder) |
| `codecs/video/Mpeg2` (`Mpeg1` is the same module), `H264` | MPEG-1 / MPEG-2 and H.264 video decoders |
| `codecs/video/Dsp` | 8x8 IDCT (bit-exact with `ffmpeg -idct int`) and half-pel motion compensation for the MPEG-style codecs |
| `codecs/video/Legacy` | FLIC, Smacker, Cinepak, Microsoft Video 1, QuickTime RLE / SMC: rgba8, palettes from `track.palette` |
| `video/<fmt>` | the formats: demux into `containers/Demux`, `open` = `Video.open(demuxer, opts)`, `encode` via Source |
Audio tracks reach the audio formats through the api hook `opts.openAudio(demuxer, track)` (a format never requires