Optimizing JPEG to WEBP conversion

2,250 views
Skip to first unread message

Joe Duarte

unread,
Aug 7, 2015, 12:21:26 AM8/7/15
to WebP Discussion
Hi team,

I've been trying to convert JPEG photos to WEBP for a website. cwebp doubles the size of the files (typically from ≈ 4MB to ≈ 8 MB). Digging into this, I've learned that converting from one lossy format to another often increases the file size. Since converting JPEGs seems to be a canonical use case, is there a guide or tips for the right settings? I initially used q 100 lossless. The cwebp guide says 100 will result in maximum compression for lossless. Taking it down to lossy q 90 still results in massive file size increase.

If the answer is that the output webp quality setting has to equal the jpeg's quality setting, or be less than the jpeg's quality setting, then I have some subsidiary questions: 1) How do I determine the JPEG's quality setting?  2) Are these quality settings commensurable across JPEG and WEBP? (Is this a universal construct in image formats?)  3) Does matching the quality setting result in new loss of image data? e.g. 75 JPEG to 75 WEBP. I would've assumed that WEBP is just more efficiently packing the JPEG's data. If it incurs another iteration of image data loss, then I'd have to weigh whether it's appropriate to use lossy webp, given archival concerns. If so, what is lossless WEBP for? Is it mainly for converting RAW or DNG images?

Thanks much,

Joe Duarte

Urvang Joshi

unread,
Aug 7, 2015, 2:06:10 AM8/7/15
to WebP Discussion
Hi Joe,
What exact 'cwebp' commandline are you using?
Do you mind sharing one of the JPEG images, which, on converting to WebP, doubles in file size?

--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webp-discuss...@webmproject.org.
To post to this group, send email to webp-d...@webmproject.org.
Visit this group at http://groups.google.com/a/webmproject.org/group/webp-discuss/.
For more options, visit https://groups.google.com/a/webmproject.org/d/optout.

Jyrki Alakuijala

unread,
Aug 7, 2015, 4:17:21 AM8/7/15
to webp-d...@webmproject.org
On Fri, Aug 7, 2015 at 6:21 AM, Joe Duarte <songof...@gmail.com> wrote:
If so, what is lossless WEBP for? Is it mainly for converting RAW or DNG images?

I designed and optimized the lossless WebP format to store images that we have used the PNG format in the past. The lossless format and the current lossless encoder is not particularly optimized for recompressing JPEGs losslessly.

You may have a higher chance of succeeding in lossless recompression if your original JPEG source is of extremely high quality (YUV444 and quality 100). This is because the lossy JPEG compression adds ringing and 8x8-block border artefacts that can actually require more bytes when compressed with WebP lossless.

Pascal Massimino

unread,
Aug 17, 2015, 7:18:12 PM8/17/15
to WebP Discussion
Hi Joe,

On Thu, Aug 6, 2015 at 9:21 PM, Joe Duarte <songof...@gmail.com> wrote:
Hi team,

I've been trying to convert JPEG photos to WEBP for a website. cwebp doubles the size of the files (typically from ≈ 4MB to ≈ 8 MB). Digging into this, I've learned that converting from one lossy format to another often increases the file size.

That's true for WebP but also JPEG: using q=100 is pretty much guarantied to make the file large for most input. You'd pretty much be using more bits to describe the same input information.

Since converting JPEGs seems to be a canonical use case, is there a guide or tips for the right settings? I initially used q 100 lossless. The cwebp guide says 100 will result in maximum compression for lossless.

I think you meant: maximum quality,  not compression.

Taking it down to lossy q 90 still results in massive file size increase.


Yes, JPEG files are using encoded with quality q~=80, depending on the source (sometimes more, sometimes less).
 
If the answer is that the output webp quality setting has to equal the jpeg's quality setting, or be less than the jpeg's quality setting, then I have some subsidiary questions: 1) How do I determine the JPEG's quality setting?

Some jpeg-sniffer programs can do that. For instance, ImageMagick's 'identify' gives a lot of information:

identify -verbose test.jpg | grep Quality

(note: -verbose must come first. And it's "Quality", with a capital Q).
 
 2) Are these quality settings commensurable across JPEG and WEBP? (Is this a universal construct in image formats?)  

Not necessarily. But a '-jpeg_like' option was added to cwebp to try to make the two quality scales match in size (WebP being visually less distorted *if* the source
is uncompressed enough).

3) Does matching the quality setting result in new loss of image data? e.g. 75 JPEG to 75 WEBP. I would've assumed that WEBP is just more efficiently packing the JPEG's data.

Yes indeed. Using the same -q value will typically results is a smaller file size for WebP, except maybe for very high quality (95+), where WebP will struggle a lot to reproduce some JPEG-friendly coefficient values.

If it incurs another iteration of image data loss, then I'd have to weigh whether it's appropriate to use lossy webp, given archival concerns. If so, what is lossless WEBP for? Is it mainly for converting RAW or DNG images?

Hope it helps,

skal/

Joe Duarte

unread,
Aug 19, 2015, 12:15:56 AM8/19/15
to webp-d...@webmproject.org
Hi Urvang,

I've attached two sample jpeg images, the two webp output files, and a png screenshot of the commands I used.

It more than doubled the size of the 4.4 MB jpeg (filename: Shoes.jpg)

It increased the size of the 833 KB jpeg by 5.1x (filename: DukeChapel.jpg)

Let me if the attachments don't come through. The total size is close to 20 MB.

Cheers,

Joe Duarte

DukeChapel.jpg
DukeChapel.webp
Shoes.JPG
Shoes.webp
2015-08-18_21-13-42.png

Joe Duarte

unread,
Aug 19, 2015, 12:21:58 AM8/19/15
to webp-d...@webmproject.org
Hi Pascal,

Thanks for your answers! On the issue of q 100, here is the text from your webp documentation page:

"In case of lossless compression (specified by the -lossless option), a small factor enables faster compression speed, but produces a larger file. Maximum compression is achieved by using a value of 100."

​It says 100 achieves maximum compression, not quality. I assume quality is held constant for lossless.​ Is the page in error? It's here: https://developers.google.com/speed/webp/docs/cwebp

(In the "-q float" section.)

Cheers,

Joe Duarte


JOZIKus

unread,
Aug 19, 2015, 6:41:35 AM8/19/15
to webp-d...@webmproject.org
Why are You using "lossless"? Lossless should be used against PNGs not JPEGs! Drop the lossless parameter and try reducing quality to about 80. :)

Pascal Massimino

unread,
Aug 19, 2015, 11:23:00 AM8/19/15
to WebP Discussion
Hi,

On Tue, Aug 18, 2015 at 9:21 PM, Joe Duarte <songof...@gmail.com> wrote:
Hi Pascal,

Thanks for your answers! On the issue of q 100, here is the text from your webp documentation page:

"In case of lossless compression (specified by the -lossless option), a small factor enables faster compression speed, but produces a larger file. Maximum compression is achieved by using a value of 100."

​It says 100 achieves maximum compression, not quality. I assume quality is held constant for lossless.​ Is the page in error? It's here: https://developers.google.com/speed/webp/docs/cwebp


oh, indeed. You are right: i totally missed that you are using lossless compression. In this case, yes, -q 100 is "maximum effort to achieve lower file size".

Now, it's no surprise that you get very large file trying to preserve the JPEG source exactly. It's pretty much like converting JPEG to PNG, it takes a lot of bytes.
There's very few chances that lossless recompression will produce a smaller file when starting from a lossy source format like JPEG, except some rare exceptions (like low color or black-and-white input).

skal/

Urvang Joshi

unread,
Aug 19, 2015, 11:50:14 AM8/19/15
to webp-d...@webmproject.org
Hi Joe,
As JOZIKus and Pascal already explained, you should be converting JPEGs to lossy WebP (not lossless). Also, when converting a JPEG image, you can try to match WebP and JPEG quality scale using '-jpeg_like' option.

So, the command-line would be:
cwebp <input.jpg> -jpeg_like -o <output.webp>

For the images you posted, attached are the WebP images you would get with these commands.

dukechapel.webp: 501 KB (original JPEG was 834 KB)
shoes.webp: 984 KB (original JPEG was 4.4 MB)

dukechapel.jpeg_like.lossy.webp

shoes.jpeg_like.lossy.webp

Zeyad Ahmed

unread,
Jul 10, 2020, 1:00:57 PM7/10/20
to WebP Discussion, pascal.m...@gmail.com
Sorry for replying to a quite old question, but I am in the same situation as Joe was, I also tried to search around for this information with no luck, so my question is does converting JPEG to WEBP using lossy compression and with "jpeg_like" switch (to match the same quality of the JPEG compression) will guarantee there is no further loss in the image data? Because generally converting from one lossy format to another lossy one will have image data loss during the compression, does this apply to JPEF to WEBP as well? Or it's like what Joe said: "I would've assumed that WEBP is just more efficiently packing the JPEG's data"

James Zern

unread,
Jul 13, 2020, 5:01:37 PM7/13/20
to WebP Discussion
Hi Zeyad,

On Fri, Jul 10, 2020 at 10:00 AM Zeyad Ahmed <aze...@gmail.com> wrote:
Sorry for replying to a quite old question, but I am in the same situation as Joe was, I also tried to search around for this information with no luck, so my question is does converting JPEG to WEBP using lossy compression and with "jpeg_like" switch (to match the same quality of the JPEG compression) will guarantee there is no further loss in the image data?

No, it will depend on the quality setting you choose for webp and what quality the jpeg was encoded at. There will still be differences between the two even at high quality, though. WebP offers lossless compression, but that will most often result in a larger file size when transcoding jpegs and isn't likely what you are looking for here. For dealing with larger amounts of images we do offer options in cwebp like -psnr and -size [1] (see -pass also) to control the final distortion or file size.

 
Because generally converting from one lossy format to another lossy one will have image data loss during the compression, does this apply to JPEF to WEBP as well? Or it's like what Joe said: "I would've assumed that WEBP is just more efficiently packing the JPEG's data"


On Tuesday, August 18, 2015 at 1:18:12 AM UTC+2 pascal.m...@gmail.com wrote:
Hi Joe,

On Thu, Aug 6, 2015 at 9:21 PM, Joe Duarte <songof...@gmail.com> wrote:
Hi team,

I've been trying to convert JPEG photos to WEBP for a website. cwebp doubles the size of the files (typically from ≈ 4MB to ≈ 8 MB). Digging into this, I've learned that converting from one lossy format to another often increases the file size.

That's true for WebP but also JPEG: using q=100 is pretty much guarantied to make the file large for most input. You'd pretty much be using more bits to describe the same input information.

Since converting JPEGs seems to be a canonical use case, is there a guide or tips for the right settings? I initially used q 100 lossless. The cwebp guide says 100 will result in maximum compression for lossless.

I think you meant: maximum quality,  not compression.

Taking it down to lossy q 90 still results in massive file size increase.


Yes, JPEG files are using encoded with quality q~=80, depending on the source (sometimes more, sometimes less).
 
If the answer is that the output webp quality setting has to equal the jpeg's quality setting, or be less than the jpeg's quality setting, then I have some subsidiary questions: 1) How do I determine the JPEG's quality setting?

Some jpeg-sniffer programs can do that. For instance, ImageMagick's 'identify' gives a lot of information:

identify -verbose test.jpg | grep Quality

(note: -verbose must come first. And it's "Quality", with a capital Q).
 
 2) Are these quality settings commensurable across JPEG and WEBP? (Is this a universal construct in image formats?)  

Not necessarily. But a '-jpeg_like' option was added to cwebp to try to make the two quality scales match in size (WebP being visually less distorted *if* the source
is uncompressed enough).

3) Does matching the quality setting result in new loss of image data? e.g. 75 JPEG to 75 WEBP. I would've assumed that WEBP is just more efficiently packing the JPEG's data.

Yes indeed. Using the same -q value will typically results is a smaller file size for WebP, except maybe for very high quality (95+), where WebP will struggle a lot to reproduce some JPEG-friendly coefficient values.

If it incurs another iteration of image data loss, then I'd have to weigh whether it's appropriate to use lossy webp, given archival concerns. If so, what is lossless WEBP for? Is it mainly for converting RAW or DNG images?

Hope it helps,

skal/

--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webp-discuss...@webmproject.org.
Reply all
Reply to author
Forward
0 new messages