ws-apifix: MP4 AAC length matches ffmpeg: the edit list's length (Track.playDuration) cuts the end padding as well as the priming (codecDelay); a 1 s clip decodes to 44100 frames, not 45056. AudioWrap.trim(dec, skip, length?); the MP4 writer keeps the edit length of copied audio. Video tests compare the whole decoded audio length with ffmpeg (not yet for Matroska)

This commit is contained in:
4DBug committed 2026-10-31 14:13:08 -05:00
1 parent ac47545aa3
commit 6274eedd12
7 files changed
+66 -9

No files matched your search

+15
View File
@@ -152,6 +152,21 @@ function C.audio(t: any, v: any, c: any, label: string, exact: boolean?, minSnr:
end
local n = got * a.channels
t:check(n == want or n * 4 == c.pcmBytes, label .. ": " .. n .. " samples read of " .. want)
-- the whole stream: as long as ffmpeg's decode (priming and end padding trimmed the same way: MP4 edit lists).
-- Not yet for Matroska / WebM, where ffmpeg also cuts the end padding of the last packets (Vorbis, MP2: a few
-- hundred frames) and we do not.
if c.pcmBytes and v.format ~= "mkv" and v.format ~= "webm" then
local total = got
while true do
local _, k = a:read(4096)
if not k or k <= 0 then
break
end
total += k
end
t:eq(total * a.channels * 4, c.pcmBytes, label .. ": decoded length = ffmpeg's (" .. total .. " frames)")
a:seek(0)
end
n = math.min(n, want)
if exact then
local same = true
+10
View File
@@ -62,6 +62,16 @@ for _, job in { { "mjpeg_aac.mp4", "mp4" }, { "mjpeg_pcm.mov", "mov" }, { "h264_
end
end
t:check(same, "write " .. job[1] .. ": same packets and times")
-- copied AAC keeps its edit list: priming and end padding cut as in the source (ffmpeg's length)
local at = a:track("audio")
if at and at.codec == "aac" then
local bt = b:track("audio")
t:check(bt and bt.playDuration and math.abs(bt.playDuration - at.playDuration) < 1e-3 and math.abs((bt.codecDelay or 0) - (at.codecDelay or 0)) < 1e-6, "write " .. job[1] .. ": edit list kept")
if v2.audio and src.pcmBytes then
local all = assert(F.ops.audio.toAudio(v2.audio))
t:eq(all.frames * all.channels * 4, src.pcmBytes, "write " .. job[1] .. ": AAC length = ffmpeg's decode of the source")
end
end
end
end
end