mozjpeg icon indicating copy to clipboard operation
mozjpeg copied to clipboard

Support "automatic quality level"

Open sicking opened this issue 11 years ago • 6 comments

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.

sicking avatar Oct 10 '14 00:10 sicking

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

danielgtaylor avatar Oct 10 '14 01:10 danielgtaylor

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.

kornelski avatar Oct 10 '14 02:10 kornelski

Perhaps #84 is also a related issue: automatic quality level boils down to quantization tables optimized for an individual image.

kornelski avatar Oct 10 '14 04:10 kornelski

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.

danielgtaylor avatar Oct 10 '14 17:10 danielgtaylor

Target display DPI could also provide easy heuristics, e.g. Retina/xhdpi displays could use a much lower quality encoding without perceptible artifacts.

phraktle avatar Dec 31 '14 06:12 phraktle

any update on automatic quality level ?

bydbest avatar Jun 04 '17 05:06 bydbest