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:
4DBug committed 2026-11-01 01:16:04 -05:00
1 parent 05eedbc8cf
commit 2956576d7f
12 files changed
+252 -3

No files matched your search

+46 -1
View File
@@ -1,7 +1,7 @@
-- video/mp4 tests: MP4 / MOV files from ffmpeg (MJPEG + AAC / PCM / FLAC / MP2, H.264 with B-frames and edit lists +
-- AAC, fragmented MP4, MPEG-1 + Opus): tracks and every packet against ffprobe (pts moved by the edit lists, as ffmpeg),
-- frames against ffmpeg (PSNR), audio through the api hook (AAC priming dropped), seeking, our MP4 / MOV writer read
-- back, fuzz. Fixtures: tools/fixtures/mp4.py.
-- back, the H.264 yield hook and maxSide, fuzz. Fixtures: tools/fixtures/mp4.py.
local T = require("@tests/T")
local C = require("@tests/video/_common")
local F = require("@formats")
@@ -76,6 +76,51 @@ for _, job in { { "mjpeg_aac.mp4", "mp4" }, { "mjpeg_pcm.mov", "mov" }, { "h264_
end
end
-- H.264 with the cooperative yield hook (decoding inside a coroutine that yields at every hook call: the same pictures)
-- and maxSide (frames shrunk to the longer side, aspect kept)
do
local Crc32 = require("@formats/core/Crc32")
local data = byName["h264_aac.mp4"].data
local function crcs(opts: any, inCoroutine: boolean): ({ number }, number, number, number)
local v = assert(F.video.open(data, opts))
local list, calls, w, h = {}, 0, 0, 0
local function body()
while true do
local f = v:nextFrame()
if not f then
break
end
w, h = f.image.width, f.image.height
table.insert(list, Crc32.of(f.image.pixels))
end
end
if inCoroutine then
local co = coroutine.create(body)
while coroutine.status(co) ~= "dead" do
local ok, err = coroutine.resume(co)
t:check(ok, "yield: resume " .. tostring(err))
calls += 1
end
else
body()
end
return list, calls, w, h
end
local plain, _, w0, h0 = crcs({ audio = false }, false)
local hooked, resumes = crcs({ audio = false, yield = function()
coroutine.yield()
end }, true)
t:check(#plain > 0, "h264: frames")
t:check(resumes > #plain, "h264 yield: the hook ran inside pictures (" .. resumes .. " resumes)")
local same = #plain == #hooked
for i, c in plain do
same = same and hooked[i] == c
end
t:check(same, "h264 yield: the same pictures as without the hook")
local _, _, w1, h1 = crcs({ audio = false, maxSide = 32 }, false)
t:check(math.max(w1, h1) == 32 and math.abs(w1 / h1 - w0 / h0) < 0.1, ("maxSide: %dx%d -> %dx%d"):format(w0, h0, w1, h1))
end
local samples = {}
for _, n in { "mjpeg_aac.mp4", "fragmented.mp4", "h264_aac.mp4" } do
table.insert(samples, string.sub(byName[n].data, 1, 30000))