I can issue this command:

ffmpeg -i input.mp3 -acodec alac -ab 128k -ar 48000 -ac 2 -y output.m4a 

to create a m4a file.

But when I issue this command

ffmpeg -i input.mp3 -acodec alac -ab 128k -ar 48000 -ac 2 -y output.aac

ffmpeg is throwing an error saying

Could not write header for output file #0 (incorrect codec parameters ?).

Also, the size of the m4a file is really almost 5.8 times larger than the original file, which is absolutely not what I wanted and why I wanted to convert to AAC.

up vote 35 down vote accepted

How can I convert to AAC?

This is the most basic FFmpeg command to convert input to AAC audio using the highest quality AAC FFmpeg has. libfdk_aac is the Fraunhofer AAC encoder, and it is available when you compiled FFmpeg with support for it.

ffmpeg -i input.mp3 -c:a libfdk_aac output.m4a

To change the quality, you have two options:

  • For variable bitrate (VBR), use the -vbr option. For example, -vbr 4 is a good choice (roughly 128 kBit/s for stereo audio). Higher means better. Values range from 1 to 5.

    ffmpeg -i input.mp3 -c:a libfdk_aac -vbr 4 output.m4a
    
  • For fixed bitrate (CBR), use the -b:a option, for example -b:a 128k. 128 kBit/s should be good enough for most situations. You can often choose something lower as well.

    ffmpeg -i input.mp3 -c:a libfdk_aac -b:a 128k output.m4a
    

You can also use HE-AAC (v1/v2) instead of the default AAC-LC (low complexity) profile, which is best suited for low bitrates:

ffmpeg -i input.mp3 -c:a libfdk_aac -profile:a aac_he_v2 -b:a 32k output.m4a

What if I don't have libfdk_aac?

Some versions of FFmpeg do not have libfdk_aac (for licensing reasons). If that's the case, you can use the built-in AAC encoder:

ffmpeg -i input.mp3 -c:a aac -b:a 192k output.m4a

This encoder does not support VBR properly, so if you need that or HE-AAC, read on.

You can compile ffmpeg yourself and add libfdk_aac support. There are guides on the FFmpeg Wiki. Compiling is easy on Linux, moderately easy on OS X, and rather hard on Windows. When you follow the compilation guides and install the appropriate libraries before, FFmpeg now gives you the option to use libfdk_aac.


There were some problems with your original approach:

  • alac is not AAC. ALAC is the Apple Lossless Audio Codec, whereas AAC is Advanced Audio Coding.

  • That's why your output is larger than the input, because in contrast to MP3, ALAC is still compressed, but it needs to be lossless – that's why it needs to store more data.

  • .aac is not an output container for ALAC audio. If you use AAC, that should work. I would use MP4 or M4A though.

  • On Ubuntu 12.04 I was unable to use an option -c:a, does this have any synonym? I guess it might mean -acodec:a but in the end I just dropped it, and ffmpeg was able to deduce a codec based on the desired output file name. (Need -strict experimental though; and threw in -map_metadata 0:0 for good measure, to preserve ID3 tags.) – tripleee Oct 3 '13 at 7:47
  • Also worth noting: I wanted M4B files (audiobooks), which ffmpeg does not appear to support, but converting into M4A and then just renaming seems to work. – tripleee Oct 3 '13 at 7:53
  • @tripleee That means you're using an outdated program called ffmpeg, but it's really not from FFmpeg, but the Libav fork. Ubuntu unfortunately bundled it instead of the "real" ffmpeg. See: Who can tell me the difference and relation between ffmpeg, libav, and avconv – slhck Oct 3 '13 at 7:57
  • @slhck: Thanks for the quick update and the link! – tripleee Oct 3 '13 at 8:00
  • 1
    @tripleee Actually no, .m4a files are identical to .mp4 (it's just a convention naming for mp4 files with audio only), but have a different format than .aac (which is known as an ADTS stream). You can also force FFmpeg to output in ADTS format by adding -f adts. – Bigue Nique Mar 22 '16 at 3:32

Easy convert to AAC for Zeranoe Windows Builds

ffmpeg -i input.mp3 -c:a aac -b:a 128k output.m4a

Use "aac" instead of libfaac or libfdk_aac: https://trac.ffmpeg.org/wiki/Encode/AAC

"FFmpeg can support three AAC-LC encoders (aac, libfaac, libfdk_aac) and one HE-AAC(v1/2) encoder (libfdk_aac). The licenses of libfaac and libfdk_aac are not compatible with the GPL, so the GPL does not permit distribution of binaries containing code licensed under these licenses when GPL-licensed code is also included."

  • 2
    libfaac support has also been removed as of 3.2. – slhck Feb 27 '17 at 17:32

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.