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)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
4DBugandClaude Opus 5.5 committed 2026-10-31 14:13:08 -05:00
1 parent 51630729f6
commit a7d44451c4
7 files changed
+66 -9

No files matched your search

+5 -1
View File
@@ -95,6 +95,7 @@ assert(r and g and b)
| `width`, `height`, `frameRate` | video tracks |
| `sampleRate`, `channels`, `bitsPerSample` | audio tracks |
| `config` | codec configuration bytes (avcC, CodecPrivate, Vorbis headers, ...) |
| `codecDelay`, `playDuration` | audio: seconds of encoder priming to drop, and seconds to play after it (an MP4 edit list; Matroska `CodecDelay`) |
| `duration`, `language`, `name`, `default` | when the container has them |
A Packet is `{ track, pts, dts?, duration?, keyframe, data }`: `data` is a buffer of the compressed bytes.
@@ -142,7 +143,8 @@ v:reset()
assert(v:nextFrame().pts == 0)
```
The audio track is an ordinary audio Decoder: read it, or turn it into an Audio.
The audio track is an ordinary audio Decoder: read it, or turn it into an Audio. Encoder priming and an MP4 edit
list's end padding are cut as ffmpeg cuts them, so a 1 s AAC track decodes to 1 s of samples.
```luau
local v = assert(F.video.open(webmBytes))
@@ -151,6 +153,8 @@ assert(a.sampleRate == 44100 and a.channels == 1)
local sound = assert(F.ops.audio.toAudio(a))
local ogg = assert(F.save(sound, nil, { format = "vorbis" })) -- the soundtrack on its own
assert(F.detect(ogg) == "vorbis")
local aac = assert(F.ops.audio.toAudio(assert(F.video.open(mp4Bytes)).audio))
assert(aac.frames == 44100) -- 1 s: the AAC priming and padding cut by the edit list
```
Animated images open as videos (`codec = "frames"`, rgba8 frames, no demuxer). `F.video.fromImage(img)` does the same