How Darktable Integrates AVIF for Raw Export
This article examines how the open-source photography workflow
application Darktable implements open-source AVIF libraries to compress
and export non-destructive raw photographic edits. It details the
underlying software architecture, the handoff between Darktable’s 32-bit
floating-point pixel pipeline and encoders like libavif,
and how high bit-depth color management is maintained throughout the
export process to maximize image fidelity while reducing storage
footprints.
The Core Integration: libavif and Encoder Backends
Darktable does not natively construct AVIF containers or encode AV1
streams using custom, internal code. Instead, its export architecture
relies on libavif, a widely adopted open-source C library
developed by the Alliance for Open Media (AOMedia). During compilation
via CMake, Darktable detects the presence of libavif on the
host system. If present, Darktable builds its AVIF image-input/output
(imageio) module, exposing AVIF as an export target in the lighttable
view.
libavif functions as a wrapper and multiplexer, handling
the ISO Base Media File Format (ISOBMFF) container creation. For the
actual frame compression, libavif links to an underlying
AV1 encoder installed on the system, most commonly:
- libaom: The reference open-source encoder, offering high compression efficiency at the expense of slower processing times.
- rav1e: A memory-safe, Rust-based AV1 encoder optimized for speed and safety.
- SVT-AV1: A multi-threaded, highly optimized production encoder developed by Intel and the AOMedia consortium.
Darktable passes user-defined configuration parameters directly to
libavif, which instructs the active underlying codec on how
to handle the raster data.
From 32-Bit Float to AVIF Encoding
Darktable’s non-destructive processing pipeline computes pixel transformations in a 32-bit floating-point linear color space. When a user triggers an export, the software translates these raw processing adjustments into a finalized raster image through a defined sequence:
- Pipeline Processing: Raw demosaicing, lens corrections, exposure compensation, and color grading modules are calculated sequentially in memory.
- Color Space Conversion and Gamut Mapping: Darktable utilizes LittleCMS (LCMS2) to transform the internal working profile (typically linear Rec. 2020) into the user's selected export profile (such as standard sRGB, Display P3, or wider gamut spaces).
- Quantization:
libavifsupports 8-bit, 10-bit, and 12-bit color depths. Darktable quantizes its 32-bit floating-point pixel buffers into 8-bit or 10-bit/12-bit integer formats depending on the export quality and bit-depth settings chosen by the user. Retaining 10-bit or 12-bit precision prevents banding and tonal posterization in high-dynamic-range scenes. - Metadata and ICC Embedding: Darktable writes EXIF,
XMP, and the exported ICC profile directly into the AVIF file structure
via
libavif's metadata packaging hooks, preserving edit attribution and hardware color-matching instructions.
Export Controls and Encoder Parameters
Within the export module, Darktable translates UI parameters into
low-level instructions passed to libavif:
- Quality vs. Compression Ratio: The user-facing quality slider maps to the encoder's Constant Rate Factor (CRF) or quantization index (\(Q\)-value). A setting of 100 instructs the library to configure true lossless mode, while lower values allocate quantizer steps based on psychoacoustic and visual metrics.
- Speed/CPU Usage Preset: Darktable exposes a speed preset setting that controls the underlying codec’s algorithmic trade-offs (e.g., motion estimation search windows, partition evaluations, and transform tree complexity). Higher speed presets reduce export latency at the cost of slight file-size overhead.
- Tiling and Multithreading: High-resolution digital
camera raw files (e.g., 45 to 60+ megapixels) generate heavy memory
demands. Darktable configures
libavifto use multi-threaded encoding and frame tiling, allowing multiple CPU cores to simultaneously compress different regions of the frame.
By leveraging libavif and modular AV1 backends,
Darktable bridges high-end raw photo processing with modern container
formats, providing photographers with HDR-capable, small-footprint image
files that retain the fidelity of their raw edits.