CompressDog

JPEG Quality 80 Is Not the Same in Every Encoder

Same 320 images, same nominal quality, two encoders. Mozjpeg produced files 13 to 14.5 percent smaller and scored 1 to 2.4 points lower.

Export a photo at quality 80 in one tool, then at quality 80 in another. The two files will not be the same size, and they will not look the same. People compare outputs by the number and get confused when the results do not match.

The number is not a scale. It is an index into a table that each encoder defines for itself.

What the number actually selects

JPEG does not store an image. It stores frequency coefficients, divided by a quantisation table before encoding. That table is what the quality setting picks. A low number selects a coarse table, a high one a fine table.

Two encoders can agree on the number and disagree on the table. The specification defines the format, not the tables, so every implementation is free to ship its own. libjpeg has interpolated the same table since the early nineties. Mozjpeg ships that one plus a second, tuned set, and picks between them based on how aggressive the setting is. Which means "quality 80" is a promise about a look-up, not a promise about how the file will look.

Four points on the same images

We encoded the same 320 photos twice: once with Pillow's libjpeg, once with the mozjpeg build this site runs. Both at 4:4:4 chroma, both scored against the same decoded original with SSIMULACRA2.

qualitylibjpeg KBlibjpeg scoremozjpeg KBmozjpeg scoresizescore
50102.669.7487.767.38−14.5%−2.36
60117.473.02101.270.82−13.8%−2.20
70139.677.03121.275.05−13.2%−1.98

| 90 | 261.0 | 87.84 | 225.4 | 86.74 | −13.6% | −1.10 | (The site's quality 80 was not part of the earlier sweeps these numbers come from, so that row has no mozjpeg figure. Everything above is measured, not interpolated.)

Two things are worth pulling out.

The size difference is stable. Between 13 and 14.5 percent across the whole range. If you switch from libjpeg to mozjpeg and change nothing else, your files get about an eighth smaller.

The quality cost is not stable. It falls from 2.36 points at quality 50 to 1.10 at quality 90. Same size advantage, half the damage.

Where the gap closes

At quality 90 the tuned tables and the baseline tables in mozjpeg are much closer in aggressiveness, so the encoder has less room to be clever. The files it produces are still smaller, but it is spending fewer quality points to get there.

At quality 50 the difference is larger in every direction. Coarse tables are where the tuned set earns its keep, and also where it does the most visible damage. If you are pushing a file down to the quality floor, the encoder you use matters more than it does at quality 90.

This is the same crossover we found when comparing the two table sets inside mozjpeg, just viewed from a different angle.

If you switch tools

Re-pick the number. Do not carry "quality 82" from one application to another and expect the same result, because 13 percent of the file size and up to 2.4 points sit between them.

Two habits make this cheap. Compare at a fixed output size rather than a fixed quality number, which is what the target-size workflow does. Or keep one tool and learn its number, which is what most people do in practice and is fine.

The failure mode to avoid is trusting a number that came from a different encoder, then being puzzled that the file is either much bigger or noticeably worse.

Running it yourself

tools/measure-quality-scale.py. It needs Pillow for the encoding and ssimulacra2 on the path. About two minutes for 320 images at five settings. The raw per-image numbers are downloadable.

Encoder versions matter here. Mozjpeg's tables changed over its history, and libjpeg has forks with their own defaults. A different build could shift these numbers by a point or so. That does not change the shape of the result, which is that the number is not portable, but it does mean you should not read the exact figures as universal constants.

One collection of images, already-compressed sources, 768 px on the long edge. If your own files behave differently, the about page has the address.

Sources

Open the compressor