ws-h264: F.video.open end to end on MP4 / MKV / TS / AVI / raw H.264 (bit-exact vs ffmpeg), display-order pts from the sorted packet times; JVT conformance test (48 streams bit-exact vs JM yuv, 4 refused); video/mp4 writer: a video edit list plays every frame (the B-frame delay no longer cut 2 frames off the end); tests tune LuaJIT through host

This commit is contained in:
4DBug committed 2026-10-31 10:53:34 -05:00
1 parent 84101d919e
commit 7271e6e3fa
9 files changed
+266 -3

No files matched your search

+14 -1
View File
@@ -199,7 +199,7 @@ end
-- ------------------------------------------------------------------------------------------------ video layer
-- newVideoDecoder(track, opts?) -> a Types.VideoCodecDecoder (the codecs/Video registry entry for "h264"):
-- track.config = avcC (MP4 / Matroska; packets length-prefixed) or nil (Annex B packets: MPEG-TS, AVI, raw .h264).
-- Pictures come out in display order with the pts of the packet that carried them; a track with
-- Pictures come out in display order with the packet timestamps sorted (display order); a track with
-- `ptsInOutputOrder` (raw Annex B, no timestamps) numbers them in output order instead.
function H264.newVideoDecoder(track: Types.Track, opts: any?): (Types.VideoCodecDecoder?, Err.Err?)
local o: Options = { maxPixels = opts and opts.maxPixels, deblock = opts and opts.deblock, lowDelay = opts and opts.lowDelay }
@@ -218,6 +218,7 @@ function H264.newVideoDecoder(track: Types.Track, opts: any?): (Types.VideoCodec
return nil, err
end
local queue: { any } = {}
local pool: { number } = {}
local outIndex: number? = if track.ptsInOutputOrder then 0 else nil
local self: any = {}
local function push(frames: { Frame })
@@ -226,6 +227,10 @@ function H264.newVideoDecoder(track: Types.Track, opts: any?): (Types.VideoCodec
if track.ptsInOutputOrder then
pts = outIndex or 0
outIndex = pts + 1
elseif #pool > 0 then
-- pictures leave in display order: they take the packet timestamps in increasing order (right for
-- MP4 / MKV / TS pts, and for AVI whose packets only carry decode-order times)
pts = table.remove(pool, 1)
end
table.insert(queue, { f.image, pts, f.keyframe })
end
@@ -237,6 +242,13 @@ function H264.newVideoDecoder(track: Types.Track, opts: any?): (Types.VideoCodec
if outIndex == nil and track.ptsInOutputOrder then
outIndex = packet.pts
end
if packet.pts ~= nil and not track.ptsInOutputOrder then
local i = #pool
while i > 0 and pool[i] > packet.pts do
i -= 1
end
table.insert(pool, i + 1, packet.pts)
end
local frames, e = (dec :: H264Decoder):decode(packet.data, packet.pts)
if not frames then
return e
@@ -259,6 +271,7 @@ function H264.newVideoDecoder(track: Types.Track, opts: any?): (Types.VideoCodec
function self.reset(_: any)
dec = make()
table.clear(queue)
table.clear(pool)
if track.ptsInOutputOrder then
outIndex = nil
end
+10
View File
@@ -264,10 +264,20 @@ function Mp4.encode(value: any, opts: EncodeOptions?): (buffer?, Err.Err?)
if s.kind == "audio" and s.track and s.track.codecDelay and s.copied then
skip = math.floor(s.track.codecDelay * scale + 0.5)
end
-- video: the skipped decode delay is a composition shift, every frame still plays (ffmpeg drops the frames an
-- edit cuts); audio: the codec delay samples are not played
local playDuration = nil
if s.kind == "video" and skip > 0 then
playDuration = 0
for _, d in durations do
playDuration += d
end
end
local t: any = {
kind = s.kind,
timescale = scale,
skip = if skip > 0 then skip else nil,
playDuration = playDuration,
samples = samples,
durations = durations,
cts = if anyCts then cts else nil,