AppleScript Code for Converting an AVI to an MP4 in QuickTime Pro
Monday, November 19th, 2007Anther Simple Answer to a Specific Quesion:
As part of my ongoing obsession with converting and storing video on the Mac, one of the obvious tools I’ve looked at for converting from .avi files .mp4 files QuickTime. Assuming you can get your video to play (hint: http://www.divx.com/), Quicktime Pro has an Export feature that produces very acceptable video using the H.264 codec.
Since there didn’t seem to be any mechanism for batch processing, I looked into using Applescript to automate the task. I found numerous examples online that almost did what I needed, but nothing that was exactly right. In every case, the format was wrong, and the script in question did way more than I wanted. So here’s the bare bones, stripped down AppleScript code for…
…saving MPEG4 export settings to an external file:
tell app "QuickTime Player" tell first movie save export settings for MPEG4 to file "Users:yourname:MPEG4 Settings" end tell end tell
…and converting an .avi file to an .mp4 using a saved external settings file:
tell application "QuickTime Player" activate close every window end tell tell application "QuickTime Player" open "Data:Upload:Harvey Birdman - 4x02 - Incredible Hippo.avi" if (can export front movie as MPEG4) then set theTime to duration of front movie with timeout of theTime seconds export front movie to ("Data:Upload:Harvey Birdman - 4x02 - Incredible Hippo.mp4") as MPEG4 using settings file "Users:yourname:MPEG4 Settings" end timeout end if end tell quit application "Quicktime Player"