Monday, September 19, 2011

Use 'ima4' compression to reduce CAF file size during conversion

While playing with sound, the most frequently encountered problem will be file format conversion.

Apple has this Technical Q&A QA1534 which talks about how to create .CAF files from .AIF files using "afconvert" utility.

If you searched on the net you can also find lots of info about converting MP3/WAV to CAF files.

However I couldn't find much information about how to reduce the .CAF file size. Of course you can reduce the bit rate, but that would more or less reduced the quality of the .CAF file.

Later I found this discussion about OpenAL file formats in Apple Support Communities which talks about "IMA4" compression - which is something I never heard before.

I did a few simple experiments as below, converting same WAV file to CAF using different bit rate and "LEI16", "IMA4" data format:

afconvert -f caff -d LEI16@44100 -c 1 correct01.wav correct01_44100.caf
afconvert -f caff -d LEI16@128000 -c 1 correct01.wav correct01_128000.caf
afconvert -f caff -d 'ima4' -c 1 correct01.wav correct01_ima4.caf
afconvert -f caff -d 'ima4@44100' -c 1 correct01.wav correct01_ima4_44100.caf
afconvert -f caff -d 'ima4@128000' -c 1 correct01.wav correct01_ima4_128000.caf


The result file size is as below:


With same 44100 bit rate, using IMA4 compression reduced the file size from 313 KB to 86 KB, about 73% smaller! With the 12800 bit rate, the result is also similar. Don't know what's the default bit rate when using "-d 'ima4'" without any bit rate, the result file of 19KB is the smallest.

I guess for small, short sound effect files, should be ok with lower bit rate as it dramatically reduced the file size, but for looping or more important music, you might want to play around with the numbers a bit to get the best balance/result.

Hope you find this information helpful. And if you are aware of any better/other compression or whatever method to further reduce file size (hopefully without loosing too much sound quality?) please let me know!!

0 comments:

Post a Comment