ffmpeg runs exactly like I want it to. I'm sure the following is not super clean but it does work with one exception: it simply adds the .mp4 to the original filename so that the new filename appears to have two extensions.
I've spent days searching for similar problems on multiple forums with no real help. I've tried copying and pasting suggestions with different errors. I would really like to drag a video file onto this applet and have it run ffmpeg the way I've specified in the shell portion with the resulting output file being created in the location of the input file but with a different extension.
I've tried the "filesString" way and the \"f\" + "{$f%.*}" and for whatever reason that doesn't seem to do anything but open terminal with the text of the shell. Other options result in a message stating that there's "NO SUITABLE OUTPUT" which I have finally figured out means, "whatever you're doing is great, but I'm going to give you this error until you take the spaces out of your file name/folders."
So:
-
To drop a file and have it convert to file with the standards specified. (check)
-
Have that output file go back to the folder where the input file lives. (check)
-
But with only the new extension. (fail)
-
A bonus would be to edit the script such that I could drop a folder of files onto the applet and have them convert 1 at a time. I believe I can drop a folder at this time but then it opens multiple instances of Terminal and processes simultaneously. I'd like to have the files process 1 at a time.
on run {input, parameters}
repeat with file_ in input
tell application "System Events"
set inputFilename to name of (get properties of file_)
end tell
set inputFilePath to quoted form of (POSIX path of file_)
set outputFilePath to quoted form of (POSIX path of file_)
tell application "Terminal"
activate
do script "/usr/local/Cellar/ffmpeg/3.0.2/bin/ffmpeg -i " & inputFilePath & " -aspect 4:3 -vf yadif=0:-1:0,scale=720:486 -acodec libfdk_aac -cutoff 20000 -vcodec libx264 -preset medium -pix_fmt yuv420p " & outputFilePath & ".mp4"
end tell
end repeat
return input
end run
Best Answer
This takes care of number 3, the double file extension issue.
I've modified the code below from your original code in the following ways:
Added the
remove_extension(this_name)
subroutine from the bottom of the Essential Sub-routines page.Changed:
To:
Removed
& ".mp4"
from the end of thedo script ...
line.I then tested it on an actual
.mkv
file and while the process started, nonetheless I did stop it shortly there after, as it was just a test to see the originalfilename.mkv
was writing tofilename.mp4
, and it was.If you want to use the
AppleScript's text item delimiters
method, wrapped in a subroutine, then replace the existingon remove_extension(this_name)
subroutine with the following one, while leaving the others changes I made to your code as I did.This is essentially doing the same as the original
on remove_extension(this_name)
subroutine I first used, it's just a different method using what was mentioned in user14492's answer, only presented in what I'd consider to be a more proper form.