How to optimize application’s file size with free tools

Junk Master: The Quest to Glory

According to the request for our game, Junk Master: The Quest to Glory (JM2Phone codename), to change its publisher. The problem faced when trying to submit the application is the the file size itself.

I’m not sure the policy is changed since several months back from first release of the game via Windows Phone 7 Marketplace.

Anyway, it leads me to this. Find a way to reduce the file size of application to the limit set, in this case 20 MB.

The game’s first version, its size is around 23 MB. This slightly seems like a bit of easy task to only reduce a couple of megs. Nonetheless, if we optimize the game’s content in latter phase like this, we should do as much as we could.

Normally, most of the time we would set an approach and requirement for the art stuff to be created whether it’s about size, number of bit-depth, file type, etc. We then go on from that set up and continue doing work without much worrying about them anymore. This is a clean way to do things as we then have an option at the latter phase again to reduce the quality of content we created, it’s like a two way coming in from the beginning and the end point. Double the quality of optimization !

For our case, we don’t actually focus or hard set the rules or requirement for content to be created that much. So we end up with non-optimized application’s file size. Finally, the call to optimize comes in and we’re in need to make an action.

I will show you now, which solutions I choose to follow to solve this kind of problem

[Approaches taken]

I consider the situation I’m now in. The changes to be apply is out of the game schedule, and our artist is doing something else, and the last reason the game will be changed to released as Free anyway so I choose to not recreate / modify any art stuff, but will go directly to compress its size without losing much of its quality.

As observed content used in the game, there’re two major content that bulk up the most of output application file size.

  1. Images (almost .png format)
  2. Sounds (all are in .wav format)

Of course, if it’s game, the content should not be mostly in other kinds rather than the above two.

After skim observing, most of images’ file size already in small size around 10 KB - 500 KB. At first, we see this as non-problem generator. It’s really small in size already !
But what we miss is that, there’re lot of images like this with this size that if we reduce each of them, the accumulative reduced file size will added up together and reduce much of the output application’s file size !

The followings, I ran the optimize for images and see the result, then (if not below 20 MB yet) I did it again for sound effects.

[Reducing images’ file size]

I chose the tool named “pngcrush” to do the trick.
It’s purely the command line tool in which I need to create a script to make it work automatically for lots of files. If you use other platform rather than Windows, you find the frontend tool to do the work for you.

I have a limited short time to accomplish this task, so I chose the fast way with the following concerns.

  • Script created just does its core work, no extensively check for error or handle the un-expected cases. Just do the work !
  • Process only 1-level of folder hierarchy.  

For the 2nd concerning point, of course we could create script to process any level of folder hierarchy like using recursive style or customized input of level-number to act upon. The possibility is there, but I chose it to be very fast and objecitve-oriented approach as much.

I end up writing it with Perl, my old friend from the old days hacking Internet stuff.

See it and grab its source here.

[Reducing sound effects’ file size]

After try out several tools out there (mostly commercial which I don’t really want, focus on open source and free tool), I found out those don’t do a trick.

So switch back to Format Factory which supports wide range of file format, converting back and forth. This stuff suits for the task at hand !

Sound effects to be played on mobile device like Windows Phone 7, in case most of the time users won’t plug in headphone anyway. So mono is a way to go. In addition, the sampling rate is changed to 11 Hz as well.
Anyway beware of some of .wav files you have as they might not work after converted in new settings as it may already occupies a low setting format. You need to test the game again.

[Result]

I can reduce both of them as follows.

  1. Images
    Original: 13.6 MB
    Optimized: 8 MB
  2. Sound effects
    Original: 15.6 MB 
    Optimized: 2.47 MB

As notice from above, only optimization for images seems to do the trick to reduce file size. But it’s NOT. After rebuild the application again, the output’s file size is still the same. I believe it’s because of .xnb format that XNA would generate from resource.

*As of images, each of them is in small size already so it doesn’t matter for the output .xnb file for itself after building with Visual Studio 2010 express for Phone.

But not for sound effect as some of them has very large size ie. 3 MB, 5 MB. After reduced with the tool, it’s only around 100 KB - 700 KB thus the resulting .xnb file will be much smaller.

Thing to note when working with XNA framework is the application’s file size will be matter if each .xnb file is relatively small in size.

At last, I have reduce the application’s file size from 23 MB to 10 MB approximately. That’s a half of it !!

{Edited}

18 November 2011, 5.35 PM
- Changed URL to grab perl script. 

posted 6 months ago