Optimising Video with Apple Shortcuts in MacOS

By Fernando Obregon

September 26, 2024 at 11:15

mac-tips handbrake mac video-optimisation

Introduction

At Tapadoo we use videos a lot during development. This might be to demonstrate how to test something, to highlight incorrect app behaviour, or to guide a client through a new feature. It is important to remember that not all of our clients have a Mac, so they may not have be able to play videos in Apple’s .mov format.

Another thing to keep in mind is that YouTrack has limited memory, and therefore it is important for us to be mindful of the size of our videos.

To solve these two problems we can use an Apple Shortcut that can create a smaller .mp4 version of any video.

Apple Shortcuts?

What is an Apple Shortcut? In Apple’s own words:

A Shortcut provides a quick way to get things done with your apps, with just a click or by asking Siri. Shortcuts can automate a wide variety of things — for example, getting directions to the next event on your Calendar, moving text from one app to another, generating expense reports and more.

Or in our case to convert from one video format to another.

Optimising a video

To optimise a video’s size we will use a tool called HandBrake. This comes as a macOS desktop app, but also includes a terminal program called HandBrakeCLI (where CLI means Command Line Interface). We’re interested in the terminal program, as we need our Shortcut to work without displaying any UI. You can get HandBrakeCLI by following these steps:

  1. Go to Download HandBrake CLI
  2. Download the MacOS Universal
  3. Open the .dmg download and drag HandBrakeCLI. to your desktop.

Next, open your terminal and type the following command to add HandBrakeCLI to the PATH

sudo mv ~/Desktop/HandBrakeCLI /usr/local/bin/HandBrakeCLI

Now, you can optimise any video through your terminal. For example, the following command takes a large 42.7 MB video named forgotemail.mov, and outputs test.mp4 which is only 4.5 MB!

HandBrakeCLI -i forgotemail.mov -o test.mp4

file_size_comparison.png

That was great! We reduced the size of a video by 10X with little to no quality loss.

Do I have to use my terminal? Can I do it from my desktop?

Yes we can! It can be cumbersome having to open your terminal and type the video path and decide which name to give the output. We can simplify this by using an Apple Shortcut. This Shortcut will also provide us with extra functionality:

  1. Optimise a video by pressing right click.
  2. Optimise multiple videos.
  3. Add a -copy suffix to the new video so you can have the original and the copy.
  4. Change .mov videos into .mp4 for better collaboration.
  5. Add the output to your clipboard so you can paste directly into apps like YouTrack and Slack.
  6. A notification to know when the process has finished.

You can get the Shortcut into your Mac by downloading from iCloud, and here’s what the shortcut looks like: shortcut_workflow image

Making a Shortcut available via a file’s context menu

Once you have downloaded and given the requested permissions to the Shortcut, you can add it to the context menu of your videos:

  1. Right click on a video
  2. Press “Quick Actions”
  3. Press “Customise”
  4. Activate “Optimise Video”

Now you can optimise any video by right clicking on it and selecting “Optimise Video”.

Final Result

Now we can enjoy the results of our work: short_in_action

Last updated: September 26, 2024 at 11:15