Ryan (tekman) wrote,
Ryan
tekman

Convert 720p/ac3 mkv to 720p/aac iPad-compatible mp4/m4v on Mac OS X Snow Leopard

# Video is not transcoded, just demuxed/muxed
# Audio is downmixed to stereo with DRC 
#
# You need these tools:
# * mkvextract (to demux the Matroska file)
#   * http://www.bunkus.org/videotools/mkvtoolnix/
#   * Just install through MacPorts, it doesn't pull in anything annoying
# * a52dec (to decompress and downmix the ac3)
#   * http://liba52.sourceforge.net/
#   * Compile from source
# * faac (to recompress the audio to mp4a/aac)
#   * http://www.audiocoding.com/
#   * Compile from source
# * MP4Box (to remux into MPEG-4 container) 
#   * http://kurtnoise.free.fr/mp4tools/
#   * Pre-compiled standalone OS X executable

mkvextract tracks ${BASE}.mkv 1:${BASE}.ac3 2:${BASE}.264
a52dec -o wav ${BASE}.ac3 > ${BASE}.wav
faac -b 96 --mpeg-vers 4 -o ${BASE}.aac ${BASE}.wav
MP4Box -add ${BASE}.264:fps=23.976 -add ${BASE}.aac ${BASE}.m4v
rm ${BASE}.{264,ac3,wav,aac}
Update: Here's a gist of an mkv2m4v script that automates the process: http://gist.github.com/502844
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 7 comments
Only four command line tools?! I am dubious it could be that easy…
Pretty much. Turns out that the AC3 and h.264 tracks might have different identifiers, so you have to check to get the right TID first.

I threw together a shell script to automate the whole process. It's available as a public gist on github:

http://gist.github.com/502844
It took 4m13s to process a 46m mkv. Much better than re-encoding through Handbrake.
Very useful article. Have been trying to repackage some MKV files into iPad-friendly formats.

Can't seem to locate the OS X executable for MP4Box at the URL you listed above. Has it been removed? Thanks.
Found a copy of MP4Box 0.4.6-DEV compiled as Max OS X universal binary.

Check the download links at:
http://penguintool.blogspot.com/

Direct download URL:
http://www.exomanic.com/joomla/index.php?option=com_weblinks&task=view&catid=15&id=20


# GPAC has mp4box:
brew install faac a52dec gpac mkvtoolnix
Damn... this script worked like a charm. Thanks for writing it!