I need an automated way to convert MKV to MP4 on Mac OS X
October 6, 2009 6:00 PM   Subscribe

I am trying to build an automated solution to convert MKV files to MP4 without re-encoding on Mac OS X, using AppleScript, Automator, etc. and I need help!

Multiple times a day I get MKV container files that I need to convert to MP4 files. There is a great application for Windows called XenonMKV that can extract the individual components out of an MKV container and re-assemble them as an MP4. It does this process without re-encoding the video, which saves tons of time. A process that would normally take an hour or two can be done in three to five minutes with XenonMKV.

Unfortunately, there is apparently nothing like this application for OS X. There is, however, a little trick you can pull off using QuickTime 7 Pro and Perian. Perian will let you open MKV files with QuickTime, which you can't normally do, and you can use the Pass Through option during export from QuickTime which achieves basically the same effect as XenonMKV.

So now that I know this process is possible, and since I have to do it multiple times a day, I want to try to automate it. It's pretty easy to slap together an AppleScript that can take a video file as input and then export it, but there are two hitches:

1. QuickTime Pro needs to use the specific Pass Through export settings no matter what the last export settings used were.

2. When you open an MKV file in QuickTime, the entire video must be indexed fully before you can run an export. This can take anywhere from a minute to three minutes or so, depending on the length and file size of the video.

The second problem seems to be the biggest because it doesn't appear there's any way to tell QuickTime to wait until a video is indexed before running a command. The best I could come up with was to parse the file size and then tell QuickTime to wait for a certain amount of time that's really just a best guess of how long it will take to index the video file based on its size. This is really not a good solution, because I'd like to share this with other people who might not have a system as fast as mine, and the numbers may be off.

So does anyone have any ideas on how I could make this process work? Ideally I'd like to see the final form as a standalone .app that can be used as a droplet and do everything automatically without any input from the user. Any help at all would be appreciated.
posted by joshrholloway to Computers & Internet (8 answers total) 4 users marked this as a favorite
tsMuxer will split MKVs into their individual tracks. Not sure about repackaging into mp4, but does AVCHD, m2ts and some other formats.
posted by wongcorgi at 6:45 PM on October 6, 2009

Response by poster: odinsdream, HandBrake only supports pass-through for audio as far as I can tell. I've scoured every bit of the interface in 0.9.3 and the latest SVN snapshot and video pass-through is just not there unless somehow I'm missing it. I know they've discussed it but I don't think it's made it into the project yet.
posted by joshrholloway at 7:23 PM on October 6, 2009

Check out the bottom of this post (the updates).
posted by travis08 at 8:49 PM on October 6, 2009

Here is another idea via the comments from the above link.

"1. Get VLC.
2. Open up the streaming and transcoding wizard (its under the file menu).
3. Click transode/save to file press next.
4. Then select your stream, press next.
5. On the Transcode page make sure none of the options are on, turn them off if they are. You don’t want to transcode your just remuxing. Press next.
6. Chose MPEG PS, press next.
7. Chose your save destination, press next.
8. Check if the details a correct and press finish, then wait while it does it business."
posted by travis08 at 8:52 PM on October 6, 2009 [1 favorite]

Response by poster: I've looked at that post before, and it doesn't offer anything that I don't already know.

I know what I want to do, I just need to know how to do it in a more automated fashion. VLC and HandBrake solutions don't help. What I really need is an AppleScript or Automator genius.

I do appreciate the effort, though.
posted by joshrholloway at 9:14 PM on October 6, 2009

Maybe the solution is to install a PC emulator on your Mac and to run that PC program you have already found under Windows.
posted by Chocolate Pickle at 9:39 PM on October 6, 2009

Looking at XenonMKV, its just a frontend for existing utilities.

This would be my process, easily scriptable.

1. Use tsMuxer to extract the video stream and the audio track(s) into separate files.
2. Reencode the audio track into AAC with afconvert (comes with OS X, looking at the man page it supports most 2ch and 5.1ch formats)
3. Use mp4box to mux the video and audio into a single MP4 file.
posted by wongcorgi at 10:34 PM on October 6, 2009

mencoder -o <new file name> -oac copy -ovc copy -of lavf -lavfopts format=mp4 <old file name>

Should do the job. This program will help turn that shellscript into a drag and drop app you can drop your movie files into.
posted by idiopath at 2:33 PM on October 7, 2009

« Older How to repair a leaking water valve?   |   A thin line between love & hate? Newer »
This thread is closed to new comments.