filter · Image filters
Convert JPEG to AVIF (convert_jpeg_to_avif)
- Category:
- Image
- CoreFilters:
- No
- OptimizeForBandwidth:
- No
- Risk:
- Test first
convert_jpeg_to_avif encodes photographic JPEG sources as AVIF.
How it works
Four filters transcode images to AVIF.
All four are opt-in. They sit outside rewrite_images and outside the CoreFilters set, so enabling rewrite_images alone produces no AVIF output — you have to name the AVIF filters you want.
AVIF is served only when the request advertises Accept: image/avif. There is no User-Agent sniffing. A client that does not advertise AVIF falls through the existing format order unchanged. The cache key folds in the client’s AVIF capability, so variants are stored and served per capability exactly as WebP variants are.
The AV1 encoder is statically linked into the module. There is no separate package or codec library to install.
Caveat: RewriteLevel AllFilters enables all four
“Opt-in” holds for filters you name explicitly. The four AVIF filters are not in the dangerous-filter set, so RewriteLevel AllFilters switches all of them on. If you run AllFilters, you are running the AVIF filters whether or not you listed them.
When to use it
- Not in CoreFilters: it runs only when you enable it by name.
- Risk rating on these docs: Test first.
Risks
-
An AVIF candidate costs a full extra decode and encode per image. The module encodes an AVIF candidate and keeps it only if it beats the WebP or optimized-original candidate. Each candidate is produced from its own decode; the decode is not shared between formats. AV1 encoding is also slower than WebP encoding at comparable quality, so enabling AVIF measurably raises the CPU cost of the first rewrite of every image. Watch
ImageMaxRewritesAtOnceand the rewrite deadline on busy origins. -
Pick-smaller means some of that work is discarded. When the AVIF candidate is not smaller, it is dropped and the existing variant is served. The CPU is spent either way.
-
Images with C2PA content credentials are not converted. A source carrying a C2PA manifest is left alone by all four filters, so its provenance chain survives the pipeline.
-
Delivery depends on the
Acceptheader reaching the module. As withconvert_jpeg_to_webp, a CDN or proxy that rewritesAcceptor ignoresVary: Acceptcan cross-serve formats. Test with your CDN configuration before rolling out.
Configuration
Enable it in the module configuration, at server, virtual-host or location scope:
Apache
ModPagespeedEnableFilters convert_jpeg_to_avifnginx
pagespeed EnableFilters convert_jpeg_to_avif;IIS (pagespeed.config)
pagespeed EnableFilters convert_jpeg_to_avifOn IIS, use the same filter names in pagespeed.config without the trailing semicolon — see IIS configuration.
| Parameter | Default | Description |
|---|---|---|
AvifRecompressionQuality | 60 | AVIF quality level; -1 uses ImageRecompressionQuality |
AvifRecompressionQualityForSmallScreens | 50 | AVIF quality for small-screen clients; -1 uses AvifRecompressionQuality |
AvifAnimatedRecompressionQuality | 50 | Quality for animated AVIF output |
AvifQualityForSaveData | 45 | AVIF quality for clients sending Save-Data: on |
AvifTimeoutMs | 5000 | Wall-clock budget for one AVIF encode; the encode is abandoned when it is exceeded |
These mirror the Webp* quality parameters: a value of -1 falls back to the more general setting, so you can set ImageRecompressionQuality alone and let AVIF follow it.
AvifTimeoutMs exists because AV1 still-image encoding is materially slower than WebP. The budget stops one expensive image from occupying a rewrite slot indefinitely; when it is hit the AVIF candidate is abandoned and the existing WebP or optimized-original output is served, so a timeout costs CPU but never a broken image. Raise it if large photographic sources are being skipped, lower it if AVIF encodes are crowding out other rewrites.
Scoping, ForbidFilters and the thresholds filters read:
Choosing filters
.
Live example
Re-encodes photographic JPEGs as AVIF for browsers that accept it.
Measured on the demo page, original against optimized:
-
Total bytes
240.9 KB → 10.2 KB −96%
Frequently asked questions
- What does the convert_jpeg_to_avif filter do?
convert_jpeg_to_avifencodes photographic JPEG sources as AVIF.- Is convert_jpeg_to_avif enabled by default?
- No.
convert_jpeg_to_avifis not in CoreFilters, the default RewriteLevel; it runs only when you enable it by name withEnableFilters. - How do I enable convert_jpeg_to_avif on Apache and nginx?
- Add
ModPagespeedEnableFilters convert_jpeg_to_avifon Apache orpagespeed EnableFilters convert_jpeg_to_avif;on nginx. On IIS, addpagespeed EnableFilters convert_jpeg_to_avifto pagespeed.config.
Related filters
- convert_jpeg_to_webp — Convert JPEG to WebP
- convert_to_avif_lossless — Lossless AVIF
- rewrite_images — Optimize images
- convert_to_avif_animated — Animated AVIF
- recompress_avif — Recompress AVIF
- convert_gif_to_png — Convert GIF to PNG
- convert_jpeg_to_progressive — Progressive JPEG
- convert_png_to_jpeg — Convert PNG to JPEG
This page is drawn from the convert_jpeg_to_avif entry on Image filters. Every filter in one table: PageSpeed filters.