How Android Integrates libavif for Native AVIF
This article provides an overview of how the Android Open Source
Project (AOSP) incorporates the libavif library to enable
native AV1 Image File Format (AVIF) support. It details the
architectural integration within the Android media framework, the
relationship between libavif and AV1 decoders, and how
developers benefit from this implementation starting from Android
12.
The Role of libavif in AOSP
Beginning with Android 12 (API level 31), Google introduced
system-wide, native support for the AVIF image format. To decode and
encode these highly compressed images, AOSP integrates
libavif—an open-source C library developed by the Alliance
for Open Media (AOM). Located within the AOSP source tree under the
external/libavif directory, this library serves as the core
engine for parsing the container structure of AVIF files, which are
based on the ISO Base Media File Format (ISOBMFF).
Architecture and Decoding Pipeline
While libavif is responsible for parsing the container
metadata, color profiles, and grid layouts of an AVIF image, it does not
decode the raw AV1 video bitstream itself. Instead, the integration
relies on a modular pipeline within Android’s media framework:
- API Layer: When an application requests an image
via standard APIs like
BitmapFactoryorImageDecoder, the request is routed to Android’s native graphics pipeline (libhwui). - Container Parsing: The framework invokes
libavifto parse the AVIF file container, extracting essential metadata such as image dimensions, rotation, alpha channels, and depth maps. - AV1 Bitstream Decoding: To decode the actual
compressed image data,
libavifinterfaces with Android’s system-level AV1 decoders. In AOSP, this is typically handled bylibgav1(a software AV1 decoder) or a hardware-accelerated AV1 decoder provided by the device’s chipset manufacturer via the MediaCodec framework. - Rendering: Once decoded, the raw pixel data is
handed back to the Android graphics system to be rendered as a standard
Bitmap.
Support for Advanced Imaging Features
By integrating libavif directly into the operating
system platform, Android natively supports advanced features of the AVIF
format without requiring third-party libraries at the application level.
This includes:
- High Dynamic Range (HDR): Support for 10-bit and 12-bit color depth, as well as Wide Color Gamut (WCG) color spaces.
- Alpha Channels: Seamless handling of transparent overlays and lossless auxiliary images.
- Monochrome and Multi-channel Images: Efficient storage of grayscale and specialized image types.
Benefits of System-Level Integration
Integrating libavif directly into AOSP ensures that all
Android applications can automatically read and write AVIF files without
increasing their APK size. This system-level support enables apps to
utilize AVIF’s superior compression efficiency—which significantly
outperforms JPEG and WebP in quality-to-file-size ratio—while
maintaining fast, standardized, and secure decoding across a wide
variety of Android devices.