I am trying to run ffmpeg from applescript. I’ve run a single conversion using do shell script and it worked perfectly. Now I am trying to make a droplet. I a complete noobie and have been cutting up scripts I found on these posts to get bye to date. Any help would be great. the goal is to convert a video mp4 file to mp3 audio.
on open droppedItems
repeat with thisItem in droppedItems
tell application "Finder" to set this_name to name of thisItem
do shell script "ffmpeg -i " & this_name & " /Users/Nevin/Movies/convert/" & this_name & ".mp3"
end repeat
end open
I’m not familiar with ffmpeg, but I would try something like this:
property outputFolder : ((path to movies folder as Unicode text) & "convert:")
on open droppedItems
repeat with thisItem in droppedItems
get name of (info for thisItem without size)
set outputFile to POSIX path of (outputFolder & result & ".mp3")
set inputFile to POSIX path of thisItem
do shell script "ffmpeg -i " & quoted form of inputFile & space & quoted form of outputFile
end repeat
end open
I think the only real problem with your script is the do shell script line. Do shell script starts at the root of your hard drive, so you need to give it the full path to the input file. However, you only give it the name of a file.
WOW!! that was fast. Never had a response within 24hrs. Thanks Bruce it worked beautifully. Just one question. When I run it with a file named ffmpeg.mp4 it creates a file named ffmpeg.mp4.mp3. Is there any way to remove the mp4 extension from the name?
Again BIG thanks for the help!!!
Try this:
property outputFolder : ((path to movies folder as Unicode text) & "convert:")
on open droppedItems
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
repeat with thisItem in droppedItems
get name of (info for thisItem without size)
try
get text 1 thru text item -2 of result
on error
get result
end try
set outputFile to POSIX path of (outputFolder & result & ".mp3")
set inputFile to POSIX path of thisItem
try
do shell script "ffmpeg -i " & quoted form of inputFile & space & quoted form of outputFile
on error errorMsg number errorNum
set AppleScript's text item delimiters to ASTID
display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
end try
end repeat
set AppleScript's text item delimiters to ASTID
end open
Again worked perfectly Bruce. Is there a simple way to change to work for all videos droped in a folder? I tried to drop 2 files on the droplet and it only produced one mp3.