Batch Convert AVIF Using ImageMagick

This article explains how ImageMagick utilizes the libavif library as an underlying delegate to handle AV1 Image File Format encoding and decoding, enabling high-efficiency batch conversions. You will learn the technical mechanics behind this integration, how ImageMagick interfaces with libavif via its modular architecture, and how to execute scalable batch conversion workflows directly from the command line.

The Delegate Architecture

ImageMagick does not implement native AV1 codec algorithms directly within its core codebase. Instead, it relies on an extensible delegate system defined in configuration files such as delegates.xml. When ImageMagick encounters an AVIF file or is instructed to output to the .avif format, it calls libavif—the open-source reference library developed by the Alliance for Open Media (AOM).

During compilation or dynamic runtime loading, ImageMagick identifies the presence of libavif. It registers the library to handle MIME types and file signatures associated with AVIF (image/avif). When an operation is executed, ImageMagick translates its internal canvas and pixel representations into the avifImage and avifEncoder structures defined by the libavif API, handing off the heavy compression and decompression tasks to the underlying codec (such as aom, dav1d, or rav1e).

Verification of AVIF Support

Before executing batch processes, verify that your local ImageMagick build has successfully linked libavif. Run the following command:

magick identify -list format | grep -i avif

If integrated correctly, the output will display AVIF with read (r) and write (w) capabilities.

How Batch Processing Works

ImageMagick facilitates batch processing primarily through two approaches: the mogrify command for in-place or directory-wide transformation, and the magick command paired with shell scripting for fine-grained parallel processing.

1. Native In-Place Batch Conversion with mogrify

The mogrify utility simplifies batch jobs by iterating through file lists natively without external loops:

magick mogrify -format avif -quality 60 -define heic:speed=6 *.jpg

In this pipeline:

2. Multi-Core Batch Processing with Parallel Loops

Because AVIF encoding is computationally intensive, processing large directories using standard shell loops alongside utilities like GNU parallel maximizes CPU core utilization:

find . -name "*.png" | parallel -j $(nproc) magick {} -quality 65 -define heic:speed=4 {.}.avif

Each thread spawns an independent ImageMagick instance that interfaces with its own libavif encoder context, ensuring total isolation, lower risk of memory fragmentation, and full saturation of modern multi-threaded processors.

Handling Advanced AVIF Features

Through libavif, ImageMagick exposes several format-specific controls that can be applied across batch sets: