12 January 2007 @ 16:59AppleScript and video transcoding
I know there are solutions out there for video transcoding such as the awesome ffmpegX, but I wanted to make my own solution. I drop my source video onto this droplet, and with just a few button clicks, I can convert almost any video to an mpeg2 that is DVD compliant. What I did here was make an AppleScript droplet which is an application bundle and contains the binaries, ffmpeg, pulldown, and mplex. Pulldown and mplex are necessary if you are starting with a 23.98fps source and want to keep it at that rate.
Things you’ll need:
- Script Editor
- ffmpeg binary
- pulldown binary
- mplex binary
property video : ""
property aspect : ""
property audio : ""
property fr_rate : ""
property resize : ""
property padtop : ""
property padbottom : ""
on open these_files
repeat with this_file in these_files
set ffmpeg_binary to ((path to me) as string)
set ffmpeg_binary to (ffmpeg_binary & "Contents:Resources:ffmpeg")
set ffmpeg_binary to (POSIX path of ffmpeg_binary)
set pulldown_binary to ((path to me) as string)
set pulldown_binary to (pulldown_binary & "Contents:Resources:pulldown")
set pulldown_binary to (POSIX path of pulldown_binary)
set mplex_binary to ((path to me) as string)
set mplex_binary to (mplex_binary & "Contents:Resources:mplex")
set mplex_binary to (POSIX path of mplex_binary)
set theuser to (do shell script "echo $USER")
set ginfo to (get info for this_file)
set disp_name to text 1 thru -((length of name extension of ginfo) + 2) of name of ginfo
set disp_name2 to name of ginfo
set POSIX_file to POSIX path of this_file
display dialog "Select target video format" buttons {"NTSC-FILM", "NTSC"} default button 2
if button returned of the result is "NTSC" then
set the video to "ntsc"
display dialog "Aspect ratio?" buttons {"4:3", "16:9"} default button 2
if button returned of the result is "4:3" then
set the aspect to "4:3"
else
set the aspect to "16:9"
end if
display dialog "Resize to what size?" default answer resize
set the resize to text returned of result
display dialog "Pad top amount?" default answer padtop
set the padtop to text returned of result
display dialog "Pad bottom amount?" default answer padbottom
set the padbottom to text returned of result
display dialog "Copy existing audio track or encode in AC3 stereo?" buttons {"AC3 stereo", "Copy"} default button 2
if button returned of the result is "AC3 stereo" then
set the audio to "ac3 -ac 2 -ar 48000 -ab 192"
else
set the audio to "copy"
end if
with timeout of 30000 seconds
tell application "Terminal"
do script ("\"" & ffmpeg_binary & "\" -i \"" & POSIX_file & "\" -target " & video & "-dvd -aspect " & aspect & " -s " & resize & " -padtop " & padtop & " -padbottom " & padbottom & " -acodec " & audio & " \"" & POSIX_file & ".mpg\"")
end tell
end timeout
else
set the video to "film"
display dialog "Aspect ratio?" buttons {"4:3", "16:9"} default button 2
if button returned of the result is "4:3" then
set the aspect to "4:3"
else
set the aspect to "16:9"
end if
display dialog "Resize to what size?" default answer resize
set the resize to text returned of result
display dialog "Pad top amount?" default answer padtop
set the padtop to text returned of result
display dialog "Pad bottom amount?" default answer padbottom
set the padbottom to text returned of result
display dialog "Copy existing audio track or encode in AC3 stereo?" buttons {"AC3 stereo", "Copy"} default button 2
if button returned of the result is "AC3 stereo" then
set the audio to "ac3 -ac 2 -ar 48000 -ab 192"
else
set the audio to "copy"
end if
with timeout of 30000 seconds
tell application "Terminal"
do script ("\"" & ffmpeg_binary & "\" -i \"" & POSIX_file & "\" -target " & video & "-dvd -aspect " & aspect & " -s " & resize & " -padtop " & padtop & " -padbottom " & padbottom & " -an -f mpeg2video \"" & POSIX_file & ".m2v\"; \"" & ffmpeg_binary & "\" -i \"" & POSIX_file & "\" -vn -acodec " & audio & " -f ac3 \"" & POSIX_file & ".ac3\"; \"" & pulldown_binary & "\" \"" & POSIX_file & ".m2v\" \"" & POSIX_file & ".pull.m2v\"; rm \"" & POSIX_file & ".m2v\"; \"" & mplex_binary & "\" -f 8 -o \"" & POSIX_file & ".final.mpg\" \"" & POSIX_file & ".pull.m2v\" \"" & POSIX_file & ".ac3\"; rm \"" & POSIX_file & ".pull.m2v\";rm \"" & POSIX_file & ".ac3\"")
end tell
end timeout
end if
end repeat
delay 3
end open
After ffmpeg finishes its work, you have an mpeg2 file that you can burn to dvd with your favorite authoring program. Personally, I use dvdauthor.
by Jon | Add a comment | Tags: applescript, ffmpeg
Posted in applescript, ffmpeg, mac, mplex, pulldown, transcode, video | Link to this