Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript droplet to convert video audio

Hi Everyone,


I'm sorry if this is a silly question, but I need to create a droplet for files at work that we need to convert.

At the moment we use ffmpeg in the command line but its very taxing when we need to do multiple files.


Ideally we need a app we can drop files on to that performs a shell script. I've had a play but haven't had any luck creating it.


We use this in terminal to achieve what we need normally.


ffmpeg -i /Pathtosource -acodec aac -vcodec copy /pathtooutput (its usually in the same folder just with a "conv" in the file name.


any help would be much appreciated.


Thanks

Posted on Apr 3, 2016 9:25 PM

Reply
6 replies

Apr 3, 2016 10:27 PM in response to v0elkl

It isn't entirely clear to me what it is you're asking...


I *think* you're asking for an AppleScript wrapper that will launch an ffmpeg task to convert the file(s). That's pretty straightforward, but it won't make any difference to your initial concern over ffmpeg being 'very taxing'. ffmpeg, by its nature, will use as much CPU power as it can garner. Launching manually in Terminal.app, or via an AppleScript won't change that.


That said, if you want an AppleScript wrapper, something like this should get you started:


on opentheseFiles

repeat with eachFile in theseFiles

set sourceFile to POSIX path of eachFile

do shell script "ffmpeg -i " & quoted form of sourceFile & " -acodec aac -vcodec copy " & quoted form of POSIX path of sourceFile & ".conv"

end repeat

end open

The 'quoted form of...' syntax takes care of quoting the paths to make sure they're shell-safe (spaces, extended characters, etc.).


There are also several caveats here. For one there's no check that the files are actually valid audio/video files, although then ffmpeg would presumably fail gracefully. You could add checks if required.

Also, the script is set to run serially - transcode each document in turn. If you want them to run in parallel, a simple change is needed.

Additionally, large files may take a long time to transcode, so you run the risk of the command timing out. Again, a simple change here can take care of that if you run into this problem.

May 1, 2016 9:15 PM in response to Camelot

Hi Camelot,


When i run this i get this

User uploaded file

It can't find the path to ffpmeg, so i amended the script to include that. like this;


on opentheseFiles

repeat with eachFile in theseFiles

set sourceFile to POSIX path of eachFile

set convertPath to "/usr/local/Cellar/ffmpeg/3.0/bin/ffmpeg"


do shell scriptconvertPath & " -i " & quoted form of sourceFile & " -acodec aac -vcodec copy " & quoted form of POSIX path of sourceFile & ".conv"

end repeat

end open


It Now when you drop the files onto the applet i get this message and nothing happens.User uploaded file


Any help would be appreciated. Thanks


May 1, 2016 9:36 PM in response to v0elkl

What you're seeing is the output of the ffmpeg command. Usually that's indicative of some problem with the switches/input, but in this case it looks like ffmpeg is displaying information about the input file. The good news is that it indicates the script is running and the file is getting parsed in correctly. I'm not an ffmpeg expert, though, to know what other of the switches you may need to amend.


The litmus test would be to manually run the command in a shell and see what happens there. I'd expect the same result, so you'll need to dig into ffmpeg to work out what changes to make.

May 2, 2016 6:25 AM in response to v0elkl

The syntax that I added does not change the execution of the preceding command string, it only redirects what would be normal Terminal output from ffmpeg to a log file. I tested that redirection syntax in a do shell script here (not with ffmpeg), and it worked fine. Carefully recheck the syntax that you typed at the end of your do shell script. In fact, post what you have back here.


The path to your log file must be a real POSIX path, and if that path has white space in it, you will need to ensure that it is quoted, or the script will fail. Omitting an '&' or unbalanced quotes will terminate the do shell script.

Applescript droplet to convert video audio

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.