AVIF Clean Aperture Box Cropping Explained

The AVIF image format relies on the Clean Aperture box (clap) to define display-level cropping without altering or re-encoding the underlying compressed AV1 bitstream. Derived from the ISO Base Media File Format (ISOBMFF) and constrained by the Multi-Image Application Format (MIAF), the clap box provides rational mathematical values that designate the visible rectangular area of an image. This article details the structure of the clean aperture box, its mathematical calculation model, and how compliant AVIF decoders interpret it to crop images for display.

The Role of the clap Box in AVIF

AVIF separates the encoded pixel canvas from the final rendered output. When an image is encoded with padding, edge artifacts, or an aspect ratio different from the target display, the encoder includes a clap property box within the image item properties (iprp).

Because it is an item property rather than a bitstream alteration, applying a crop via a clap box is entirely lossless and reversible. Decoders decode the full AV1 frame first, then apply the clap boundaries to determine the final presentation canvas.

Structure and Fields of the clap Property

The clap box uses fractional arithmetic rather than fixed integer pixels to prevent rounding errors across varying subsampling schemes. It contains four fractional parameters, each represented as a numerator (N) and a denominator (D):

  1. cleanApertureWidth (cleanApertureWidthN / cleanApertureWidthD): The exact width of the cropped viewing area.
  2. cleanApertureHeight (cleanApertureHeightN / cleanApertureHeightD): The exact height of the cropped viewing area.
  3. horizOff (horizOffN / horizOffD): The horizontal offset of the center of the crop rectangle relative to the center of the coded image canvas.
  4. vertOff (vertOffN / vertOffD): The vertical offset of the center of the crop rectangle relative to the center of the coded image canvas.

All values are signed 32-bit integers for numerators and unsigned 32-bit integers for denominators.

Calculating the Display Rectangle

To derive the pixel coordinates of the visible area from the coded dimensions (\(W_c\) and \(H_c\)), decoders compute the position of the cropping rectangle relative to the image center:

  1. Center Calculation: \[\text{Center}_x = \frac{W_c}{2} + \frac{\text{horizOffN}}{\text{horizOffD}}\] \[\text{Center}_y = \frac{H_c}{2} + \frac{\text{vertOffN}}{\text{vertOffD}}\]

  2. Boundary Derivation: \[\text{Left} = \text{Center}_x - \frac{\text{cleanApertureWidthN}}{2 \times \text{cleanApertureWidthD}}\] \[\text{Top} = \text{Center}_y - \frac{\text{cleanApertureHeightN}}{2 \times \text{cleanApertureHeightD}}\] \[\text{Right} = \text{Left} + \frac{\text{cleanApertureWidthN}}{\text{cleanApertureWidthD}}\] \[\text{Bottom} = \text{Top} + \frac{\text{cleanApertureHeightN}}{\text{cleanApertureHeightD}}\]

MIAF Alignment and Constraints

The AVIF specification mandates adherence to MIAF (ISO/IEC 23000-22) constraints regarding clap usage:

If a clap box violates any of these constraints or yields an empty display area, compliant AVIF decoders must ignore the clap box and render the full coded canvas.