mozjpeg
mozjpeg copied to clipboard
Support "automatic quality level"
At EdgeConf the other week it was pointed out that when people encode JPEG images they often pick a fairly arbitrary quality level. Generally one based on habit than one that makes the given image look good.
It would be good if mozjpeg could automate this and automatically pick a quality level that results in a good tradeoff between quality and size for the given picture. Or at the very least provide better defaults.
I'm not sure really what algorithm to use to make this selection. But it would probably both involve looking at when the error rate starts going up, as well as when there starts being diminishing returns in the file size.
I believe this is a duplicate of #12, and for algorithms you can take a look at jpeg-recompress, which uses mozjpeg in its latest version to compress images. It's possible to use it like cjpeg:
jpeg-recompress --ppm input.ppm output.jpg
# Or using stdin
cat input.ppm | jpeg-recompress --ppm - output.jpg
Imgmin (mentioned in #12) tries to choose JPEG quality based on MSE & other heuristics.
I think that approach may work in general and could be more performant if was integrated with the encoder.
For example imgmin only needs to test distortion, but doesn't look at file size. This could be done quicker by just doing DCT & IDCT and skipping coding entirely.
Perhaps #84 is also a related issue: automatic quality level boils down to quantization tables optimized for an individual image.
It would be nice if skipping coding were exposed as an option or otherwise simple to do. That way programs using mozjpeg can implement their own comparison methods (jpeg-recompress supports SSIM, MS-SSIM, PSNR, and SmallFry (similar to BBCQ) for example). At the moment I am wasting a significant amount of time doing the full JPEG encode and decode before I can compare the images.
Target display DPI could also provide easy heuristics, e.g. Retina/xhdpi displays could use a much lower quality encoding without perceptible artifacts.
any update on automatic quality level ?