cwebp is the standard tool for WebP, avifenc for AVIF, and cjxl for JPEG XL. ffmpeg can convert too, but whether the encoder is included depends on the build, so check first. Quality numbers mean different things in each format and have to be compared directly.
Dedicated per-format programs are the baseline for conversion, and ffmpeg is a handy alternative when it's already installed. The options below were picked only from each tool's official documentation, but options and defaults can change between versions, so check with tool-name -h before running. In particular, even the same -q 80 is not the same quality when the format differs.
The quality scale differs by format and tool. Don't compare using the same number. Option ranges are based on each tool's help and manual.
# Photo: lossy WebP. Quality 80, compression effort 6
cwebp -q 80 -m 6 photo.jpg -o photo.webp
# Logo or screenshot: lossless WebP
cwebp -lossless logo.png -o logo.webp# Quality 70, speed 6 (default)
avifenc -q 70 -s 6 photo.jpg photo.avif
# Transparent PNG: color and alpha quality set separately
avifenc -q 70 --qalpha 90 sticker.png sticker.avif# An existing JPEG is normally handled as lossless recompression (the original JPEG can be restored)
cjxl photo.jpg photo.jxl
# A regular image, lossy: distance 1 is described as visually close to lossless
cjxl photo.png photo.jxl -d 1To make images with ffmpeg, encoders such as libwebp, libaom-av1, and libsvtav1 have to be included in the build. Check first with ffmpeg -encoders. A big plus is that you can use video filters on images as is. Resizing is the same as the scale filter.
ffmpeg -encoders
# Check that libwebp shows up in the list
# Shrink to a width of 800 and output WebP (height keeps the aspect ratio)
ffmpeg -i photo.jpg -vf scale=800:-2 -c:v libwebp -quality 80 photo-800.webp
# Make three sizes, widths 480, 800, and 1600, in one go (Linux and Mac)
for w in 480 800 1600; do
ffmpeg -i photo.jpg -vf scale=$w:-2 -c:v libwebp -quality 80 photo-$w.webp
doneConverting a lossy image (JPEG) into another lossy format causes generation loss. Whenever possible, make each format and size directly from the original (camera file, PNG, lossless master). If all you have is a JPEG, keep in mind that it has already been through loss once, and start with the quality set slightly higher.
Location and shooting information the camera embedded (EXIF) may be kept or dropped during conversion, depending on the tool. On a public site, it's a good habit to check which metadata remains in the output file so you don't accidentally expose location data. If the color profile is lost, colors can look different, so open one image in several browsers and compare (color-related symptoms).
The command-line WebP encoder included in libwebp.
The command-line AVIF encoder from libavif. -q sets quality and -s sets speed.
The command-line JPEG XL encoder from libjxl.
Can you consider the results of cwebp -q 80 and avifenc -q 80 to be the same quality?
What should you check first before making a WebP with ffmpeg?