Ffmpeg transcoding audio to MPEG-4 HE AAC instead of AAC

audioencodingvideo

I have an Automator script that uses ffmpeg to re-encapsulate a video file into an mp4 container with its audio transcoded to aac while leaving the video as is.

for f in "$@"
do
    /Applications/Scriptlets/ffmpeg -i "$f" -c:v copy -c:a aac -b:a 384k -strict -2 "${f%.*}.m4v"
done

This works fine and the resulting video plays well on my system in both iTunes as well as Quick Time Pro; tried it with both avi and mov source files. However, I just noticed that the resulting files have their audio encoded to MPEG-4 HE AAC instead of plain AAC as intended. As a result, even though the file plays well on my Mac, I am unable to play it on my TV which recognizes AAC but not HE-AAC. Any workaround using ffmpeg? Please note that I am not interested in installing yet another encoding/transcoding application for this job. I only want to use ffmpeg so please do not suggest installing anything else.

Best Answer

The problem is your ffmpeg. If telling ffmpeg to use aac causes it to encode in he aac, if that is true, then there is something wrong with your ffmpeg, because specifying aac should never result in he aac. Only telling ffmpeg to encode using libaacplus or libfdk_aac should result in he aac encodes.


Here's an idea... build your own ffmpeg from source, because your binary was built wrong (if what you are saying is true).

You can download the ffmpeg source and build it manually:

  git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

But its far easier to install it using package management, like macports:

MacPorts requires an appropriate version of xcode; xcode_5.1.1.dmg is the most recent version for Mavericks (after registerring for a free developer account, and logging into developer.apple.com, that link will begin your xcode download). Once the download completes, open your Terminal.app and complete the installation:

 hdiutil attach -quiet -noverify -nobrowse -noautoopen ~/Downloads/xcode_5.1.1.dmg
 cp -npR /Volumes/Xcode/Xcode.app /Applications/
 hdiutil detach -quiet /Volumes/Xcode

Download and build macports:

MacPorts Guide

 curl -Ok https://distfiles.macports.org/MacPorts/MacPorts-2.2.1.tar.bz2
 tar xf MacPorts-2.2.1.tar.bz2
 cd MacPorts-2.2.1
 ./configure
 make
 sudo make install     # *not war!*
 cd ..
 rm -rf Macports-*
 sudo /opt/local/bin/port -v selfupdate
 diskutil quiet repairPermissions /

add macports to your $PATH:

 export PATH=/opt/local/bin:/opt/local/sbin:$PATH
 export MANPATH=/opt/local/share/man:$MANPATH

build your ffmpeg

 sudo port -vsc install ffmpeg

you can keep everything updated simply with:

 sudo port -vsc selfupdate
 sudo port -vsc upgrade installed

If you are unsatisfied and/or need to remove MacPorts:

 sudo port -dfp uninstall --follow-dependencies installed
 sudo port -dfp uninstall all
 sudo rm -rf /opt/local  
 sudo rm -rf /Library/Tcl/macports*