Skip to content

Commit e11ebd1

Browse files
committed
Can't remember where I got the original script, i have made a couple of small changes.
Basically it converts AVI to mp4 using handbrake on your mac
1 parent cafd576 commit e11ebd1

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

avi_handbrake_conversion.applescript

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Script Name : avi_handbrake_conversion
2+
# Author : Craig Richards
3+
# Created : 23rd November 2012
4+
# Last Modified : 11th February 2013
5+
# Version : 2.0
6+
7+
# Modifications : 2.0 - CR - Added the section at the end of the script to display the prompt box once the files have been created
8+
9+
# Description : This will convert all AVI videos to mp4 format. You will just need a folder to_convert on your desktop, drop the files in there and run the script
10+
11+
with timeout of (720 * 60) seconds
12+
tell application "System Events"
13+
set currentUser to (name of current user)
14+
end tell
15+
16+
tell application "Finder"
17+
--Get all AVI and MKV files that have no label color yet, meaning it hasn't been processed
18+
set allFiles to every file of entire contents of folder "to_convert" of folder "Desktop" of folder currentUser of folder "Users" of startup disk whose ((name extension is "avi" or name extension is "mkv") and label index is 0)
19+
20+
--Repeat for all files in above folder
21+
repeat with i from 1 to number of items in allFiles
22+
set currentFile to (item i of allFiles)
23+
24+
try
25+
--Set to gray label to indicate processing
26+
set label index of currentFile to 7
27+
28+
--Assemble original and new file paths
29+
set origFilepath to quoted form of POSIX path of (currentFile as alias)
30+
set newFilepath to (characters 1 thru -5 of origFilepath as string) & "mp4'"
31+
32+
--Start the conversion
33+
set shellCommand to "nice /Applications/HandBrakeCLI -i " & origFilepath & " -o " & newFilepath & " -e x264 -b 4000 -a 1 -E faac -B 160 -R 48 -6 dpl2 -f mp4 --crop 0:0:0:0 -x level=40:ref=2:mixed-refs:bframes=3:weightb:subme=9:direct=auto:b-pyramid:me=umh:analyse=all:no-fast-pskip:filter=-2,-1 ;"
34+
do shell script shellCommand
35+
36+
--Set the label to green in case file deletion fails
37+
set label index of currentFile to 6
38+
39+
--Remove the old file
40+
set shellCommand to "rm -f " & origFilepath
41+
do shell script shellCommand
42+
on error errmsg
43+
--Set the label to red to indicate failure
44+
set label index of currentFile to 2
45+
end try
46+
end repeat
47+
end tell
48+
end timeout
49+
50+
-- Display dialog box after the conversions
51+
52+
display dialog "The Script has finished - http://www.thegeekblog.co.uk" with icon 1 buttons {"OK", "Visit Site", "Send Email"}
53+
if result = {button returned:"Visit Site"} then
54+
tell application "Safari"
55+
tell window 1
56+
set current tab to (make new tab with properties {URL:"http://www.thegeekblog.co.uk"})
57+
end tell
58+
end tell
59+
else if result = {button returned:"Send Email"} then
60+
tell application "Mail"
61+
set theNewMessage to make new outgoing message with properties {subject:"Subject text", content:"Script Feedback", visible:true}
62+
tell theNewMessage
63+
make new to recipient at end of to recipients with properties {address:"[email protected]"}
64+
--send -- uncomment this line if you want the email to automatically send
65+
end tell
66+
end tell
67+
end if

0 commit comments

Comments
 (0)