Mark Stephens Mark founded the company and has worked with Java and PDF since 1997. The original creator of the core code, he is also a NetBeans enthusiast who enjoys speaking at conferences and reading. He holds an Athletics Blue and an MA in Mediaeval History from St. Andrews University.

How to write AVIF image files in Java (Tutorial)

2 min read

AVIF file

TL;DR

Java’s ImageIO does not support AVIF output. To add AVIF support to ImageIO, you can use the Open source vavi-image-avif plugin (which is a wrapper around libavif) or the commercial JDeli library (which is a pure Java Implementation).

Does Java support AVIF natively?

No. ImageIO ships without an AVIF codec, so both reads and writes fail silently or throw an exception:

// Both of these fail with vanilla ImageIO
// Read
BufferedImage image = ImageIO.read(new File("input.avif")); // returns null
// Write
ImageIO.write(bufferedImage, "avif", new File("output.avif")); // returns false

You need an external library. The two main options are vavi-image-avif (free, open source) and JDeli (commercial).

JDeli vs vavi-image-avif: which should you use?

JDelivavi-image-avif
Pure Java (no native binaries)✗ (wraps native libs)
Works as ImageIO plugin
Direct API (non-ImageIO)
Encoder options (quality, speed)Limited
Supports other formats (WebP, HEIC, TIFF…)
CostCommercialFree
SupportIncludedGitHub issues
Actively developedLimited

vavi-image-avif is a reasonable choice for a simple, low-stakes use case. If you are running a server, distributing an application, or need format breadth beyond AVIF, JDeli is the safer option.

Option 1: Add AVIF support to ImageIO (no code changes)

JDeli registers itself as an ImageIO plugin, so your existing read/write calls work without modification once it is on the classpath.

Maven

<dependency>
    <groupId>com.idrsolutions</groupId>
    <artifactId>jdeli</artifactId>
    <version>[JDELI_VERSION]</version>
</dependency>

Gradle

implementation 'com.idrsolutions:jdeli:[JDELI_VERSION]'

Alternatively, download the trial jar and add it to your classpath manually.

Once JDeli is on the classpath, your existing ImageIO code works unchanged:

// Read — works once JDeli is on the classpath
BufferedImage bufferedImage = ImageIO.read(new File("input.avif"));
// Write — same
ImageIO.write(bufferedImage, "avif", new File("output.avif"));

Option 2: Write AVIF directly with the JDeli API

The JDeli API gives you more control and does not depend on ImageIO’s plugin registration order.

  1. Add JDeli to your class or module path. (download the trial jar)
  2. Create a File or OutputStream for the output.
  3. Call JDeli.write() with your image, format, and output target.
// String format
JDeli.write(bufferedImage, "avif", new File("/path/to/output.avif"));
// Type-safe enum (preferred)
JDeli.write(bufferedImage, OutputFormat.AVIF, new File("/path/to/output.avif"));

Controlling output with AVIFEncoderOptions

For production use you will usually want explicit control over compression. Pass an AVIFEncoderOptions object instead:

AVIFEncoderOptions options = new AVIFEncoderOptions();
options.setQuality(80);      // 0–100, higher = better quality, larger file
JDeli.write(bufferedImage, options, new File("/path/to/output.avif"));

See the AVIFEncoderOptions API reference for the full list of settings.

Frequently asked questions

What is the AVIF format?

AVIF (AV1 Image File Format) is an image format derived from the AV1 video codec. It offers better compression than JPEG and WebP at equivalent visual quality, with typical file sizes 50% smaller than JPEG. It supports HDR, wide colour gamut, and transparency, making it increasingly common for web images.

Which browsers support AVIF?

AVIF has broad browser support, covering Chrome, Firefox, Safari 16+, and Edge. See caniuse.com/avif for current data.

Can I read AVIF files in Java with JDeli?

Yes. See our companion article: how to read AVIF files in Java.

Is JDeli pure Java?

Yes. JDeli has no native binaries and makes no calls to external libraries. This matters in server or distributed environments where deploying platform-specific binaries is impractical or a security concern.

Other useful AVIF resources

As experienced Java developers, we help you work with images in Java and bring over a decade of hands-on experience with many image file formats.



Are you a Java Developer working with Image files?

Mark Stephens Mark founded the company and has worked with Java and PDF since 1997. The original creator of the core code, he is also a NetBeans enthusiast who enjoys speaking at conferences and reading. He holds an Athletics Blue and an MA in Mediaeval History from St. Andrews University.