Log in

View Full Version : JPGs Closest to PNGs


jay123210599
15th January 2025, 02:45
I decided to use JPGs to save space for my computer. Which software or tools make JPGs from videos that most closely resemble or look like PNGs, ffmpeg, Shutter Encoder, VirtualDub2, Imagemagick, or something else?

GeoffreyA
15th January 2025, 08:13
Most JPEG encoders can make JPEGs that, while lossy, can't be told apart from or closely resemble lossless sources, such as PNG or BMP. Usually, a quality of 95 or upwards, along with 4:4:4 sub-sampling, does the trick. But, since you are concerned with size, Google's Jpegli (https://giannirosato.com/blog/post/jpegli/) compresses a bit better than classic JPEG encoders, using some tricks from JPEG XL to gain more compression while creating compliant JPEG files.

In short, convert the video to a sequence of PNGs. Then use cjpegli (https://github.com/libjxl/libjxl/releases) to encode the JPEGs.


:: BAT file that converts PNGs to JPGs

mkdir "out-jpegli"

for %%i in (*.png) do (

cjpegli "%%i" "out-jpegli\%%~ni.jpg"

)

pause

jay123210599
15th January 2025, 15:20
Most JPEG encoders can make JPEGs that, while lossy, can't be told apart from or closely resemble lossless sources, such as PNG or BMP. Usually, a quality of 95 or upwards, along with 4:4:4 sub-sampling, does the trick. But, since you are concerned with size, Google's Jpegli (https://giannirosato.com/blog/post/jpegli/) compresses a bit better than classic JPEG encoders, using some tricks from JPEG XL to gain more compression while creating compliant JPEG files.

In short, convert the video to a sequence of PNGs. Then use cjpegli (https://github.com/libjxl/libjxl/releases) to encode the JPEGs.


:: BAT file that converts PNGs to JPGs

mkdir "out-jpegli"

for %%i in (*.png) do (

cjpegli "%%i" "out-jpegli\%%~ni.jpg"

)

pause

Does it also produce higher quality than them?

GeoffreyA
15th January 2025, 15:49
I haven't tested quality myself, but according to Rosato's limited tests, it is on par with MozJPEG, which has, presumably, higher quality than the old reference libjpeg-turbo. If you look at the graphs, Jpegli 444 seems to have a slight edge in the higher-fidelity regime.

Z2697
17th January 2025, 08:52
I think mozjpeg just tuned some default settings of libjpeg-turbo to better suit the "web use".
Now I think that it's not a good choice for "highest quality" use... and if jpegli is similar to that, it's not a good choice too.
Luckily mozjpeg provides a flag "-revert" to revert settings to default libjpeg-turbo settings. (you'd want to enable -progressive to optimize the filesize)

(Yes, -progressive optimizes filesize better than -optimize, and they both won't change the encoding quality)

GeoffreyA
17th January 2025, 09:30
Apparently, Jpegli makes its gains through adaptive-quantisation tricks from JPEG XL, along with different quantisation matrices and calculating at higher precision.

EDIT: I put together a quick, haphazard, and very poor comparison. I couldn't find out how to disable subsampling in libjpeg-turbo CLI, not being familiar with it, so I created the JPEGs in GIMP, the settings being 4:4:4 subsampling, floating-point DCT, and optimise. Qualities were 90 and 50. For cjpegli, I left it at default, which, I believe, is using 4:4:4, along with qualities of 90 and 50. The sizes of the resulting JPEGs are different, especially so in the case of quality 50, so it's not a proper bit-for-bit comparison.

https://slow.pics/c/SMqBCK7P

jay123210599
19th January 2025, 15:56
So which type of jpg has the higher quality, then?

Also, can anyone tell the difference between the PNGs and the cjpegli/Google's Jpegli JPGs?

https://slow.pics/c/Uirx1Otf

GeoffreyA
19th January 2025, 17:14
So which type of jpg has the higher quality, then?

libjpeg-turbo may have better quality than Jpegli, but I think it's subjective and depends on what one views as noise or detail. Increasingly, at lower quality settings, Jpegli softens the picture. It's evident in that grainy shot of Naomi Watts above. Anime may paint a different story.

Also, can anyone tell the difference between the PNGs and the cjpegli/Google's Jpegli JPGs?

https://slow.pics/c/Uirx1Otf

I checked your comparison, and can tell the difference. It's very faint but there is slight quantisation noise along lines at certain places.

Here's a BAT script to try libjpeg-turbo:

mkdir "out-jpeg"

for %%i in (*.bmp) do (

cjpeg -quality 95 -optimize -progressive -sample 1x1 -outfile "out-jpeg\%%~ni.jpg" "%%i"

)

pause

* Download "libjpeg-turbo-3.1.0-vc64.exe" from here (https://github.com/libjpeg-turbo/libjpeg-turbo/releases).
* Using 7-Zip, extract the installer archive. No need to install anything.
* From the "bin" directory, copy "cjpeg.exe" and "jpeg62.dll" elsewhere to use with the BAT script.
* The source images must be BMP.

jay123210599
19th January 2025, 19:52
libjpeg-turbo may have better quality than Jpegli, but I think it's subjective and depends on what one views as noise or detail. Increasingly, at lower quality settings, Jpegli softens the picture. It's evident in that grainy shot of Naomi Watts above. Anime may paint a different story.



I checked your comparison, and can tell the difference. It's very faint but there is slight quantisation noise along lines at certain places.

Here's a BAT script to try libjpeg-turbo:

mkdir "out-jpeg"

for %%i in (*.bmp) do (

cjpeg -quality 95 -optimize -progressive -sample 1x1 -outfile "out-jpeg\%%~ni.jpg" "%%i"

)

pause

* Download "libjpeg-turbo-3.1.0-vc64.exe" from here (https://github.com/libjpeg-turbo/libjpeg-turbo/releases).
* Using 7-Zip, extract the installer archive. No need to install anything.
* From the "bin" directory, copy "cjpeg.exe" and "jpeg62.dll" elsewhere to use with the BAT script.
* The source images must be BMP.

Here's another comparison. So which JPG has the higher quality? Can anyone tell the difference between PNG and libjpeg-turbo?

https://slow.pics/c/b3UgbRzG

huhn
19th January 2025, 21:37
jpegli is just plain bad. libjpg turbo does a good job here.

this is not an optimal test for this. this is from a video file which already has similar issue which jpg will create. plus chroma scaling and dithering...

yes i can tell the difference in such a comparison but only jpegli is sticking out.

jay123210599
19th January 2025, 23:22
jpegli is just plain bad. libjpg turbo does a good job here.

this is not an optimal test for this. this is from a video file which already has similar issue which jpg will create. plus chroma scaling and dithering...

yes i can tell the difference in such a comparison but only jpegli is sticking out.

What was the difference between PNG and libjpeg-turbo?

huhn
20th January 2025, 00:08
line definition is different. you can see more noise around lines.
there is also a very tiny tint difference looks like jpg needs to do it's thing in YCbCr.

looking at the file size using jpg turbo at these settings is not worth it.
jpegli is using 1/5 to 1/10 of the bit rate that not a fair comparison.

GeoffreyA
20th January 2025, 08:05
Can anyone tell the difference between PNG and libjpeg-turbo?

https://slow.pics/c/b3UgbRzG

I am having a hard time telling the difference. If at all.

To address the concern of the file sizes being different, I made another comparison with the files from libjpeg-turbo and Jpegli being almost the same size, using the "--target_size" switch. (First, I created the JPEGs with libjpeg-turbo, then passed those sizes to cjpegli. PNGs were converted to BMP with Paint.)

https://slow.pics/c/mlv3y3nO

Another one using huhn's picture from the chroma tests: https://slow.pics/c/Ao9ROYh9

jay123210599
2nd February 2025, 19:53
looking at the file size using jpg turbo at these settings is not worth it.
jpegli is using 1/5 to 1/10 of the bit rate that not a fair comparison.

How do I make it a fair comparison, then?

huhn
2nd February 2025, 19:57
same "bit rate" or same target quality is a start.

jay123210599
2nd February 2025, 21:20
same "bit rate" or same target quality is a start.

Well, for my comparison, I converted a video into a PNG image sequence and converted 5 of its frames to JPG using cjpegli. Then I converted the same video into a BMP image sequence and convert the equivalent frames to JPG using libjpeg-turbo at quality 100.

Was there a problem with what I did?

huhn
2nd February 2025, 21:49
i highly doubt jpegli is quality 100 GeoffreyA literally shared an image of jpegli 3 times the size

jay123210599
2nd February 2025, 22:43
i highly doubt jpegli is quality 100 GeoffreyA literally shared an image of jpegli 3 times the size

Okay, I manage to set the quality to 100 for jpegli using --quality 100, and made another comparison with more images.

https://slow.pics/c/DMiPkg0u

Z2697
2nd February 2025, 23:00
JPGs closest to PNGs is lossless JPEG (yeah, it's a thing)

Edit:
There's no encoder I know of that can do it, although libjpeg does provide a lossless option it doesn't look like it's working (at least not as simple as I thought).
Even if you successfully encode one the compression ratio will be worse than PNG, I guess.

Confusing answer for confusing question, that's what you get.

All that aside, there's RGB JPEG that will be your friend to get as close as possible to PNG, because the error and precision problem of colorspace conversion will be gone. (and the file size is already dangerously close to original PNG at quality 100 and it's still lossy LOL the lossless JXL will beat it to the ground)

If you want you JPEG to be closest to the video, if the video is YUV 8bit then just use original YUV data, if the video is YUV 10bit then... it's comlicated LOL.

You want JPG close to PNG or close to video? or close to pNG which si close to video? FFS

jay123210599
2nd February 2025, 23:19
JPGs closest to PNGs is lossless JPEG (yeah, it's a thing)

How do I make lossless JPEG, then? Wait, it's just JXL, right?

Z2697
2nd February 2025, 23:46
It's not like you are really trying to save space although you said you want to save space in the begginning, if you are really trying to save space you should leave the videos as videos.

SHIFT+DELETE ALL YOUR JUNK IMAGES

jay123210599
3rd February 2025, 00:58
It's not like you are really trying to save space although you said you want to save space in the begginning, if you are really trying to save space you should leave the videos as videos.

SHIFT+DELETE ALL YOUR JUNK IMAGES

Can you answer this question, at least?

https://forum.doom9.org/showthread.php?t=186081