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 August 2019 and followed all of the steps on a fresh Slackware install and it all worked beautifully, so hopefully it will work just as well on your own system!

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...

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.69/qaac_2.69.zip && \ unzip -j qaac_2.69.zip 'qaac_2.69/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.69, 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:

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. 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. 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. 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 follow the numbers only. To 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 and 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 and AAC-LC should normally be enough. 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 something like the following will suffice:

qaac --cvbr 48k --he --quality 2 --verbose luckynight.wav

qaac will not produce HE-AAC v2 files unfortunately and for this you will need to go to fdkaac. However I think you will be very pleasantly suprised with the sound quality of qaac's HE-AAC (version 1) files. A final note in this section: if you find a file that qaac will not natively import (and to tell the truth there are actually not too many of these courtesy of the CoreAudio AudioFile interface) it is possible to use FFmpeg to achieve this. I give an example here, complete with tagging options, with this Windows Audio Lossless file:

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 \ -

There are many more options to explore with HE-AAC and I encourage you 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 CoreAudio or the Open Source refalac. To use CoreAudio simply run the following:

qaac --alac luckynight.wav

It really could not be much easier could it? If you would like to go Open Source simply substitute refalac for qaac in the above commandline and you will have a great encode and slight self-righteous glow as well! For the sake of completion I give here as well the appropriate syntax to encode as well as tag the little demonstration file:

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

Using a bash 'for' loop it is also possible to import multiple files and then use qaac to convert the import files, this is documented below:

Importing flacs with a 'for' loop..

If you have loaded the extra 32bit dlls that enable import from multiple formats as well as wav you can also convert flac files, which are relatively common online. On my own system I have used this import facility for several very large collections of flac audio files which I have converted to alac 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!

Using abcde and qaac...

I am breaking one of my own resolutions here to make a small note and also give an example of usage of qaac with abcde. It is perhaps not a great thing to own up to but I added support to abcde for both wine and qaac when I was moonlighting as an abcde developer. However I let all of this go when I built a computer without an optical drive; brashly declaring that the time of the Audio CD, DVD and BluRay was now over. However the purchase of an external, USB 3.0 BluRay drive and a request from RM has meant that I have retested abcde with qaac and added an updated version of my old conf file here. Note that this single config file, with some appropriate commenting and uncommenting will serve to produce AAC files using qaac as well as ALAC files with either qaac or refalac:

# -----------------$HOME/.abcde.conf----------------- # # # A sample configuration file to convert music cds to # either AAC or ALAC using qaac or refalac, wine # and abcde version 2.9.3 # # http://andrews-corner.org/qaac.html # -------------------------------------------------- # # Encode tracks immediately after reading. Saves disk space, gives # better reading of 'scratchy' disks and better troubleshooting of # encoding process but slows the operation of abcde quite a bit: LOWDISK=y # Specify the method to use to retrieve the track information, # the alternative here is to specify 'musicbrainz': CDDBMETHOD=cddb # With the demise of freedb (thanks for the years of service!) we move # to an alternative which so far works as a 'drop-in' replacement: CDDBURL="http://gnudb.gnudb.org/~cddb/cddb.cgi" # Make a local cache of cddb entries and then volunteer to use # these entries when and if they match the cd: CDDBCOPYLOCAL="y" CDDBLOCALDIR="$HOME/.cddb" CDDBLOCALRECURSIVE="y" CDDBUSELOCAL="y" # Specify the encoder to use for AAC or ALAC: AACENCODERSYNTAX=qaac # The path for qaac can be problematic as abcde cannot cope # with the 'standard' Wine location with spaces: # "$HOME/.wine/drive_c/Program\ Files/qaac/qaac.exe" # However the following works well: QAAC="$HOME/.wine/drive_c/qaac/qaac.exe" # Or use the Open Source ALAC encoder 'refalac' with this small hack: # QAAC="$HOME/.wine/drive_c/qaac/refalac.exe" # Specify your required encoding options here, further options can be seen # by running 'qaac --help'. Note the ALAC options are 'commented' out here # so this example encodes to AAC: # QAACENCOPTS="--alac --threading --verbose" QAACENCOPTS="--tvbr 91 --quality 2 --verbose" # Output type for AAC: OUTPUTTYPE="m4a" # The cd ripping program to use. There are a few choices here: cdda2wav, # dagrab, cddafs (Mac OS X only) and flac. New to abcde 2.7 is 'libcdio'. CDROMREADERSYNTAX=cdparanoia # Give the location of the ripping program and pass any extra options, # if using libcdio set 'CD_PARANOIA=cd-paranoia'. CDPARANOIA=cdparanoia CDPARANOIAOPTS="--never-skip=40" # Give the location of the CD identification program: CDDISCID=cd-discid # Give the location for the 'compatibility layer software application' # known as Wine: WINE=wine # Give the base location here for the encoded music files. OUTPUTDIR="$HOME/Music" # The default actions that abcde will take. ACTIONS=cddb,playlist,read,encode,tag,move,clean OUTPUTFORMAT='${OUTPUT}/${ARTISTFILE}-${ALBUMFILE}/${TRACKNUM}.${TRACKFILE}' VAOUTPUTFORMAT='${OUTPUT}/Various-${ALBUMFILE}/${TRACKNUM}.${ARTISTFILE}-${TRACKFILE}' ONETRACKOUTPUTFORMAT='${OUTPUT}/${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}' VAONETRACKOUTPUTFORMAT='${OUTPUT}/Various-${ALBUMFILE}/${ALBUMFILE}' # Create playlists for single and various-artist encodes. I would suggest # commenting these out for single-track encoding. PLAYLISTFORMAT='${OUTPUT}/${ARTISTFILE}-${ALBUMFILE}/${ALBUMFILE}.m3u' VAPLAYLISTFORMAT='${OUTPUT}/Various-${ALBUMFILE}/${ALBUMFILE}.m3u' # This function takes out dots preceding the album name, and removes a grab # bag of illegal characters. It allows spaces, if you do not wish spaces add # in -e 's/ /_/g' after the first sed command. mungefilename () { echo "$@" | sed -e 's/^\.*//' | tr -d ":><|*/\"'?[:cntrl:]" } # What extra options? MAXPROCS=2 # Run a few encoders simultaneously PADTRACKS=y # Makes tracks 01 02 not 1 2 EXTRAVERBOSE=2 # Useful for debugging COMMENT='abcde version 2.9.3' # Place a comment... EJECTCD=y # Please eject cd when finished :-)

Note especially the end of support from freedb, it looks like for the moment gnudb is an adequate drop-in replacement and this certainly worked well enough on my system. I have tested this on my own system and it was quite a pleasure to see abcde cranking up into action again. And I hope RM that this also works well on your system too!