Choosing an AVIF quality setting is easy if file size is the only concern. The difficult part is deciding how much visible degradation is acceptable. A quality value of 40 does not mean a perceptual quality score of 40, nor does it guarantee the same result for every image. Different sources can respond very differently to identical encoder settings.
SSIMULACRA2 helps close that gap by comparing a decoded compressed image against a reference. But applying an exhaustive quality search to every image can turn an otherwise straightforward conversion pipeline into a costly encoding workload. When the goal is reasonable web image quality rather than perfect optimization of every file, there is a simpler approach: calibrate one AVIF quality setting on a representative sample, inspect the results, and use that setting for the rest of the collection.
AVIF quality and SSIMULACRA2 are different numbers
The quality option passed to an AVIF encoder is an instruction about compression. SSIMULACRA2 is a measurement of the encoded result. Their scales are not interchangeable: AVIF quality: 40 does not imply SSIMULACRA2 = 40, 60, or any other fixed score.
To measure an encode, decode it and compare it with the reference:
ssimulacra2 reference.png encoded-decoded.png
Higher SSIMULACRA2 scores indicate greater perceptual similarity. Its official documentation describes a score around 50 as medium quality and around 70 as high quality. A threshold of 60 can be a useful pragmatic target, but it is a policy choice, not a universal definition of an acceptable image. Always inspect representative results at their actual display size.
Why exhaustive per-image optimization gets expensive
A strict optimizer can encode an image repeatedly at different quality values, measure each candidate with SSIMULACRA2, then keep the smallest acceptable result. That often extracts more compression efficiency because an easy image might pass at a low quality while a difficult image needs a higher one.
The disadvantage is the number of encodes. If there are N images and each takes K candidate encodes to find an acceptable setting, that is on the order of N × K encodes, plus decoding and scoring. In practice, high-effort AVIF encoding can dominate the cost; running the SSIMULACRA2 metric itself is not necessarily the expensive part.
Choosing one quality per folder reduces search work, but still requires sampling, measuring and maintaining separate settings for different groups. For collections with a consistent delivery requirement and some tolerance for outliers, the added complexity may not be worthwhile.
| Strategy | Calibration work | Main trade-off |
|---|---|---|
| Per-image adaptive quality | Several candidate encodes per image | Fine-grained control, highest calibration cost |
| Per-group adaptive quality | Several candidate encodes for each group's sample | Less work, but more configuration and group-dependent results |
| One fixed quality | Candidate encodes on a limited calibration sample | Low operational complexity, accepts some over- and under-compressed images |
The important distinction: average score versus pass rate
Before choosing a quality value, define what “good enough” means. Two superficially similar goals produce very different encoder settings:
- Average-score goal: the mean SSIMULACRA2 across the sample should be about 60.
- Pass-rate goal: approximately 90% of images should receive SSIMULACRA2 ≥ 60, while the remaining images may fall below it.
These are not equivalent. A high score on a simple image can compensate for a poor score on a difficult image when calculating the mean. For example, half the images scoring 75 and half scoring 55 produce an average of 65, yet only half meet a threshold of 60.
For a general web-image workflow where most images should look acceptable and a minority of failures are tolerable, the pass-rate goal is often more useful. Measure:
pass_rate = count(scores >= 60) / count(all_scores)
Also record the distribution of failures and inspect the worst-looking images. A sample with 9% scoring 59 is materially different from one with 9% scoring 30, even though both have the same pass rate.
What a real calibration exercise showed
In an exploratory AVIF calibration, an adaptive procedure selected different quality settings for different image groups, spanning roughly the mid-30s to the mid-40s. This was expected: some groups contained images that crossed the chosen SSIMULACRA2 threshold early, while a few difficult samples required substantially higher encoder quality.
However, the adaptive rule was stricter than the actual delivery requirement. It tried to make almost every tested image in each group pass a threshold, with only a narrowly limited outlier. That protects difficult images, but it can also push an entire group to a higher quality because of one exceptional sample.
Re-examining the measurements against a different goal—roughly nine images out of ten at SSIMULACRA2 60 or above—made a single AVIF quality around 39–40 a plausible compromise. In that comparison, 39 favored smaller output while 40 provided more headroom for images near the threshold. Those values were derived from the calibration data and follow-up analysis; a full fixed-quality conversion and independent corpus-wide validation had not been performed. The exact file-size benefit of 39 over 40 was not established.
The lesson is not that AVIF quality 39 or 40 works everywhere. It is that a fixed setting can be reasonable when it matches an explicitly chosen quality distribution. A different encoder, image mix, color pipeline or perceptual threshold can lead to a different answer.
How to calibrate AVIF quality once
- Choose the acceptable failure rate. For example, require approximately 90% of images to reach SSIMULACRA2 ≥ 60. Decide whether this is a flexible target or a strict release requirement.
- Construct a genuinely representative sample. Include different dimensions, source formats, gradients, sharp edges, textures and low-detail images. Randomly sample from the real workload and use stratification if one category would otherwise be missed. Selecting files only by compressed bytes per pixel is a useful heuristic for range coverage, not a guarantee of perceptual representativeness.
- Test a small range of encoder qualities. Start with a few candidates around a visually acceptable setting, rather than trying the entire quality scale. For example, test nearby values such as 38, 39, 40 and 42 on the same images.
- Keep the encoding pipeline identical. Hold resolution, orientation, color conversion, encoder implementation, effort, chroma subsampling, bit depth and preprocessing constant. If you apply a watermark, the reference image must include the same watermark and transformations before the compressed result is compared.
- Record score and size together. For each candidate calculate the share of images scoring at least 60, the distribution below the threshold and the total encoded bytes for the same sample. Do not infer bandwidth savings from the quality number alone.
- Inspect the failures. Look at faces, text, thin lines, gradients and other details that matter to the intended presentation. Check at realistic display sizes, not just zoomed-in comparisons.
- Pick the lowest satisfactory quality, then validate it. Test the candidate on a separate random holdout that did not influence the choice. If missing the 90% target would be costly, leave a safety margin and treat sampling uncertainty seriously. If occasional failure is acceptable, a more aggressive value may be reasonable.
Calibrating once does not mean ignoring future changes. Repeat a small sample check when the source mix, image dimensions, encoder version, delivery transformation or visual requirements change.
A minimal Sharp and SSIMULACRA2 comparison
This simplified example uses Sharp's AVIF encoder to generate two candidates from the same input. It is an illustrative calibration snippet, not a claim that every project should use these encoder options or quality values. Run it as an ES module after installing sharp.
import sharp from 'sharp';
const source = 'sample.png';
const encoding = {
effort: 9,
chromaSubsampling: '4:4:4',
bitdepth: 8,
tune: 'iq',
lossless: false
};
// Use the same orientation and color conversion in both paths.
await sharp(source)
.rotate()
.toColourspace('srgb')
.png()
.toFile('reference.png');
for (const quality of [39, 40]) {
const encoded = `candidate-q${quality}.avif`;
await sharp(source)
.rotate()
.toColourspace('srgb')
.avif({ ...encoding, quality })
.toFile(encoded);
await sharp(encoded)
.png()
.toFile(`candidate-q${quality}.png`);
}
Then compare the decoded candidates to the prepared reference:
ssimulacra2 reference.png candidate-q39.png
ssimulacra2 reference.png candidate-q40.png
For a real test, automate this process across the sampled images and collect the score and file size for every candidate. If your production pipeline resizes, crops, overlays or otherwise transforms images, apply the same operations to the comparison reference. Otherwise, SSIMULACRA2 will partly measure the transformation rather than the compression loss.
Once a global quality is selected, production encoding becomes ordinary single-pass AVIF conversion. You no longer have to run a quality search for each image or folder. This removes repeated trial encodes; it does not eliminate the cost of the one encode every output image still needs.
When one AVIF quality is the wrong choice
A fixed setting is a trade-off, not a universal optimum. Adaptive encoding remains valuable when individual image quality floors are contractual, visual failures are unacceptable, sources vary dramatically, or optimizing every byte justifies the extra compute and implementation complexity.
Be especially careful with mixed image types. Photographs, flat graphics, fine text and previously compressed sources do not necessarily respond alike. If one class repeatedly fails the acceptance test, a small number of format- or content-specific profiles may be more efficient than either extreme: one universal quality or full per-image optimization.
Also distinguish encoder speed from calibration speed. Using one quality avoids repeated experiments, but encoding all images at a very high effort can still be computationally expensive. A lower-effort encoder profile is another valid optimization, provided you recalibrate: the quality-to-score relationship can change with encoder options.
The practical rule
Use SSIMULACRA2 as a calibration instrument, not necessarily as a mandatory production step for every image. Pick a quality target that reflects how the images will actually be viewed, encode a representative sample at a few nearby settings, compare both perceptual scores and bytes, inspect failures, and lock in the lowest setting that meets your tolerance.
In one exploratory calibration, AVIF quality around 39–40 looked like a sensible place to stop. That was a decision under a specific threshold and tolerance, not a universal preset or a confirmed full-corpus benchmark. The broadly reusable lesson is simpler: when time and compute are constrained, a carefully validated fixed quality is often more practical than endlessly optimizing each individual image.