Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Announcements and Chat > General Discussion

Reply
 
Thread Tools Search this Thread Display Modes
Old 15th January 2025, 02:45   #1  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
JPGs Closest to PNGs

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?
jay123210599 is offline   Reply With Quote
Old 15th January 2025, 08:13   #2  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 254
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 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 to encode the JPEGs.

Code:
:: BAT file that converts PNGs to JPGs

mkdir "out-jpegli"

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

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

)

pause

Last edited by GeoffreyA; 15th January 2025 at 13:36.
GeoffreyA is offline   Reply With Quote
Old 15th January 2025, 15:20   #3  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Quote:
Originally Posted by GeoffreyA View Post
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 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 to encode the JPEGs.

Code:
:: 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?
jay123210599 is offline   Reply With Quote
Old 15th January 2025, 15:49   #4  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 254
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.
GeoffreyA is offline   Reply With Quote
Old 17th January 2025, 08:52   #5  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 361
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)
Z2697 is online now   Reply With Quote
Old 17th January 2025, 09:30   #6  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 254
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

Last edited by GeoffreyA; 17th January 2025 at 11:53.
GeoffreyA is offline   Reply With Quote
Old 19th January 2025, 15:56   #7  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
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
jay123210599 is offline   Reply With Quote
Old 19th January 2025, 17:14   #8  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 254
Quote:
Originally Posted by jay123210599 View Post
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.

Quote:
Originally Posted by jay123210599 View Post
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:

Code:
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.
* 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.

Last edited by GeoffreyA; 19th January 2025 at 18:12.
GeoffreyA is offline   Reply With Quote
Old 19th January 2025, 19:52   #9  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Quote:
Originally Posted by GeoffreyA View Post
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:

Code:
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.
* 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
jay123210599 is offline   Reply With Quote
Old 19th January 2025, 21:37   #10  |  Link
huhn
Registered User
 
Join Date: Oct 2012
Posts: 8,287
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.
huhn is offline   Reply With Quote
Old 19th January 2025, 23:22   #11  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Quote:
Originally Posted by huhn View Post
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?
jay123210599 is offline   Reply With Quote
Old 20th January 2025, 00:08   #12  |  Link
huhn
Registered User
 
Join Date: Oct 2012
Posts: 8,287
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.
huhn is offline   Reply With Quote
Old 20th January 2025, 08:05   #13  |  Link
GeoffreyA
Registered User
 
Join Date: Jun 2024
Location: South Africa
Posts: 254
Quote:
Originally Posted by jay123210599 View Post
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

Last edited by GeoffreyA; 20th January 2025 at 08:18.
GeoffreyA is offline   Reply With Quote
Old 2nd February 2025, 19:53   #14  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Quote:
Originally Posted by huhn View Post
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?
jay123210599 is offline   Reply With Quote
Old 2nd February 2025, 19:57   #15  |  Link
huhn
Registered User
 
Join Date: Oct 2012
Posts: 8,287
same "bit rate" or same target quality is a start.
huhn is offline   Reply With Quote
Old 2nd February 2025, 21:20   #16  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Quote:
Originally Posted by huhn View Post
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?
jay123210599 is offline   Reply With Quote
Old 2nd February 2025, 21:49   #17  |  Link
huhn
Registered User
 
Join Date: Oct 2012
Posts: 8,287
i highly doubt jpegli is quality 100 GeoffreyA literally shared an image of jpegli 3 times the size
huhn is offline   Reply With Quote
Old 2nd February 2025, 22:43   #18  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Quote:
Originally Posted by huhn View Post
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
jay123210599 is offline   Reply With Quote
Old 2nd February 2025, 23:00   #19  |  Link
Z2697
Registered User
 
Join Date: Aug 2024
Posts: 361
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

Last edited by Z2697; 2nd February 2025 at 23:54.
Z2697 is online now   Reply With Quote
Old 2nd February 2025, 23:19   #20  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 324
Quote:
Originally Posted by Z2697 View Post
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?
jay123210599 is offline   Reply With Quote
Reply

Tags
image-quality, jpeg, png

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 23:26.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.