How Animated AVIF (avis) Tracks Schedule and Decode Inter-Coded Frames
Inside moov/trak Sample Tables vs. WebCodecs ImageDecoder
Unlike animated GIF or APNG where every frame header sits sequentially in a flat byte stream, an animated AVIF uses the ISO Base Media File Format major brand avis with both a static primary item (meta/pitm) and a full movie box (moov/trak). Frame durations live inside the decoding time-to-sample table (stts) scaled by the media header timescale (mdhd), while inter-coded AV1 P-frames and B-frames reference earlier keyframes inside mdat.
Our Worker parses the bounded stbl hierarchy first to establish exact millisecond presentation timestamps and enforce the 240-frame memory guardrail. In browsers supporting Dedicated Worker WebCodecs (Chromium, Edge, Firefox), ImageDecoder reconstructs every inter-predicted VideoFrame inside a try/finally block that guarantees immediate VideoFrame.close() disposal. When ImageDecoder is disabled or unavailable, the engine falls back cleanly to pinned libavif WASM to extract the primary still item while surfacing full container timing.
- Reads exact mdhd timescale and stts delta runs to expose uneven variable-frame-rate delays.
- Guarantees zero leaked GPU/decoder handles by closing every VideoFrame and ImageDecoder instance immediately after RGBA readout.
- Includes a live Force Pinned WASM toggle to audit fallback behavior deterministically.