AVIF ftyp Box: Identifying Valid AVIF Images

The AV1 Image File Format (AVIF) relies on the ISO Base Media File Format (ISOBMFF) container, where the File Type box, denoted by the four-character code ftyp, serves as the foundational identifier for file validity. This article explains the technical purpose of the ftyp box, its internal structure, and how decoders read its contents to confirm that a file is indeed a valid AVIF document before attempting to decode any pixel data.

Structural Placement in the Container

In an ISOBMFF-compliant file, the ftyp box is placed at the very beginning of the file structure. Because binary parsers read data sequentially, placing the ftyp box first allows decoders, web browsers, and operating systems to immediately determine whether they can process the file without buffering the entire payload into memory. If the ftyp box is missing, corrupted, or positioned behind other media data, standard conformant parsers will instantly reject the file as invalid.

Components of the ftyp Box

The ftyp box contains metadata fields that explicitly state the standards and profiles to which the file adheres:

  • Major Brand (major_brand): A 4-byte identifier designating the primary specification used to author the file. For standard still AVIF images, this is typically set to avif. For image sequences or animated files, it is often set to avis.
  • Minor Version (minor_version): A 4-byte integer indicating the minor specification or revision level of the major brand.
  • Compatible Brands (compatible_brands[]): A variable-length array of 4-byte identifiers indicating other specifications with which the file remains compatible.

Brand Verification and Validation

A file is not verified as AVIF purely by its .avif file extension, as extensions can be mislabeled or spoofed. Instead, parsers inspect the ftyp payload for specific brand codes:

  1. Primary Conformance: The parser evaluates the major_brand. If it reads avif, the file is identified as a still image utilizing AV1 compression within the Multi-Image Application Format (MIAF) framework.
  2. Fallback and Compatibility: If the major_brand contains a generic or related brand (such as mif1 for generic image items), the parser iterates through the compatible_brands list. To be recognized as an AVIF document, the array must contain the avif brand (or avis for sequences), usually alongside base baseline profiles like mif1 (HEIF image) and miaf (MIAF constrained media).

The Fast-Fail Mechanism

The functional role of the ftyp box serves as a fast-fail gatekeeper. Image decoders must allocate memory and initialize dedicated hardware or software AV1 pipelines to process compressed frames. By evaluating the ftyp box first, the parser confirms:

  • The file uses an ISOBMFF-compatible structure.
  • The content conforms to constraints required by the AVIF specification.
  • The software possesses the necessary codec features to decode the internal bitstream.

If the necessary AVIF signatures are absent from both the major_brand and the compatible_brands array, the parser halts execution immediately, protecting system resources from handling incompatible or malicious files.