Tutorial Others Making Your Games Smaller w/o Quality Loss - PNG, JPG, MP3 Optimization

CobraPL

NTR PALADIN
Donor
Sep 3, 2016
1,924
3,783
So, you can losslessy (unless you choose otherwise) optimize your game assets with >>> <<<- PNG, jpg, mp3 and more ! Just don't use it on Ogg Vorbis. Do not optimize or convert CMYK images or do it carefully. Don't use for RPG MAKER versions earlier than VX (VX, VX ACE, MV are OK).

Games are 5-25% smaller with this, without quality loss. JPG files 1-11%, PNG files 5-25%
It is not multi-threaded/parallel, but recurses subdirs. SO! You can just leave it optimizing for X hours, maybe in two instances. This program simply runs third-party command-line optimizers one by one to achieve best file size. Some of these 3rd party apps are single-threaded and some are multi-threaded. So I suggest leaving 2-3 instances of optimizer with work divided between them. Suggested program's options:
Options.jpg

Also, I believe that optimized PNGs are less complex internally and easier to open/scroll etc. So MAYBE your game will be faster, not only smaller.

There is PNG Gauntlet app which is obsolete to above one. File Optimizer provides same or better result in 100% cases.

Since ultra optimization takes DAYS for turbo optimization select:
General 1 / Optimization level 0
General 2 / Disable plugin mask /
Code:
pngwolf;PNGOut;TruePNG
EDIT: 30-09-2020 - I added TruePNG to exceptions, because it hangs sometimes.
-------------------------------------------------------------------------------------
EDIT 11.03.2018 - WebP Ren'Py lossless compression, images ~25-50% smaller than PNGs.
So, guys, for Ren'Py consider using WebP format instead of PNG and forget optimization thing.
with this thing you can select WebP as output, in properties force lossless encoding and batch convert all images to WebP. Put this into your Ren'Py game, edit code and enjoy. Irfanview allow viewing. I suggest optimizing only images folder, since I never tested it on alpha channel (transparency) images. On i5-8600K this shit consumes 25% of CPU, so run ~4 instances doing different part of the images.

WebP for RPGMakerMV:
DynamiteRedGames said:
The JavaScript library that RPG Maker MV uses already supports WebP image files, but the developers of RPG Maker hard coded the ".png" file extension into its ImageManager.loadBitmap() method, which you can find in rpg_managers.js One solution would be just to edit that file and replace ".png" with ".webp". This however would force you to use WebP for all of your images, including tilesets, system images, etc. I wanted a hybrid approach so that I could use both PNG and WebP files, so what I did was override the ImageManager.loadBitmap() method in a separate plugin, and added a bit of code to check if the PNG file exists. If the PNG doesn't exist, then it trys to load the file as .webp instead. Another unrelated change I made was to change RPG Maker's error handling of missing image files so that the game doesn't hard crash, but just loads a blank texture.
Native Windows WebP support codec:
-------------------------------------------------------------------------------------
For (almost) maximum ZIP compression, use latest >>> <<<
With following options (click to enlarge):
I highlighted custom options with red (you must set them manually). Note, I suggest using n+1 threads for compression and rendering for better performance. Compression ratio will be unaffected.
ZIP.jpg
NOTE: You can still use FileOptimizer for ZIP archives. 7-zip method described above is still quite fast and efficient.
-------------------------------------------------------------------------------------
- LOSSY tool for automatic Ren'Py game recompression.
Do you have a text editor that shows line numbers like notepad ++ or Atom? If you do, edit the batch file line 75 and replace "-q 85" with "- lossless -q 100 -m 6 -exact". Then it will work lossless !:)

(leave like if you think this post is helpful)
 
Last edited:

Bip

Active Member
Donor
May 4, 2017
734
2,096
And for Mac, there is the excellent open-source for jpg, png and gif.

You can set the optimisation speed, choose lossless or the level of quality for each type of files, remove or not optional chunks, strip JPEG metadata or not, etc.
Backstage, it combines:
Zopfli, pngout, optipng, advpng, pngcrush
mozjpeg, jpegoptim, jpegtran, guetzli
Gifsicle, SVGO
 
  • Like
Reactions: CobraPL

Twistty

The Happy Beaver
Respected User
Donor
Former Staff
Sep 9, 2016
4,138
37,734
Hello - I'm using 7-Zip 17.01 beta
I have an - Intel Core i7-8700K with 64GB G.SKILL TridentZ - DDR4 3600
8700K-7Z.png
What does the parameters = pass 10 do?
And are my settings ok?
Seems to work well - as far as I can tell?
Thanks
 

Cyan

Member
Jul 25, 2017
126
551
What does the parameters = pass 10 do?
And are my settings ok?
Seems to work well - as far as I can tell?
Thanks
Pass=10 means it makes 10 passes, I believe.

When images are compressed they aren't perfectly compressed. Meaning, you further compress images that have already been compressed - making them smaller than before (this has diminishing returns).

I recommend taking a single image, using pass=1, then comparing it with a pass=50 - you should see a pretty large difference in the way the image looks.

Also for the OP saying there's "no quality loss" - this is a pretty bold statement, and one I consider to be mostly false. (depends on the image)
 

CobraPL

NTR PALADIN
Donor
Sep 3, 2016
1,924
3,783
Wait, guys, what? pass=10 is maximum number and it is about 7-zip ZIP compression only. It is about making small ZIP archive. And has nothing to do with PNGs.
About threads - this affect 7-zip performance only, use n+1 threads, so with Core i7-8700K it will be 13/12.
 

Twistty

The Happy Beaver
Respected User
Donor
Former Staff
Sep 9, 2016
4,138
37,734
Can you look at my above post - do my setting look good - for compressing games?
Thanks
 

Cyan

Member
Jul 25, 2017
126
551
Wait, guys, what? pass=10 is maximum number and it is about 7-zip ZIP compression only. It is about making small ZIP archive. And has nothing to do with PNGs.
About threads - this affect 7-zip performance only, use n+1 threads, so with Core i7-8700K it will be 13/12.
Oh that's for the zip compression? I thought that was the interface for fileoptimizer - I apologize.

(The information about the file compression 'passes' was accurate, though)

Doesn't the zip compression affect the file-contents as well in that case? (Otherwise there would be no need to make multiple passes, since it should optimize as much as it can)

The idea of using n+1 threads is a little weird to me too, meaning a single thread handling 2 different threads in software, or something?

One thing is for sure, I need to look into 7zip/Fileoptimizer more :heartcoveredeyes:

Can you look at my above post - do my setting look good - for compressing games?
Thanks
@CobraPL has some different settings than you do.

Compression method is LZMA2 vs Deflate
Dictionary size is 512MB vs 32KB
Word size 258 v 256
Solid block size is 'solid' as opposed to being grayed out.

I'd try to stick as close to the recommended settings as possible.
 
Last edited:

Twistty

The Happy Beaver
Respected User
Donor
Former Staff
Sep 9, 2016
4,138
37,734
Think those setting in the OP are more for images?
Dictionary size is 512MB vs 32KB etc.
And some are determined by smaller ram sizes.
I'm using about 36 GB vs 164 MB in the OP.
I have 64GB of fairly fast ram.
Trying to figure out the best setting I can get - for making game zips.
 

Cyan

Member
Jul 25, 2017
126
551
Think those setting in the OP are more for images?
Dictionary size is 512MB vs 32KB etc.
And some are determined smaller ram sizes.
I'm using about 36GB vs
I have 64GB of fairly fast ram.
Trying to figure out the best setting I can get - for making game zips.
No the dictionary size is not the file size. The 'dictionary' in this context is a file that holds redundancy data. The larger the dictionary the more data it can hold/the smaller the compression can get. Typically unless you have an absurd amount of images/data to compress you can leave the dictionary size as default (32Mb I believe is the default?).

No harm in increasing the size though. It won't effect the compression size of your files unless your dictionary runs out of memory.

P.S. - 36Gb file compression you could probably do with a much larger than the default dictionary size, 512mb/1Gb - If you change the dictionary sizes and compress with both a small and large dictionary size, you should see a pretty large difference in the overall file sizes.
 
Last edited:
  • Like
Reactions: Twistty

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,109
14,783
What does the parameters = pass 10 do?
The answer gave by @Cyan was valid despite the fact that he misunderstood your question. No compression algorithm is optimal, so basically speaking this parameter mean that 7z will look at each file 10 times, to see if the result is better "when doing it like this instead of like that". When take in count (which I'm not sure it happen here), the higher the pass number is, the better the compression will be ; but obviously the slower it will be, especially for really big files.
But, like I said, I'm not even sure that it's took in account. I haven't heard of "pass" parameter for a compression tool since two decades at least. Now it's the "compression level" which do this. It works in the same way, by increase the number of passes according to the level of compression you look for. That while being more understandable for the user, especially if he use an interface which replace the number used as compression level by names like "fastest" or "ultra".
 
  • Like
Reactions: Twistty and Cyan

CobraPL

NTR PALADIN
Donor
Sep 3, 2016
1,924
3,783
Hello - I'm using 7-Zip 17.01 beta
I have an - Intel Core i7-8700K with 64GB G.SKILL TridentZ - DDR4 3600
View attachment 47435
What does the parameters = pass 10 do?
And are my settings ok?
Seems to work well - as far as I can tell?
Thanks
For LZMA larger word size is not always better. I used 160. 128 is/was better than 256.
@Cyan explained dictionary size quite well, BUT you must know, that for decompression you need ram in amount little higher that dictionary size.
If you make solid archive and you want to unpack 1 small file from the middle of archive, you need to unpack all files packed before that file. For 36GB archive it is overkill.
Otherwise settings are good for archiving... but...
You may use WinRAR and consider its extra repair data (reed-solomon algorithm used in CD/DVD).
 
  • Like
Reactions: T800 and Twistty

CobraPL

NTR PALADIN
Donor
Sep 3, 2016
1,924
3,783
No offense but just this is enough to tell everyone who have any idea what you are talking about that you have absolutely no idea how the size saving is done and what are the drawbacks (including what quality loss is introduced by the process you suggested).
You don't have permission to view the spoiler content. Log in or register now.

ZIP and 7-zip are 2 totally different compression methods and should not be mistaken for one another. Also you're settings recommendations in the topic might be good for you're needs but are wrong for normal everyday use. And there is no reason to use .zip instead of .7z unless you are in a hurry and need to just compress something in order to have it in one file instead of having it take less space.
Of course you have no idea what I talked about and you make bold and false statements.

7-zip can compress both to 7z and to zip. I wrote how to have higher compression ratio by using 7-zip to make zip. I know that 7z is better than ZIP, but some devs use zip for better compatibility and they are right. That is why I posted info how to make ZIPs smaller w/o breaking compatibility.

As for lossy formats like jpg and mp3 - there is data and there is protocol overhead. So mp3packer rearranges declared frame size, especially if you select forced VBR - but does not change audio data itself. I don't know how jpg optimization is done however if program author declares lossless, than I believe him.
 

Cyan

Member
Jul 25, 2017
126
551
I don't know how jpg optimization is done however if program author declares lossless, than I believe him.
The concept of a 'lossless' jpg in a sense, doesn't exist.

It's ultimately going to depend on the image itself, and how much compression you're doing.

I can take a .png from any game, put it into MS paint and convert it to JPG and it will be ~50% of the size of the PNG - ballpark. If I use a custom script I created to batch convert png -> jpg, the file sizes is about 10% of the size of the PNG (I actually wish I could increase the quality :'() - there's much more compression of the file.

I can blindly pick out which images are PNG/High Quality JPG/Low Quality JPG. I've never seen a truly lossless JPG.

Though - I still recommend using JPG (as long as its a high quality jpg) over PNG, since the quality is still pretty good. Even a 5-10% reduction in size is still worth it.
 

gue5t

Active Member
Sep 11, 2016
594
1,025
EDIT: For (almost) maximum ZIP compression, use latest >>> <<<
With following options (click to enlarge):
I highlighted custom options with red (you must set them manually). Note, I suggest using n+1 threads for compression and rendering.
View attachment 45474
In my tests using n+1 threads leads to more time taken and the exact same size archives as expected. Adding "pass=10" resulted in the exact same size as without it. Might be it needs specific type of data in order to produce results.
Using LZMA2 (7z) compression resulted in a 182MB file in comparison to the 315MB one produced with Deflate (zip).

Of course you have no idea what I talked about and you make bold and false statements.
Please quote the false statements I made, preferably with proof.

7-zip can compress both to 7z and to zip. I wrote how to have higher compression ratio by using 7-zip to make zip. I know that 7z is better than ZIP, but some devs use zip for better compatibility and they are right. That is why I posted info how to make ZIPs smaller w/o breaking compatibility.
They are not using zip files for compatibility but because it is easier for them to use the zip file provided by the engine instead of making one themselves or recompensing the zip file contents in 7z for example. And the statement that "some devs use zip for better compatibility and they are right" is totally wrong because there is no compatibility issue to begin with.

As for lossy formats like jpg and mp3 - there is data and there is protocol overhead. So mp3packer rearranges declared frame size, especially if you select forced VBR - but does not change audio data itself. I don't know how jpg optimization is done however if program author declares lossless, than I believe him.
Could you clarify which author are you believing in when he declares lossless - the one of mp3packer, the one who made FileOptimizer or the author that made one of the 5 or more programs used for optimizing JPG files in FileOptimizer?

P.S. I'll grant you that there are ways/tools to improve the file size of some file types like VBR MP3's and PNG's without quality loss but that doesn't mean that you're suggestions of using a tool that includes tools that do both types (loss-less and loose) is a good idea especially when you haven't tested the results but are willing to testify to them ...
 

gue5t

Active Member
Sep 11, 2016
594
1,025
The concept of a 'lossless' jpg in a sense, doesn't exist.

It's ultimately going to depend on the image itself, and how much compression you're doing.

I can take a .png from any game, put it into MS paint and convert it to JPG and it will be ~50% of the size of the PNG - ballpark. If I use a custom script I created to batch convert png -> jpg, the file sizes is about 10% of the size of the PNG (I actually wish I could increase the quality :'() - there's much more compression of the file.

I can blindly pick out which images are PNG/High Quality JPG/Low Quality JPG. I've never seen a truly lossless JPG.

Though - I still recommend using JPG (as long as its a high quality jpg) over PNG, since the quality is still pretty good. Even a 5-10% reduction in size is still worth it.
Let me prove you wrong, as you can see in some cases a PNG (50KB) file can be smaller and with better quality than a JPG (82KB) version of the same image. And if we use OptiPNG on the png file we get a 35KB version.
 

CobraPL

NTR PALADIN
Donor
Sep 3, 2016
1,924
3,783
1. n+1 threads, 7-zip benchmark - 6/4 ~18500MIPS, ~4/4 18000MIPS - of course it does not change compression ratio.
2. pass=10 is intended for zip compression only, does not change anything with LMZA/LZMA2
3. LZMA is ofc better than deflate, 7z is better than zip. If you make archive for enduser, who may be lamer, w/o 7-zip/winrar/etc - he still can unpack your game with os build-in zip support. Almost everything unpacks ZIP. And many people have problems with 7z/rar. This is compatibility I wrote about. Anything hard to understand?
 

CobraPL

NTR PALADIN
Donor
Sep 3, 2016
1,924
3,783
PNGs, especially very small and optimized, can be smaller than jpg's - I encountered that personally.

About jpeg lossless optimization:
View attachment 47466
 
Last edited: