Automating ffmpeg using Automator Service
I often use ffmpeg off the command line to convert video files into mp4 on my Mac (running Mavericks). Do note, however, that I am NOT re-encoding my videos; am just changing the container from an avi or an mkv to an mp4. The exact command I run on Terminal is as follows:
/Users/Amit/Documents/Scripts/ffmpeg -i /input.mkv -c:v copy -c:a copy /output.mp4
As can be seen, this involves a lot of typing (for example, the entire path for ffmpeg and the source and target videos) and since I do a lot of such conversions, it would be great to have some Automator help here.
So, how can one go about creating a Finder Service that automates this activity? I would prefer a Finder Service instead of a standalone app or menu item.
Solution 1:
Automator Service
You can use Automator to create a new service or droplet:
- Launch Automator.app
- Create a new service with service receives files or folders in any application
- Add a Run Shell Script action
- Set Pass input: to as arguments
- Within the script, replace
echo
with the script below. - Save your workflow as a service.
Shell Script
for f in "$@"
do
/Users/Amit/Documents/Scripts/ffmpeg -i "$f" -c:v copy -c:a copy "${f%.*}.mp4"
done
To learn more about using Automator, see Apple's Mac Basics: Automator.
Solution 2:
You could also add a function like this to a shell configuration file like ~/.bash_profile
:
mp4() {
for f; do
ffmpeg -i "$f" -c copy "${f%.*}.mp4"
done
}
Then you can just run mp4 input.mkv
.
You can replace /Users/Amit/Documents/Scripts/ffmpeg
with just ffmpeg
if you move ffmpeg
somewhere like /usr/bin
or if you add PATH=~/Documents/Scripts:$PATH
to ~/.bash_profile
.