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:

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:

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.