<p>I've been looking for a way to convert an mp3 to aac programmatically or via the command line with no luck.  Ideally, I'd have a snippet of code that I could call from my rails app that converts an mp3 to an aac.  I installed ffmpeg and libfaac and was able to create an aac file with the following command:</p>

<p><code>ffmpeg -i test.mp3 -acodec libfaac -ab 163840 dest.aac</code></p>

<p>When i change the output file's name to dest.m4a, it doesn't play in iTunes.  </p>

<p>Thanks!  </p>

[{'answer_id': 70117, 'author': 'Dark Shikari', 'author_id': 11206, 'author_profile': 'https://Stackoverflow.com/users/11206', 'pm_score': 2, 'selected': False, 'text': "<p>There are only three free AAC encoders that I know of that are available through a commandline interface:</p>\n\n<ol>\n<li><p>FAAC (LPGL), which is honestly pretty bad (the quality is going to be significantly worse than LAME at the same bitrate).  Its fine though if you're willing to go for higher bitrates (>>128kbps) and need AAC for compatibility, not quality reasons.  The most common way to use FAAC is through ffmpeg, as libfaac.</p></li>\n<li><p>Nero AAC, the commandline encoder for which is available for free under Windows and Linux, but only for noncommercial use (and is correspondingly closed-source).</p></li>\n<li><p>ffmpeg's AAC encoder, which is still under development and while I believe it does technically work, it is not at all stable or good or even fast, since its still in the initial stages.  Its also not available in trunk, as far as I know.</p></li>\n</ol>\n\n<p>(Edit: Seems iTunes might have one too, I suspect its terms of use are similar to Nero's.  AFAIK its quality is comparable.)</p>\n"}, {'answer_id': 70122, 'author': 'Sev', 'author_id': 83819, 'author_profile': 'https://Stackoverflow.com/users/83819', 'pm_score': 1, 'selected': False, 'text': '<p>After installing the converting app on the linux/window machine you\'re running your Rails application on, use the "system()" command in Ruby to invoke the converting application on the system.  system("command_here");</p>\n'}, {'answer_id': 70138, 'author': 'rpetrich', 'author_id': 4007, 'author_profile': 'https://Stackoverflow.com/users/4007', 'pm_score': 4, 'selected': True, 'text': '<p><a href="http://en.wikipedia.org/wiki/Ffmpeg" rel="noreferrer">FFmpeg</a> provides AAC encoding facilities if you\'ve compiled them in. If you are using Windows you can grab full binaries from <a href="http://arrozcru.no-ip.org/ffmpeg_builds/" rel="noreferrer">here</a></p>\n\n<pre><code>ffmpeg -i source.mp3 -acodec libfaac -ab 128k dest.aac\n</code></pre>\n\n<p>I\'m not sure how you would call this from ruby.</p>\n\n<p>Also, be sure to set the bitrate appropriately.</p>\n'}, {'answer_id': 72678, 'author': 'dmckee --- ex-moderator kitten', 'author_id': 2509, 'author_profile': 'https://Stackoverflow.com/users/2509', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve had good luck using mplayer (which I believe uses ffmpeg...) and lame. To the point that I\'ve wrapped it up in a script:</p>\n\n<pre><code>#!/bin/sh\n\nTARGET=$1\n\nBASE=`basename "${TARGET}"`\necho TARGET: "${TARGET}"\necho BASE:   "${BASE}" .m4a\n\n# Warning! Race condition vulnerability here! Should use a mktemp\n# variant or something...\nmkfifo encode\nmplayer -quiet -ao pcm -aofile encode "${TARGET}" &amp;\nlame --silent encode "${BASE}".mp3\nrm encode\n</code></pre>\n\n<p>Sorry for the security issues, I banged this out on the train one day...</p>\n\n<p>My mplayer and lame come from <a href="http://www.finkproject.org/" rel="nofollow noreferrer">fink</a></p>\n'}, {'answer_id': 154619, 'author': 'Tim Farley', 'author_id': 4425, 'author_profile': 'https://Stackoverflow.com/users/4425', 'pm_score': 2, 'selected': False, 'text': '<p>I realize I\'m late to this party, but I\'m questioning the premise of this question.  Why do you even want to convert an MP3 to an "itunes playable" format?  iTunes already handles MP3s natively.  </p>\n\n<p>It seems like you are doing an unnecessary conversion, and since you are converting from one lossy format to another, you are losing some quality in the process.</p>\n'}, {'answer_id': 2518567, 'author': 'Jacek Glinkowski', 'author_id': 301982, 'author_profile': 'https://Stackoverflow.com/users/301982', 'pm_score': 2, 'selected': False, 'text': '<p>in ffmpeg 0.5 or later use\nffmpeg -i source.mp3 target.m4a</p>\n\n<p>for better results to transfer metadata and to override default bitrate ffmpeg applies</p>\n\n<p>ffmpeg -i "input.mp3" -ab 256k -map_meta_data input.mp3:output.m4a output.m4a</p>\n\n<p>best do not convert as ipod plays mp3 fine (I know there is such answer but my low standing does not allow voting)</p>\n'}, {'answer_id': 23302325, 'author': 'user62107', 'author_id': 3574313, 'author_profile': 'https://Stackoverflow.com/users/3574313', 'pm_score': 0, 'selected': False, 'text': '<p>Actually, syntax is ffmpeg  -i input.mp3 -c:a aac -strict -2 -b:a 256k output.m4a; more correct if one is emulating "correct" bitrate. \ncf.:<a href="http://ffmpeg.gusari.org/viewtopic.php?f=25&amp;t=38" rel="nofollow">link</a> for a compilation scheme. (rpmfusion package works fine too:</p>\n\n<p>configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags=\'-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic\' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-libass --enable-libcdio --enable-libcelt --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect</p>\n'}]
['https://Stackoverflow.com/questions/70096', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']