libavif avifDecoder Struct Explained

This article provides a comprehensive overview of the avifDecoder struct in the libavif library, which serves as the central hub for managing the decoding process of AVIF images. By examining its internal fields, developers can understand how the decoder manages input/output operations, configures codec choices, stores image dimensions, tracks animation playback states, and handles error diagnostics.

The avifDecoder struct is defined in the core avif/avif.h header file of the libavif library. It coordinates the lifecycle of decoding a container file (ISOBMFF) and the underlying compressed AV1 payloads.

1. Configuration and Control Fields

These fields allow developers to customize how the decoding engine behaves before processing an image file:

2. Image and Frame Metadata

These fields store information about the loaded asset once the file header has been parsed:

3. Animation Timing

When dealing with animated AVIF sequences, the avifDecoder tracks playback timing through these specific variables:

4. Input/Output and Internal State

To process the physical data stream and maintain internal tracking, the struct references helper interfaces and private structures: