logo hsb.horse
← Back to snippets index

Snippets

Batch Convert Images to AVIF with avifenc

A Bash snippet that recursively scans jpg/jpeg/png files and converts them to .avif using avifenc.

Published: Updated:

A minimal script that converts all jpg/jpeg/png files under a directory to .avif. Uses find -print0 and read -d '' to handle filenames containing spaces.

#!/usr/bin/env bash
set -euo pipefail
while IFS= read -r -d '' file; do
avifenc "$file" -o "${file%.*}.avif" >/dev/null 2>&1
done < <(
find . -type f \( -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' \) -print0
)

Notes

  • If a .avif file with the same name already exists, it will be overwritten
  • To see conversion logs, remove >/dev/null 2>&1