remuxing the audio

I really, really hate AAC.  Don’t ask me why … it’s an unreasonable hatred.  But, who cares.  Last night I downloaded a trailer from Apple’s website (they have them in HD, how cool is that … my computer couldn’t handle the 1080p one, heh), and of course the audio was in AAC.  I hate that.

I wanted to get just the audio from the file, decode it using faad, then re-encode it to AC3.  Normally in a situation like this, you would just use mencoder to re-encode the audio portion and create a new AVI.  But, I always have problems with that when I just want to copy the video portion (mencoder -ovc copy -oac whatever … ), so instead I just dump the audio, reencode it, then mux it all back in one file.

More specifically, this is what I do:

1. Start with a file where I want to keep the video the same (copy it, no encoding), but only re-encode the audio to another codec.

2. Extract the audio to a WAV file using mplayer

mplayer cool_movie_trailer.mov -vo null -vc null -ao pcm:fast:file=cool_movie_trailer.wav

3. Reencode the WAV to the codec of my choice.  In this case, AC3 (emerge media-sound/aften).

aften cool_movie_trailer.wav cool_movie_trailer.ac3

4. Mux the original video into a Matroska file, ignoring the audio track, and inserting the AC3 track instead

mkvmerge -o cool_movie_trailer.mkv -A cool_movie_trailer.mov cool_movie.trailer.ac3

The -A flag tells mkvmerge to ignore any audio tracks from the .mov file, thus the .ac3 file becomes the first (and only) audio track.  Without that flag, I could have had both audio tracks on there, but I don’t really want that either.

That’s pretty much it.  I wrote a little bash script to do the whole thing for me:

#!/bin/bash
I=${1}
EXT=${1/*./}
BASE=`basename ${1} .${EXT}`

WAV=${BASE}.wav
AC3=${BASE}.ac3
MKV=${BASE}.mkv

mplayer ${1} -vo null -vc null -quiet -ao pcm:fast:file=${WAV}
aften ${WAV} ${AC3}
mkvmerge -o ${MKV} -A ${1} ${AC3}
rm ${AC3} ${WAV}

Just save it as some_script.sh and the first (and only) argument is the movie you want to convert.  So foobar.sh cool_movie_trailer.mov, and it’ll spit out the .mkv file and delete all the temp files.

No more AAC.  I’m happy. :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s