Automating ffmpeg using Automator Service

applescriptautomatorfinderterminalvideo

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.

Best Answer

Automator Service

You can use Automator to create a new service or droplet:

  1. Launch Automator.app
  2. Create a new service with service receives files or folders in any application
  3. Add a Run Shell Script action
  4. Set Pass input: to as arguments
  5. Within the script, replace echo with the script below.
  6. 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

Automator ffmpeg

To learn more about using Automator, see Apple's Mac Basics: Automator.