Can libavif Decode XMP Metadata in AVIF?

This article explains whether the libavif library can decode and extract XMP (Extensible Metadata Platform) metadata from AVIF images. It covers how libavif handles container-level metadata, the specific APIs used to access XMP payloads, and the distinction between extracting the raw data versus parsing the actual XML metadata.

Yes, libavif can decode and extract XMP metadata embedded within an AVIF file. Because the AVIF format is based on the ISO Base Media File Format (ISOBMFF), metadata such as Exif and XMP are stored in dedicated boxes within the file container. The libavif library is fully capable of parsing these boxes to retrieve the raw metadata payload.

How libavif Handles XMP Metadata

When libavif decodes an AVIF image, it reads the container’s metadata box. If XMP metadata is present, the decoder extracts the raw bytes and associates them with the decoded image object.

In the libavif C API, this is managed through the avifImage structure. After a successful decode operation, the raw XMP data is populated in the following location:

Extraction vs. Parsing

It is important to understand the division of labor when using libavif:

  1. Extraction (Supported by libavif): libavif locates the XMP box, decodes the container structure, and outputs the raw, uncompressed XMP packet (typically formatted as XML/RDF).
  2. Parsing (Not supported by libavif): libavif does not interpret, edit, or parse the XML content within the XMP packet. To read individual metadata tags (such as camera settings, copyright info, or creator details), you must pass the extracted raw bytes to an external XML or metadata parsing library, such as Exiv2, ExifTool, or Adobe’s XMP Toolkit.

Summary of the Workflow

To access XMP metadata using libavif: * Initialize the decoder and parse the AVIF file. * Check if the decoded avifImage struct contains data in the xmp field (image->xmp.size > 0). * Read the raw bytes from image->xmp.data. * Pass these bytes to an XML or metadata parsing library to read the specific XMP properties.