Using qaac under Linux...

This is a page that aims to promote and facilitate the use of the great AAC/ALAC commandline encoder qaac under a Linux environment. qaac is an application that uses Apple AAC to produce the best AAC quality available today which is otherwise not available in a Linux environment. This page provides a simple copy and paste approach to an installation that can otherwise be somewhat complex. As well I have included instructions on basic command line usage so once the installation is complete, Gentle Reader, you can launch straight into encoding...

If this page helps anyone to get their first usage of this great command line encoder I will be very happy. I have revisited this page in March 2021 and followed all of the steps on a fresh Slackware multilib install and it all worked beautifully, so hopefully it will work just as well on your own system!

Installation...

One fundamental fact of qaac is that it is a native Windows application so under Linux you will need to install the Wine package appropriate for your distro. You will also need both the 7z file archiver and the unzip utility. If you are running Ubuntu for example you will need something like the following:

sudo apt-get install wine p7zip-full unzip

It would be wise to now spend a little quality time with the application winecfg and get your Wine installation running exactly as you would like. From here you will need both the qaac application zip file as well as a modern copy of iTunes from which we will extract the appropriate dll files that qaac needs. The following single command makes a build directory, downloads and then unzips qaac to the appropriate location. The syntax presupposes that your wine prefix is the default ~/.wine, if it is not you will need to adjust the output path:

mkdir $HOME/qaac_build && cd $HOME/qaac_build && \
wget https://github.com/nu774/qaac/releases/download/v2.71/qaac_2.71.zip && \
unzip -j qaac_2.71.zip 'qaac_2.71/x86/*' -d ~/.wine/drive_c/qaac/

The next single command downloads the 195MiB 32bit iTunes installation file and extracts the Apple Application Support msi file needed by qaac:

cd $HOME/qaac_build && \
wget \
https://secure-appldnld.apple.com/itunes12/041-02279-20180912-24D8EE3A-AC7A-11E8-BE19-C36F1B1141A5/iTunesSetup.exe && \
7z e -y iTunesSetup.exe AppleApplicationSupport.msi

Rather than fully install the Apple Installation Support msi file we are going to extract what we need from it. The author of qaac has created a very nice Windows batch file called makeportable.bat which extracts all the relevant dlls and packages them nicely (under Windows) and I have shamelessly followed his example with the following native Linux syntax which extracts the required dll files, renames them appropriately and then moves them to the qaac directory. Again this is a single command that can be copied and pasted into your Terminal window:

cd $HOME/qaac_build && \
7z e -y AppleApplicationSupport.msi \
     -i'!*AppleApplicationSupport_ASL.dll' \
     -i'!*AppleApplicationSupport_CoreAudioToolbox.dll' \
     -i'!*AppleApplicationSupport_CoreFoundation.dll' \
     -i'!*AppleApplicationSupport_icudt*.dll' \
     -i'!*AppleApplicationSupport_libdispatch.dll' \
     -i'!*AppleApplicationSupport_libicu*.dll' \
     -i'!*AppleApplicationSupport_objc.dll' \
     -i'!F_CENTRAL_msvc?100*' && \
for j in *.dll; do mv -v $j $(echo $j | sed 's/AppleApplicationSupport_//g'); done && \
for j in F_CENTRAL_msvcr100*; do mv -v "$j" msvcr100.dll; done && \
for j in F_CENTRAL_msvcp100*; do mv -v "$j" msvcp100.dll; done && \
mv -v *.dll ~/.wine/drive_c/qaac/ && \
rm -v AppleApplicationSupport.msi

Now that is pretty cool I think and I thank the qaac developer for showing the way here! Now to extend qaac a little in terms of media file types it can read directly. The developer has carefully detailed the individual steps required on the qaac installation page but for you, Gentle Reader, I have already assembled the required dlls and placed them in a download section of this website. The qaac developer has already done this for 64bit systems, my offerings are for the 32bit Wine installation. The following is a single command:

cd $HOME/qaac_build && \
wget http://www.andrews-corner.org/downloads/x32DLLs_20161112.zip && \
unzip -j x32DLLs_20161112.zip 'x32DLLs_20161112/*' -d ~/.wine/drive_c/qaac/

And now your copy of qaac can take take several new import formats on top of those supported by the Apple's core audio framework Core Audio! All that remains now is to make an alias in either your ~/.bashrc file or in the usual file that you use for such aliases, so that you can run qaac (and the Open Source refalac) more easily. I include here as well a line to turn off some painful Wine debugging messages:

# So I can launch qaac or refalac with a single command:
alias qaac='wine ~/.wine/drive_c/qaac/qaac.exe'
alias refalac='wine ~/.wine/drive_c/qaac/refalac.exe'

# Turn off a few pesky warnings (well, actually all of them!):
export WINEDEBUG=-all

And now you should be able to run qaac directly from the commandline (once you have sourced your ~/.bashrc file appropriately of course) and a good test is to run the following:

andrew@ilium~$ qaac --check
qaac 2.71, CoreAudioToolbox 7.10.9.0
libsoxconvolver 0.1.0
libsoxr-0.1.3
libsndfile-1.0.25
libFLAC 1.3.1
wavpackdll 5.0.0
tak_deco_lib 2.3.0 compatible
andrew@ilium~$  

All done and when I repeated these steps in August 2019 with a fast computer and a good broadband speed the whole installation took only 5 minutes! I believe this is the most current version of Core Audio from Apple (as of January 2019), remembering that Apple AAC is still scored by HydrogenAudio the best AAC encoder available today. Next I will describe the command line usage of qaac and show how to import multiple flac files with a bash 'for' loop:

Commandline usage...

Before launching straight into the command line usage of qaac let us clear up some confusion about AAC encoding in general. Currently (August 2019) for our purposes there are 4 recognised forms of AAC encoding available for Linux:

  1. AAC-LC: Otherwise known as "MPEG AAC Low Complexity", this is AAC encoding which produces excellent sound at bitrates up to 256 kbit/s per channel and sampling rates from 8 to 96 kHz. This is the form of AAC that most will use for computer playback, use in iTunes, mobile phones etc. qaac produces AAC-LC files.
  2. HE-AAC: Otherwise known as "High Efficiency AAC". This is AAC encoding which produces excellent encoding at lower bitrates: 48 to 64 kbit/s Stereo and sampling rate 24 to 96 kHz. This is specifically designed for low bitrate streaming from TV or radio and can be used by those keen to have quality files at low bitrates. It uses AAC-LC and adds in a technique called Spectral band replication (SBR). Also known as HE-AAC v1. qaac produces HE-AAC files.
  3. HE-AAC v2: Otherwise known as "High Efficiency AAC version 2". This is the successor to the original HE-AAC and aims to produce quality AAC at 24 to 32 kbit/s Stereo and sampling rate 24 to 96 kHz. It adds in a technique called Parametric Stereo (PS). qaac does not produce HE-AAC v2 files.
  4. xHE-AAC: Otherwise known as "Extended High Efficiency AAC", or some may even use the more umbrella term Unified Speech and Audio Coding (USAC). This is the most recent addition to the AAC family and it aims to unify speech and music encoding primarily for broadcast with high quality encoding at low bitrates. There is now an encoder: exhale which produces playable xHE-AAC files under Linux. Exciting times!

qaac also has the added bonus of producing Apple Lossless Audio Codec (alac) files by either using qaac itself or by using "refalac", an encoder based on the Open Source reference implementation of alac released by Apple. The biggest advantage of refalac is that it does not require any extra Apple libraries to function. Now to demonstrate some of the commandline requirements for each output of qaac, I use my favourite wav file to demonstrate and you are welcome to download and use it as well for testing:

wget samples.mplayerhq.hu/A-codecs/lossless/luckynight.wav.bz2 && \
bzip2 -dkv luckynight.wav.bz2

Consider as well looking at the words of the qaac developer on the subject of encoding with qaac.

AAC-LC...

If you are not completely sure where you AAC files will end up being used then AAC Low Complexity (AAC-LC) is what you probably should be using. My own practice is to use qaac's True Variable Bitrate (tvbr) option and at the very least this will make a good start in your own exploration of qaac. The tvbr settings take an integer betwen 0-127 which map to the following settings. I have constructed a fairly crude test with a sample wav file to show what the average bitrate will be:

AAC True VBR mode
tvbr setting 0 9 18 27 36 45 54 63 73 82 91 100 109 118 127
Overall Bitrate in kbps 44.4 51.2 58.0 65.7 71.5 87.6 102 114 131 150 190 232 269 305 346
Testing with this file: qaac --tvbr <n> luckynight.wav

But experiment a little and see what sounds better on your system and go with that rather than simply following the bitrate numbers alone. To convert our input file to AAC-LC and also add in some meta data you should try something like the following:

qaac --tvbr 100 --quality 2 --verbose \
     --band "Treasure Quest Soundtrack" \
     --artist "Jody Marie Gnant" \
     --track "9" \
     --title "Lucky Night" \
     --genre "Soundtrack" \
     --date "1995" \
     --comment "Testing qaac encoding..." \
     -o luckynight.m4a \
     luckynight.wav

That is usually enough for me but there are many more options that I will leave for you, Gentle Reader, to explore. Have a look at qaac --help to then explore the options for Constrained Variable Bitrate mode (CVBR), Average Bitrate mode (ABR) and Constant Bitrate Mode (CBR) encoding. But now to the exciting world of High Efficiency AAC encoding with qaac!

HE-AAC...

For the most part you will not need High-Efficiency AAC (HE-AAC) encoding as AAC-LC would normally be adequate for most playback needs. However if you would like to produce high quality, low bitrate AAC files this is the mode you are after. To produce a decent quality HE-AAC file with qaac, as well as adding in some meta data, something like the following should suffice:

qaac --cvbr 48k --he --quality 2 --ignorelength --verbose \
     --band "Treasure Quest Soundtrack" \
     --artist "Jody Marie Gnant" \
     --track "9" \
     --title "Lucky Night" \
     --genre "Soundtrack" \
     --date "1995" \
     --comment "Testing qaac encoding..." \
     -o luckynight.m4a \
     luckynight.wav

There are many more options to explore with HE-AAC and I encourage you again to look at qaac --help and both read and experiment! Now to have a look at qaac and ALAC encoding.

Apple Lossless Audio Codec (ALAC)...

Encoding with alac under qaac is easy, in part because there are not that many commandline options to worry about! Perhaps the biggest choice is whether to use the closed source CoreAudio or the Open Source refalac. To use the CoreAudio version simply run the following to encode to alac as well as adding in some meta tags:

qaac --alac --verbose \
     --band "Treasure Quest Soundtrack" \
     --artist "Jody Marie Gnant" \
     --track "9" \
     --title "Lucky Night" \
     --genre "Soundtrack" \
     --date "1995" \
     --comment "Testing qaac encoding..." \
     -o luckynight.m4a \
     luckynight.wav

It really could not be much easier could it? If you would like to go full Open Source simply substitute refalac for qaac in the above commandline and you will not only still have a great encode but you will have a slight self-righteous glow as well!

Importing from other formats..

If you have loaded the extra 32bit dlls you will now have the ability to import from multiple other audio formats as well as wav. On my own system I have used this import facility with several very large collections of flac audio files which I have converted to alac and suitably tagged using the following code snippet:

mkdir converted && \
for f in *.flac; do
   title=$(metaflac --show-tag=title "$f" | cut -d '=' -f 2)
   artist=$(metaflac --show-tag=artist "$f" | cut -d '=' -f 2)
   album=$(metaflac --show-tag=album "$f" | cut -d '=' -f 2)
   date=$(metaflac --show-tag=date "$f" | cut -d '=' -f 2)
   track=$(metaflac --show-tag=tracknumber "$f" | cut -d '=' -f 2)
   genre=$(metaflac --show-tag=genre "$f" | cut -d '=' -f 2)
   wine ~/.wine/drive_c/qaac/qaac.exe --alac --verbose \
   --title "$title" --artist "$artist" --album "$album" \
   --date "$date" --track "$track" --genre "$genre" --comment "" \
   --artwork cover.jpg \
  "$f" -o converted/"${f%.flac}.m4a"
done

Note the embedding here for a suitable cover art image. Works very nicely on my system and then the resulting files are then ready for playback with a nice piece of album art showing! I have just now tested this syntax and this conversion and I can tell you Gentle Reader that I love seeing a nice command line running so beautifully!

Importing unusual formats...

Courtesy of the CoreAudio AudioFile interface as well as courtesy of the extra 32bit dlls there are not that many files that qaac cannot import and convert. However these files do exist and fortunately there is a nice 'work around' for these files using FFmpeg. I give an example here with one of those pesky Windows Audio Lossless file which can be so difficult to work with:

ffmpeg -i luckynight.wma -f wav - | \
qaac --cvbr 48k --he --quality 2 --ignorelength --verbose \
     --band "Treasure Quest Soundtrack" \
     --artist "Jody Marie Gnant" \
     --track "9" \
     --title "Lucky Night" \
     --genre "Soundtrack" \
     --date "1995" \
     --comment "Testing qaac encoding..." \
     -o luckynight.m4a \
     -

And there, we have tamed a Windows Lossless Audio file and safely rendered it to a more conventional HE-AAC file! If you use this command line don't forget to keep the trailing '-' in place otherwise it will not work at all. My suspicion is that if the power of FFmpeg is harnessed in this way there will be no audio file that cannot be converted using qaac. Please let me know if this is an empty statement by using the email link at the base of this page...

And in conclusion...

This page represents my own exploration of the great commandline encoder qaac and my efforts to make it both easy to install and use under Linux. I hope that your own exploration of this great encoder will take you even further and that you thoroughly enjoy the quality audio that you will undoubtedly produce!! Please feel free to contact me with any errors of fact that you have found on this page, any errors of opinion will probably remain uncorrected. In the meantime I am having a great time exploring Linux and the amazing command line, what about you?