I have a bunch of mkv files that are encoded as MPEG-4 video and AC-3 audio. I usually use Subler to convert the mov into mp4 to read them in iTunes, but the AC-3 audio is unreadable by Subler or iTunes.

So, I want to convert them into mp4 files with AAC audio, without re-encoding the video part which is just fine as MPEG-4.

How can I do that?

2 Answers 2


Install ffmpeg by running brew install ffmpeg or sudo port install ffmpeg or by downloading a binary from http://ffmpegmac.net. Then run a command like:

for f in *.mkv;do ffmpeg -i "$f" -c:v copy -c:a aac -b:a 256k -strict -2 "${f%mkv}mp4";done

Or if you don't need to re-encode audio:

for f in *.mkv;do ffmpeg -i "$f" -c copy "${f%mkv}mp4";done
  • What time did it take for you to decode mkv video files like 1GB size? This solution worked beautifully, 1GB video mkv files processed with old MBA in about 3 minutes +1
    – hhh
    Commented Nov 12, 2016 at 12:40


z264 will examine everything, but will only touch avi, flv, mpg, mpeg, wmv, vob, mkv and mp4 video files, copying video and audio streams and rewrapping if possible, transcoding just the audio if necessary, and transcoding only what video is necessary, and leave you with iTunes friendly, atom optimized mp4 files, leaving the originals in your Trash. It makes reasonably intelligent decisions for you about how to transcode files based on how you set its HandBrake variables (set at lines 312-333).

minor issues: does not yet count how many background processes it spawns, meaning if there are a lot of transcodes, it will take awhile for them to complete, but they will complete. You also need a lot of memory (8GB is ok). Snow Leopard users will need to install purge command from xcode developer tools.

check file for AVC encoding and flv, wmv, or mkv wrapper and rewrap in mp4 container otherwise, if not already am mp4, transcode to AVC mp4

z264 has several dependencies (mediainfo, rmtrash, ffmpeg, SublerCLI, and HandBrakeCLI)

  • copy and paste into text file, uncomment binary install section (remove #), save anywhere
  • open Terminal.app

    chmod +x z264
  • run once

  • recomment binary section (replace #) after dependencies install into /usr/local/bin/

  • create ramdisk called 'Two' using command in ramdisk section

    diskutil quiet erasevolume HFS+ 'Two' `hdiutil attach -nomount ram://4194304`
  • double-check command definitions (locations of dependencies), and correct locations (to "/usr/local/bin/")

    change line 231 to read:  mediainfo="/usr/local/bin/mediainfo"
    change line 236 to read:  rmtrash="/usr/local/bin/rmtrash"
    change line 238 to read:  ffmpeg="/usr/local/bin/ffmpeg"
    change line 239 to read:  SublerCLI="/usr/local/bin/SublerCLI"
    change line 262 to read:  mediainfo="/usr/local/bin/mediainfo"
    change line 263 to read:  rmtrash="/usr/local/bin/rmtrash"
    change line 265 to read:  HandBrakeCLI="/usr/local/bin/HandBrakeCLI"
  • save as z264 in /usr/local/bin/

  • use Terminal to call z264 on single file, directory of files, or your entire drive

    z264 directory.full.of.mixed.video.filetypes/*
  • How much time does this method approximately take to covert 1GB video mkv files?
    – hhh
    Commented Nov 12, 2016 at 12:43

You must log in to answer this question.

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