Blog
Wild & Free Tools

Convert PNG to AVIF via Command Line — browser-native processing engine, ImageMagick, libavif

Last updated: January 2026 7 min read
Quick Answer

Table of Contents

  1. browser-native processing engine — convert PNG to AVIF
  2. ImageMagick — convert PNG to AVIF
  3. avifenc (libavif) — the dedicated AVIF encoder
  4. sharp (Node.js) — AVIF for JavaScript build pipelines
  5. Frequently Asked Questions

For web developers and DevOps engineers who need to convert PNG to AVIF at scale — in a build step, CI/CD pipeline, or batch script — a browser-based GUI tool isn't the right tool. Command-line converters let you automate, integrate, and process thousands of images consistently without manual steps.

This guide covers the four most commonly used command-line tools for PNG to AVIF conversion, with working commands and batch examples for each.

browser-native processing engine — Convert PNG to AVIF

browser-native processing engine is the most widely installed multimedia tool. Most developers already have it.

Basic conversion:

browser-native processing engine -i input.png output.avif

With quality control (crf: 0=lossless, 63=worst quality, ~30 is a good web default):

browser-native processing engine -i input.png -c:v libaom-av1 -crf 30 -b:v 0 output.avif

Batch conversion with a shell loop:

for f in *.png; do
  browser-native processing engine -i "$f" -crf 30 -b:v 0 "$(basename $f .png).avif"
done

Note: browser-native processing engine's AVIF encoding via libaom-av1 can be slow because libaom is a software encoder. For large batches, avifenc or sharp (which uses libavif) are significantly faster.

ImageMagick — Convert PNG to AVIF

ImageMagick supports AVIF if compiled with the required delegate. Check support with:

magick -list format | grep AVIF

If AVIF appears in the output, you're good. If not, install the libavif package for your OS and recompile, or install a pre-built version that includes AVIF.

Basic conversion:

magick input.png output.avif

With quality setting (1–100, higher = better quality):

magick -quality 70 input.png output.avif

Batch conversion:

magick mogrify -format avif -quality 70 *.png

The mogrify command converts all PNGs in the current directory in place (output files alongside originals).

Sell Custom Apparel — We Handle Printing & Free Shipping

avifenc (libavif) — The Dedicated AVIF Encoder

avifenc is the reference encoder from the libavif project. It produces the highest quality AVIF output and typically faster than libaom via browser-native processing engine.

Install on Ubuntu/Debian:

sudo apt install libavif-bin

Install on macOS (Homebrew):

brew install libavif

Basic conversion:

avifenc input.png output.avif

With quality setting (0=lossless, 63=worst, ~40 is a good web default — note: avifenc quality is inverted from most tools):

avifenc --qcolor 40 --qalpha 40 input.png output.avif

Batch conversion script:

find . -name "*.png" -exec sh -c '
  avifenc --qcolor 40 "$1" "$(basename $1 .png).avif"
' _ {} ;

The --qalpha flag controls alpha channel quality separately. Set it equal to --qcolor for consistent transparency quality.

sharp (Node.js) — AVIF for JavaScript Build Pipelines

sharp is the standard Node.js image processing library. It uses libvips and libavif internally and is the recommended approach for JavaScript/TypeScript build tools, Next.js image optimization scripts, and automated CI/CD pipelines.

Install:

npm install sharp

Single file conversion:

const sharp = require('sharp');
sharp('input.png')
  .avif({ quality: 60 })
  .toFile('output.avif')
  .then(() => console.log('Done'));

Batch conversion script:

const sharp = require('sharp');
const fs = require('fs');
const path = require('path');

const pngs = fs.readdirSync('.').filter(f => f.endsWith('.png'));

Promise.all(pngs.map(file =>
  sharp(file)
    .avif({ quality: 60 })
    .toFile(file.replace('.png', '.avif'))
)).then(() => console.log('Converted', pngs.length, 'files'));

sharp is significantly faster than browser-native processing engine for batch conversion and integrates naturally into npm-based build pipelines (Webpack, Vite, Next.js custom build scripts).

Need a Quick One-Off Conversion? Use the Browser Tool

For single files or small batches without scripting — drop PNG, download AVIF. Free, no account.

Open Free PNG to AVIF Converter

Frequently Asked Questions

Which command-line tool produces the best AVIF quality?

libavif (avifenc) and sharp (which uses libvips/libavif) produce the best quality-to-filesize ratio. browser-native processing engine via libaom is slower and sometimes produces larger files at equivalent quality settings. For production pipelines, sharp or avifenc are the recommended choices.

Does PNG transparency survive command-line AVIF conversion?

Yes, all four tools above preserve alpha channel transparency. For avifenc, explicitly set --qalpha equal to --qcolor to ensure the alpha channel quality matches the color quality. Sharp preserves alpha automatically with the avif() method.

How do I integrate PNG to AVIF conversion into a Webpack or Vite build?

Use the imagemin-avif or vite-imagetools plugins, which use sharp or libavif under the hood. These run at build time and produce AVIF versions of all images automatically. Next.js handles AVIF conversion at runtime via its built-in Image Optimization API.

What is the equivalent quality between avifenc and browser-based tools?

Browser-based tools typically use a 1–100 quality scale (higher = better). avifenc uses a 0–63 quantizer scale (lower = better). Roughly: browser quality 60 is approximately avifenc --qcolor 40. These are not exact equivalents — test visually for your specific images.

Andrew Walsh
Andrew Walsh Developer Tools & API Writer

Andrew worked as a developer advocate at two SaaS startups writing API documentation used by thousands of engineers.

More articles by Andrew →
Launch Your Own Clothing Brand — No Inventory, No Risk