Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

worldomination

macrumors member
Original poster
Jun 28, 2014
59
9
I have a lot of files to process... over five hundred.

It would be helpful to speed things up a bit.

I'm extracting each movie's audio file in terminal using ffmpeg.

Is it possible to create an application to help with this?

  1. open Terminal
  2. type ffmpeg -i
  3. ask for the movie file
  4. type -vn
  5. automatically output an audio file with the movie's name in the same directory
Is this possible?
 

bogdanw

macrumors 603
Mar 10, 2009
5,746
2,768
Something like this:
Code:
set theInputFile to POSIX path of (choose file of type {"mp4", "mov", "mkv", "m4v"} with prompt "Choose a video file")
set theFileName to name of (info for theInputFile)
--set theOutputFolder to POSIX path of (choose folder with prompt "Please select an output folder:")
set theOutputFolder to POSIX path of theInputFile
set theCom to "/usr/local/bin/ffmpeg -i " & theInputFile & " -vn " & theOutputFolder & "_audio" & ".m4a"
tell application "Terminal"
    do script theCom
    activate
end tell
I left an option to select a different output folder.
 

worldomination

macrumors member
Original poster
Jun 28, 2014
59
9
Thank you for your your reply!

I modified your script through a little trial and error...

Code:
set theInputFile to POSIX path of (choose file of type {"mp4", "mov", "mkv", "m4v"} with prompt "Choose a video file")
set theOutputFolder to POSIX path of theInputFile
set theCom to "ffmpeg -i " & theInputFile & " -vn " & theOutputFolder & "_audio" & ".eac3"
tell application "Terminal"
    do script theCom
    activate
end tell

This might just work.

However, Terminal is inputing and outputing the path as...

Code:
/Volumes/Elite Pro Duo/movie.mp4

When it ought to be...

Code:
/Volumes/Elite\ Pro\ Duo/movie.mp4

...and I receive an error... unknown file attribute: 2.

Is there a way to change this?
 

bogdanw

macrumors 603
Mar 10, 2009
5,746
2,768
This shoud work for files/folders with spaces in the name
Code:
set theInputFile to POSIX path of (choose file of type {"mp4", "mov", "mkv", "m4v"} with prompt "Choose a video file")
set theOutputFolder to POSIX path of theInputFile
set theCom to "ffmpeg -i " & quoted form of theInputFile & " -vn " & quoted form of theOutputFolder & "_audio" & ".eac3"
tell application "Terminal"
    do script theCom
    activate
end tell
It can be done as an Automator service with run Shell Script
Code:
for f in "$@"
do
/usr/local/bin/ffmpeg -i "$f" -vn "${f%.*}.eac3"
done
 
  • Like
Reactions: worldomination

worldomination

macrumors member
Original poster
Jun 28, 2014
59
9
Thank you, bogdanw!

There's no way I could have figured out that on my own.

I don't understand what to do with the second part... Automator service with run Shell Script...

I was able to save the script as an application, though, and that works great. A HUGE time saver.

Cheers!
 
Last edited:

bogdanw

macrumors 603
Mar 10, 2009
5,746
2,768
Glad to help and learn, I didn't know about the -vn option.
An improved AppleScript
Code:
set theInputFile to (choose file of type "public.movie" with prompt "Choose a video file")
set theFileName to name of (info for theInputFile)
tell application "Finder" to set theOutputFolder to POSIX path of ((container of theInputFile) as text)
set theCom to "ffmpeg -i " & quoted form of (POSIX path of theInputFile) & " -vn " & quoted form of (theOutputFolder & theFileName) & ".eac3"
tell application "Terminal"
    do script theCom
    activate
end tell

Sorry about the second part, I should have said QuickAction https://support.apple.com/guide/automator/aut73234890a/mac
and it looks like this

Video2Audio.jpg

It doesn't start Terminal, but does the job in the background. It's probably more useful for small files, rather than large ones where you probably want to see the progress in Terminal.
 

Marty_Macfly

macrumors 6502a
Apr 26, 2020
952
269
Glad to help and learn, I didn't know about the -vn option.
An improved AppleScript
Code:
set theInputFile to (choose file of type "public.movie" with prompt "Choose a video file")
set theFileName to name of (info for theInputFile)
tell application "Finder" to set theOutputFolder to POSIX path of ((container of theInputFile) as text)
set theCom to "ffmpeg -i " & quoted form of (POSIX path of theInputFile) & " -vn " & quoted form of (theOutputFolder & theFileName) & ".eac3"
tell application "Terminal"
    do script theCom
    activate
end tell

Sorry about the second part, I should have said QuickAction https://support.apple.com/guide/automator/aut73234890a/mac
and it looks like this

View attachment 1772495
It doesn't start Terminal, but does the job in the background. It's probably more useful for small files, rather than large ones where you probably want to see the progress in Terminal.

nice! ?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.