1. Andrew's Corner »
  2. Linux Explorations...

Using fhgaacenc under Linux...

Buoyed somewhat by the success of another page: Using qaac under Linux... I have decided to burrow a little deeper into the world of AAC encoding under Linux by investigating the usage of fhgaacenc with Wine. fhgaacenc is a wrapper for the commercial AAC encoder licensed to the almost defunct Winamp and has the virtue of not only producing great AAC-LC files but also HE-AAC and HE-AAC v2 files. This page provides a simple copy and paste approach to an installation of fhgaacenc that can otherwise under Linux be somewhat complex. The page also includes instructions on commandline usage and finally the most exciting aspect of the whole page for me personally: details of how to use fhgaacenc with the commandline ripper abcde!

If this page helps anyone to successfully and effectively use this commandline encoder I will be very happy. If perhaps the page falls short of this mark please email me using the link at the base of this page to let me know what shortcomings of this page should be addressed. And remember: "Have fun!!".


fhgaacenc and Winamp were created for Windows users so will need to install the Wine package appropriate for your distro. I tested this guide while runing Wine 1.6.2 under Slackware Linux, you will also need the 7z file archiver. If you are running Ubuntu you will need something like the following:

sudo apt-get install wine p7zip-full

With these installed you will need both the fhgaacenc application zip file and a modern copy of Winamp from which we will extract the appropriate dll files. The following single command makes a build directory, downloads and then unzips fhgaacenc 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/fhgaacenc_build && \
cd $HOME/fhgaacenc_build && \
wget http://tmkk.undo.jp/tools/fhgaacenc-20120624.zip && \
7z e fhgaacenc-20120624.zip \
     fhgaacenc.exe libsndfile-1.dll -r \
     -o$HOME/.wine/drive_c/fhgaacenc/ && \
chmod +x $HOME/.wine/drive_c/fhgaacenc/fhgaacenc.exe

Note the adjustment of permissions to fhgaacenc.exe, this adjustment is required by abcde and is good practice as well. The next single command downloads the Winamp installation file and extracts the dll files needed by fhgaacenc. Note that the original host of the Winamp installer has been forced to remove the file from his own site so I am hosting a copy on my own site temporarily:

cd $HOME/fhgaacenc_build && \
wget http://andrews-corner.org/downloads/winamp5666_full_en-us_redux.exe && \
7z e winamp5666_full_en-us_redux.exe \
     enc_fhgaac.dll libmp4v2.dll \
     nsutil.dll -r \

This Winamp installer is easily found in other parts of the internet so feel free to search it out if you are not happy with my own stored copy! 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 fhgaacenc more easily. I include here as well a line to turn off the painful Wine debugging messages:

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

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

All done! Perhaps these instructions will change if Radionomy produces a new version of Winamp in 2015, I will be following these developments with keen interest! With the installation done I will next describe the commandline usage of fhgaacenc and finally I give you an ~/.abcde.conf for the commandline ripper abcde to produce HE-AAC v2 files using the git abcde!

Commandline usage...

To demonstrate the commandline usage of fhgaacenc I will use my favourite wav file and perhaps you should also download it? The options for fhgaacenc are remarkably simple and I will demonstrate the usage for both VBR and CBR encoding (if all of the acronyms are a bit confusing have a look here for a simple explanation!):

fhgaacenc and Variable Bitrate Mode (VBR)...

fhgaacenc's default mode is VBR and certainly if you have no special needs this is the mode you should also use. Rather than target a specific bitrate there are a set of profiles numbered from 1-6 which will achieve a certain overall bitrate as well as allowing fhgaacenc to automatically select the appropriate AAC mode. The table below show the typical bitrates and modes achieved with each preset:

fhgaacenc VBR Presets
Testing with this file: fhgaacenc --vbr <n> luckynight.wav
VBR preset 1 2 3 4 5 6
Overall Bitrate in kbps 38.0 64.5 98.6 132.0 207.0 253.0

Note that fhgaacenc does not have any tagging capabilities and I have personally been using the latest version of AtomicParsley to achieve easy tagging. So to get great AAC-LC sound and appropriate tagging something like the following would be fine for our sample file:

fhgaacenc --vbr 5 luckynight.wav luckynight.m4a && \
AtomicParsley luckynight.m4a \
              --album "Treasure Quest Soundtrack" \
              --artist "Jody Marie Gnant" \
              --tracknum "9" \
              --title "Lucky Night" \
              --genre "Soundtrack" \
              --year "1995" \
              --comment "Testing fhgaacenc encoding..." \

And this may very well be enough for all of your encoding needs with fhgaacenc, it certainly is enough for my own usage. But if you would like a little more have a look at the following section which deals with the use of CBR encoding:

fhgaacenc and Constant Bitrate Mode (CBR)...

If you have decided to use CBR encoding you will have a few more choices to play with. You can select a bitrate from 8kbps to a mind-altering 576kbps as well as either allowing fhgaacenc to select the most appropriate AAC format or manually selecting it yourself with the --profile option (by default set to 'auto'). To illustrate this point So the following commandline creates an HE-AAC v1 file of the correct bitrate:

fhgaacenc --cbr 64k luckynight.wav

But this bitrate is on the cusp of the boundary where you could with some degree of sanity prefer to use AAC-LC and this can be forced as follows:

fhgaacenc --cbr 64k --profile lc luckynight.wav

The profile options are: --profile <auto|lc|he|hev2> and to tell the complete truth the defaults are quite sane and will not need tampering with all that much. But for those who wish to experiment or those who have specific needs the options are all there. Now to add the meta tags as well:

fhgaacenc --cbr 64k --profile lc luckynight.wav luckynight.m4a && \
AtomicParsley luckynight.m4a \
              --album "Treasure Quest Soundtrack" \
              --artist "Jody Marie Gnant" \
              --tracknum "9" \
              --title "Lucky Night" \
              --genre "Soundtrack" \
              --year "1995" \
              --comment "Testing fhgaacenc encoding..." \

It all works beautifully! But for me the true magic is converting an entire audio cd using fhgaacenc and the commandline ripper abcde:

Using fhgaacenc with abcde...

It gave me immense pleasure and not an inconsequential amount of work to add support for fhgaacenc into abcde. Currently this is for version 2.7.1 and greater.Tagging in abcde for fhgaacenc is with AtomicParsley, the best current version of AtomicParsley that is under active development can be found here. Below is a sample ~/.abcde.conf file that produces a great HE-AAC v2 encode:

# -------------------$HOME/.abcde.conf------------------- #
#   A sample configuration file to convert music cds to 
#     HE-AAC v2 using fhgaacenc abcde version 2.7.1
#       http://andrews-corner.org/fhgaacenc.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:

# Specify the method to use to retrieve the track information,
# the alternative is to specify 'cddb':

# Make a local cache of cddb entries and then volunteer to use 
# these entries when and if they match the cd:

# Specify the encoder to use for AAC:

# The path for fhgaacenc can be problematic as abcde cannot cope
# with the 'standard' Wine location with spaces:
#   "$HOME/.wine/drive_c/Program\ Files/fhgaacenc/fhgaacenc.exe"
# However the following works well:             

# Specify your required encoding options here, these options
# give HE-AAC v2 VBR with an average bitrate of about 32kbps:

# Give the location of the fhgaacenc tagger and pass any extra options
# here. Remember that the 'overWrite' option is already used:

# Output type:

# 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'.
# Give the location of the ripping program and pass any extra options,
# if using libcdio set 'CD_PARANOIA=cd-paranoia'.

# Give the location of the CD identification program:       

# Give the location for the 'compatibility layer software application'
# known as Wine:
# Give the base location here for the encoded music files.

# The default actions that abcde will take.


# Create playlists for single and various-artist encodes. I would suggest
# commenting these out for single-track encoding.

# 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.7.1'             # Place a comment...
EJECTCD=y                                 # Please eject cd when finished :-)

And of course you can alter FHGAACENCOPTS to achieve whatever form of encoding you desire from fhgaacenc. Let me know how you go with this one, as an abcde developer I am in a position to add suggested enhancements into abcde and I am more than happy to do so!

And in conclusion...

This page represents my own exploration of the commandline encoder fhgaacenc and my efforts to make it both easy to install and use under Linux. If I have perhaps made your own usage of fhgaacenc a little easier let me know by using the email link below. Also let me know of any errors on this page or indeed if there are better ways to accomplish the various tasks I have outlined here. And above all "Have fun!".