6

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.

7

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.

  • Thank you for your help. I did exactly as you suggest but it does nothing. I do have the service available on Finder as intended but when I select an mkv file and run the service, it does nothing. :( – TheLearner May 7 '14 at 14:46
  • Never mind, I figured it out. Just replaced "$fbname" with "${f%.*}.mp4" as suggested by Lauri Ranta. Damn, I wish I could accept both answers because both were equally helpful to my workaround! – TheLearner May 7 '14 at 15:22
4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .