2

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.

2 Answers 2

2

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*
10
  • A complete layman here so I have some questions despite your thorough explanation: First, what's git? is it something I just run on my Terminal and the rest is taken care of by my shell? Or is it something I need to separately install? I tried opening the link you gave (git://source.ffmpeg.org/ffmpeg.git) and it obviously didn't open in Safari. I already have Xcode installed on my system but the whole macports process seems overly complicated. Maybe because I am far from tech-savvy. :(
    – TheLearner
    Commented May 15, 2014 at 6:41
  • Also, though I already have Xcode installed, I am curious about the Terminal method of installation suggested by you ( hdiutil attach -quiet -noverify -nobrowse -noautoopen ~/Downloads/xcode_5.1.1.dmg cp -npR /Volumes/Xcode/Xcode.app /Applications/ hdiutil detach -quiet /Volumes/Xcode). I installed it off my App Store. Is there any particular advantage in going the Terminal route for installing Xcode?
    – TheLearner
    Commented May 15, 2014 at 6:44
  • 1
    Yes, the advantage is that you won't have to deal with App Store. git is a way to "check out" software like checking out a library book. Its really much simpler to build ffmpeg using macports, because macports will take care of all the dependencies for you, download and build them all for you. If you tried to use that git command, you just get the ffmpeg source, and the build will fail because you're missing all the other source of the dependencies. Just start at "Download and build MacPorts" It won't interfere with anything, and if you don't like it, you can remove everything quite simply.
    – chillin
    Commented May 15, 2014 at 6:48
  • 1
    But you're going to love it, I assure you. It only seems like a lot of commands to build one port, ffmpeg. But you then have access to all of macports with a simple command, port. For example, to build mediainfo, which is a great little media analysis tool, you install it the same way: sudo port -vsc install mediainfo or to build HandBrake its sudo port -vsc install handbrake ; Search for stuff with port search something and it returns names of ports that are germane. Then you'd port info something to get info about it. then sudo port -vsc install something to build from source
    – chillin
    Commented May 15, 2014 at 6:54
  • 1
    let us continue this discussion in chat
    – chillin
    Commented May 15, 2014 at 6:59
1

The AAC Encoding Guide ffmpeg wiki page for should help.

This superuser question may also help, How to use ffmpeg to downmix 5.1 DTS HD MA or Dolby TrueHD to stereo AAC with Dolby Pro Logic II?

The guide mentions multiple AAC encoding formats are supporting but they may require custom compiling to be present:

FFmpeg can support four AAC-LC encoders (aac, libfaac, libfdk_aac, libvo_aacenc) and two AAC-HE encoders (libaacplus and libfdk_aac). The licenses of libaacplus, 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. Therefore these encoders have been designated as "non-free", and you cannot download a pre-built ffmpeg that supports them. This can be resolved by compiling ffmpeg yourself.

There are a few guides for building or getting more capable builds of ffmpeg onto your Mac, for example Install FFMPEG on a Mac. As mentioned in the article, I find brew the easiest way to install such tools.

1
  • I did read that excerpt on the ffmpeg wiki page but it didn't help much. I do understand that libfaac and libfdkaac are not available for licensing reasons but aac is, right? Shouldn't ffmpeg be converting to aac by default then (when used with the aac argument)? I am an absolute layman on this issue so my question might be a tad stupid for which I apologize in advance.
    – TheLearner
    Commented May 15, 2014 at 6:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .