timdoug's interesting tidbits

Little bits of technical documentation and such. Hopefully helpful.

2010-07-26

Converting a .mkv file to .mp4 to play on the iPad

Problem: you acquire a MKV file you want to play on your iPad. It's already H264/AAC, which the iPad can handle, so you don't want to re-encode it.

Solution: extract the tracks with mkvextract, and mux them into an iPad-friendly MP4 with MP4Box.

  1. Get a GPAC Subversion snapshot from http://gpac.sourceforge.net/.
  2. Build it. It's a bit finicky, and it will probably crap out looking for nonexistent wxwidgets libraries, but hopefully before that it'll create an MP4Box binary in bin/gcc.
  3. Grab a Mac OS X binary of MKVToolnix. Its dependencies are pretty extensive, so I used the binary available here.
  4. Determine what's in the mkv container: Mkvtoolnix.app/Contents/MacOS/mkvinfo Foo.mkv
  5. It'll tell you that, e.g., track one is H264 video at 24 fps, and track two is AAC.
  6. Extract the tracks accordingly: Mkvtoolnix.app/Contents/MacOS/mkvextract tracks Foo.mkv 1:Foo.h264 2:Foo.aac
  7. Put them back together in an MP4: MP4Box -add Foo.aac -add Foo.h264 -fps 24 Foo.mp4

Sometimes, though, you'll get audio in a non-AAC format (e.g., MP3 or AC3). This requires conversion.

  1. Download, make, and install the libfaac library. (We'd use FFmpeg's internal AAC encoder, but currently it's broken.)
  2. Do the same with FFmpeg, making sure to point it to libfaac appropriately.
  3. Convert the extracted audio file to AAC: ffmpeg -i Foo.ac3 -acodec libfaac -ab 192k Foo.aac
  4. Then use MP4Box as before, but with your new .aac file.
Thanks to this thread and this blog post.

[/coding] permanent link


© 2006-18 timdoug | email: "me" at this domain
So necessary