I am looking to implement a fully automated solution that will pick video files from an incoming directory, process them and put the result to iTunes special "Automatically Add to iTunes" directory.

Before starting to propose different products do read the requirements:

  • Command line interface, so we can use it with a cron
  • Do Pass Thru for video and audio streams if the source is already compatible with target format
  • Download subtitles from an external service (optional)
  • Embedding existing SRT files into the output video
  • Fixing metadata from an external service (optional)

Initially I would say that Handbrake should be able to do this, but I discovered that handbrake will never do Pass Thru for video (that's a statement that I got from the author).

  • Since you're looking for a fully automated process it's pointless for me to write down the manual process I think. I'm using 3 programs to do exact what you want to achieve, except that it's manually. I download in mp4 format, so I don't need HandBrake for conversion anymore.
    – Rob
    Commented Jan 22, 2014 at 10:52
  • 1
    @Robuust please could you share which programs you are using. It may be possible for them to be combined through AppleScript or Automator. While it may not exactly meet the question's requirements, it may be close enough. Commented Jan 22, 2014 at 11:49
  • @Robuust yes, a manual process is a good example if the tools being used do have a command line interface.
    – sorin
    Commented Jan 23, 2014 at 15:06

7 Answers 7



z264 will look at every file, 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).

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 binary install section into a new bash script and use it to download and install the dependencies into /usr/local/bin/ (create /usr/local and /usr/local/bin/ if not there already)

  • create 2GB 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/

  • make executable

    sudo chmod +x /usr/local/bin/z264

  • use Terminal to call z264 on single file, directory of files, or call it from a cron to crawl entire file systems periodically

    z264 directory.full.of.mixed.video.filetypes/*

minor issues: user needs to be able to read, debug, and use bash. z264 does not yet count how many background_transcoder 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.

  • Thanks! Before testing, only by looking at the description and source code it seems to be what I was looking for. I posted the code on github, raise a ticket so I can add you as an admin of the project github.com/z264/z264
    – sorin
    Commented Jun 23, 2014 at 17:43
  • @sorin @chillin Seem to be getting stuck in a loop after the transcoding audio step: tty: illegal option -- - usage: tty [-s]
    – Yashar
    Commented Oct 14, 2014 at 3:04
  • @sorin I have been coming across files that should process fine, that do not,usually mkv with fataudio or audio that is too high kbps rates, and z264 processes… abd the result is a file that does not work. I think the problem is… certainly not ffmpeg… and I want to be seeringly clear, and if this sounds racist, its only to twist the tiniest pin prick to the most painful spot on the guy that actually broke handbrake downstream a few versions ago… lost my train… oh, french devs. yeah. french fn devs. But really we know the problem is Apple. We want the slick, but not at any expense!
    – chillin
    Commented Oct 15, 2014 at 3:56
  • mediainfo chokes sometimes, too, but there's no emotional investment. But when you spin a special transcode for something for someone off to a processor node, and that little engine transcodes its little heart out, and the result is a file that is, um, junk, tends to annoy. But MUCH RESPECT to debug devs in other languages.
    – chillin
    Commented Oct 15, 2014 at 4:17

Currently I use Subler to convert MKVs to MP4s and embed subtitles in the process, without transcoding either video or audio. If I need to transcode DTS so that Apple TV will play it, I use MP4Tools. However, both of these are GUIs, and I have no idea if they can be called from the command-line. I suppose your best bet would be MKVToolNix (assuming you just want to change the format) and ffmpeg (which includes transcoding options for when they're needed).


I'm using HandBrake as suggested in the Question above if the download isn't in MP4 format available. (I think I cannot name the service I'm using as downloading isn't legal in every country, but searching for Keyword "YIFY" might help to find MP4 rips) Next to that I'm using Subler to add an SRT without having to convert the MP4 all over again.

And afterwards to get the meta-data and the copy to iTunes I'm using iFlicks which can be downloaded from the App Store.

  • Subler can fetch the metadata directly from iTunes or TV/MovieDB. Why add the extra piece of software?
    – Jeff H.
    Commented Jan 2, 2016 at 7:07

I think you'll find your answers in those two posts:

So, to sum it up:

ffmpeg -i <input_file>.mkv -f srt -i <input_subtitle>.srt -c:v copy -c:a aac -b:a 384k -c:s mov_text -strict -2 <output_file>.mp4

Try in the package ffmpeg. It can decide if not all, most of the problems.

  • 2
    Please can you expand on how the questioner might use ffmeg to perform the desired tasks. Are there any flags or settings that might help them get started more easily. Commented Jan 22, 2014 at 14:25

You can have a look at VideoDrive for mac. It does all that automatically: www.aroonasoftware.com

It does not have a CLI, but it has a built-in timer to run whenever you want. And it's compatible with Applescript as well.


SmartConveter is Free in the App Store and it is faster than Handbrake.

  • Please can you expand on how SmartConverter can help answer the question. Does it offer a command line interface, pass thru, or other part of the requirements? Commented Jan 22, 2014 at 14:24

You must log in to answer this question.

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