ws-video2: docs/guide/video.md MPEG-2 section (tested snippet, tsBytes clip), formats table; docs/video.md layers
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
8216b80512
commit
f70fa346a2
3 files changed
+38
-8
No files matched your search
+29
-5
@@ -2,7 +2,7 @@
|
||||
|
||||
A video file opens as a **VideoDecoder**: frames come out one at a time, as Images, with their presentation time.
|
||||
Underneath sits a **Demuxer**: the container's tracks and their compressed packets. Video tracks decode through a
|
||||
codec registry (H.264, VP8, MPEG-1, Motion-JPEG, raw), and the first audio track opens as an audio
|
||||
codec registry (H.264, VP8, MPEG-1, MPEG-2, Motion-JPEG, raw), and the first audio track opens as an audio
|
||||
[Decoder](audio.md#decoder). Animated GIF, APNG and WebP open as videos too. [docs/video.md](../video.md) covers the
|
||||
internals and how to add a codec.
|
||||
|
||||
@@ -263,6 +263,30 @@ assert(C.register({
|
||||
assert(C.fromFourcc("SLID") == "solid" and C.canDecode("solid"))
|
||||
```
|
||||
|
||||
## MPEG-2 (DVD, broadcast TS)
|
||||
|
||||
MPEG-1 and MPEG-2 video decode through one decoder (`codecs/video/Mpeg2`; `codecs/video/Mpeg1` is the same module):
|
||||
Main profile, progressive and interlaced, frame and field pictures, 4:2:0 and 4:2:2. It reads `.mpg` / `.vob`
|
||||
program streams, transport streams (stream type 0x02, or a private type such as 0x80 carrying a video PES), raw
|
||||
`.m2v` elementary streams, and MPEG-2 tracks of MP4 / MOV, Matroska and AVI. The output equals `ffmpeg -idct int`
|
||||
sample for sample (the integer IDCT of the IJG; ffmpeg's default IDCT differs from it by at most a level or two).
|
||||
|
||||
```luau
|
||||
local v = assert(F.video.open(tsBytes)) -- MPEG-TS: interlaced MPEG-2 + MP2
|
||||
assert(v.format == "mpegts" and v.codec == "mpeg2")
|
||||
local f = assert(v:nextFrame())
|
||||
local src = f.image.meta.source
|
||||
assert(src.format == "mpeg2" and src.interlaced and src.topFieldFirst)
|
||||
assert(f.image.format == "yuv420p") -- both fields woven: the top field on the even lines
|
||||
local a = assert(v.audio, tostring(v.audioError)) -- the MP2 track through the audio hook
|
||||
assert(a.sampleRate == 44100)
|
||||
```
|
||||
|
||||
Interlaced frames come out woven, as they were coded: deinterlace them yourself if needed (`src.interlaced`,
|
||||
`src.topFieldFirst`). 4:2:2 streams (studio / XDCAM) are converted to 4:2:0 for the frame Image, averaging chroma
|
||||
lines of the same field. A 720x576 interlaced stream decodes at about 130 frames per second in Luau on one desktop
|
||||
core (`tools/bench.luau`): real time with room to spare on a PC, less so on phones.
|
||||
|
||||
## 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
|
||||
@@ -306,10 +330,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 |
|
||||
| mkv / webm | yes | yes | VP8, MJPEG, MPEG-1, raw (+ H.264) |
|
||||
| avi | yes | yes | MJPEG, MPEG-1, raw (+ H.264) |
|
||||
| mpegts, mpegps | yes | - | MPEG-1, H.264 |
|
||||
| mp4 / mov / m4v / 3gp | yes | yes | H.264, MJPEG, MPEG-1, MPEG-2 |
|
||||
| mkv / webm | yes | yes | VP8, MJPEG, MPEG-1, MPEG-2, raw (+ H.264) |
|
||||
| avi | yes | yes | MJPEG, MPEG-1, MPEG-2, raw (+ H.264) |
|
||||
| mpegts, mpegps | yes | - | MPEG-1, MPEG-2, H.264 |
|
||||
| y4m | yes | yes | raw |
|
||||
| h264 (Annex B) | yes | yes (copy) | H.264 |
|
||||
| gif, png (APNG), webp | as video | as video via the image writers | frames |
|
||||
|
||||
@@ -28,6 +28,8 @@ F.convert(gif, "avi") -- animated images become videos (un
|
||||
| `codecs/video/Video/Source` | what writers write: copied packets or frames encoded by a registry encoder, PCM from the audio |
|
||||
| `codecs/image/Yuv` | yuv420p <-> rgba8 (BT.601 / 709, limited / full range from `image.meta.yuv`), range remap |
|
||||
| `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 |
|
||||
| `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
|
||||
|
||||
Reference in new issue
Block a user