
Batch Converting AVIF Images: Tools and Methods
Converting AVIF images individually can be tedious, especially when you have hundreds or thousands of files to process. Batch conversion automates the process, saving you valuable time while ensuring consistent results across all your images.
In this comprehensive guide, we explore various tools and methods for batch converting AVIF images, from simple command-line solutions to programmatic approaches using Node.js and Python.
Why Batch Convert?
Batch conversion is essential when you need to:
- Update an entire website's image library to a new format
- Process assets for digital marketing campaigns
- Prepare images for platforms that don't support AVIF
- Create consistent exports from a photo shoot
- Reduce file sizes across a large collection
Method 1: ImageMagick (Command Line)
ImageMagick is the most versatile command-line tool for batch image conversion.
Installation
# macOS
brew install imagemagick
# Ubuntu/Debian
sudo apt install imagemagick
# Windows (using Chocolatey)
choco install imagemagickBasic Batch Conversion
# Convert all AVIF files in current directory to JPG
mogrify -format jpg -quality 85 *.avif
# Convert to PNG
mogrify -format png *.avif
# Convert to WebP with quality setting
mogrify -format webp -quality 80 *.avifAdvanced Options
# Convert with resize (max 1920px wide)
mogrify -format jpg -quality 85 -resize "1920>" *.avif
# Output to different directory
mkdir converted
for f in *.avif; do
magick "$f" -quality 85 "converted/${f%.avif}.jpg"
done
# Recursive conversion (all subdirectories)
find . -name "*.avif" -exec magick {} -quality 85 {}.jpg \;Method 2: FFmpeg
FFmpeg is another powerful option, especially if you're already using it for video processing.
# Convert single file
ffmpeg -i input.avif output.jpg
# Batch convert with shell loop
for f in *.avif; do
ffmpeg -i "$f" -q:v 2 "${f%.avif}.jpg"
done
# With quality control (lower number = higher quality)
for f in *.avif; do
ffmpeg -i "$f" -qscale:v 3 "${f%.avif}.jpg"
doneMethod 3: Node.js with Sharp
Sharp is a high-performance Node.js library that's excellent for batch processing.
// batch-convert.js
const sharp = require('sharp');
const fs = require('fs');
const path = require('path');
const inputDir = './input';
const outputDir = './output';
const format = 'jpeg'; // 'jpeg', 'png', 'webp'
const quality = 85;
// Create output directory
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Get all AVIF files
const files = fs.readdirSync(inputDir)
.filter(f => f.toLowerCase().endsWith('.avif'));
console.log(`Converting ${files.length} files...`);
// Process files
async function convert() {
for (const file of files) {
const inputPath = path.join(inputDir, file);
const outputName = file.replace(/\.avif$/i, `.${format}`);
const outputPath = path.join(outputDir, outputName);
await sharp(inputPath)
[format]({ quality })
.toFile(outputPath);
console.log(`Converted: ${file}`);
}
console.log('Done!');
}
convert();Run with:
npm install sharp
node batch-convert.jsParallel Processing for Speed
// batch-convert-parallel.js
const sharp = require('sharp');
const fs = require('fs');
const path = require('path');
const CONCURRENCY = 4; // Number of parallel conversions
async function batchConvert(inputDir, outputDir, options = {}) {
const { format = 'jpeg', quality = 85 } = options;
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const files = fs.readdirSync(inputDir)
.filter(f => f.toLowerCase().endsWith('.avif'));
// Process in chunks for parallelism
for (let i = 0; i < files.length; i += CONCURRENCY) {
const chunk = files.slice(i, i + CONCURRENCY);
await Promise.all(chunk.map(async (file) => {
const input = path.join(inputDir, file);
const output = path.join(outputDir,
file.replace(/\.avif$/i, `.${format}`));
await sharp(input)[format]({ quality }).toFile(output);
console.log(`Converted: ${file}`);
}));
}
}
batchConvert('./input', './output', { format: 'jpeg', quality: 85 });Method 4: Python with Pillow
Pillow with the pillow-avif-plugin provides AVIF support in Python.
# batch_convert.py
from PIL import Image
import pillow_avif
import os
from pathlib import Path
input_dir = Path('./input')
output_dir = Path('./output')
output_format = 'JPEG' # 'JPEG', 'PNG', 'WEBP'
quality = 85
output_dir.mkdir(exist_ok=True)
avif_files = list(input_dir.glob('*.avif'))
print(f'Converting {len(avif_files)} files...')
for avif_path in avif_files:
img = Image.open(avif_path)
# Convert to RGB if saving as JPEG (no alpha)
if output_format == 'JPEG' and img.mode in ('RGBA', 'P'):
img = img.convert('RGB')
ext = {'JPEG': 'jpg', 'PNG': 'png', 'WEBP': 'webp'}[output_format]
output_path = output_dir / f'{avif_path.stem}.{ext}'
img.save(output_path, output_format, quality=quality)
print(f'Converted: {avif_path.name}')
print('Done!')Run with:
pip install Pillow pillow-avif-plugin
python batch_convert.pyMethod 5: Desktop Software
For those who prefer a graphical interface, several desktop applications support batch conversion:
XnConvert (Free)
XnConvert is a free, cross-platform batch image converter:
- Add your AVIF files to the input panel
- Configure output format and quality in the Output tab
- Add any transformations (resize, filters) in the Actions tab
- Click Convert
Adobe Photoshop
Using Photoshop's Image Processor:
- File → Scripts → Image Processor
- Select source folder with AVIF files
- Choose output folder and format
- Set quality and resize options
- Click Run
IrfanView (Windows)
IrfanView with plugins offers batch conversion on Windows via File → Batch Conversion.
Best Practices for Batch Conversion
1. Always Backup Original Files
# Create backup before batch operations
cp -r input_folder backup_folder2. Test on Sample First
Before processing thousands of files, test your settings on a few representative images:
# Convert just first 5 files as test
ls *.avif | head -5 | xargs -I {} magick {} -quality 85 {}.jpg3. Use Consistent Quality Settings
| Use Case | Quality |
|---|---|
| Archival/Print | 90-100% |
| Web (high quality) | 80-85% |
| Web (balanced) | 70-80% |
| Thumbnails | 60-70% |
4. Consider Output Organization
# Organize by format and date
output/
├── jpg/
│ └── 2025-03/
├── png/
│ └── 2025-03/
└── webp/
└── 2025-03/5. Log Your Conversions
# Bash script with logging
#!/bin/bash
LOG_FILE="conversion_log.txt"
echo "Conversion started: $(date)" > $LOG_FILE
for f in *.avif; do
if magick "$f" -quality 85 "${f%.avif}.jpg"; then
echo "SUCCESS: $f" >> $LOG_FILE
else
echo "FAILED: $f" >> $LOG_FILE
fi
done
echo "Conversion completed: $(date)" >> $LOG_FILEPerformance Tip: For very large batches (10,000+ images), use parallel processing and consider running overnight. SSD storage significantly improves batch conversion speed.
Troubleshooting Common Issues
Out of Memory Errors
- Process files in smaller batches
- Limit parallel processing concurrency
- Close other applications
Slow Processing
- Use Sharp (Node.js) or libvips for faster processing
- Enable parallel processing
- Use SSD storage
Color Shift Issues
- Ensure color profile preservation in your tool
- Convert to sRGB for web use
Conclusion
Batch conversion of AVIF images doesn't have to be complicated. Whether you prefer command-line tools like ImageMagick, programming with Sharp or Pillow, or desktop applications like XnConvert, there's a solution that fits your workflow.
For occasional conversions, try our online tools. For regular batch processing, set up a script with the methods above and integrate it into your workflow.
Ready to convert? Try our tools: