Right-Click to Compress Videos on Mac

As a developer, I frequently find myself needing to compress screen recordings and videos to meet file size requirements. Whether it's uploading to GitLab (10MB limit), uploading videos to Confluence, or sharing demos with teammates, video compression is a regular part of my workflow.

The typical approach involves uploading videos to online compression services, waiting for processing, then downloading the compressed result. This workflow is inefficient — you're uploading large files, consuming bandwidth twice, and depending on internet connectivity.

There's a better way. You can compress videos locally on your Mac and make it as simple as a right-click. This guide shows you how to create a custom macOS workflow using HandBrake CLI that integrates directly into Finder's context menu.

Here's a quick demo of the workflow in action:

Why This Approach Works

  • Local processing: No internet required, your files never leave your machine
  • Faster workflow: Right-click → compress → done
  • Consistent quality: Reliable compression settings every time
  • Batch processing: Select multiple files and compress them all at once
  • Privacy: Your videos stay on your local machine

Prerequisites

Before we start, you'll need to install HandBrake CLI. HandBrake is a popular open-source video transcoder that's more user-friendly than FFmpeg for this use case.

Install HandBrake CLI

# Using Homebrew (recommended)
brew install handbrake

# Verify installation
which HandBrakeCLI

The installation path will typically be:

  • Apple Silicon Macs: /opt/homebrew/bin/HandBrakeCLI
  • Intel Macs: /usr/local/bin/HandBrakeCLI

Creating the Workflow

Now let's create a custom macOS workflow using the built-in Automator application.

Step 1: Open Automator

  1. Press Cmd + Space and search for "Automator"
  2. Click "New Document"
  3. Select "Quick Action" (formerly called Service)
  4. Click "Choose"

Step 2: Configure Workflow Settings

In the workflow configuration:

  1. Set "Workflow receives current" to files or folders
  2. Set "in" to Finder
  3. Leave "Image" as the icon (or choose your preferred icon)

Step 3: Add the Shell Script Action

  1. In the Actions library, search for "Run Shell Script"
  2. Drag "Run Shell Script" to the workflow area
  3. Set "Pass input" to as arguments
  4. Replace the default script with our compression script

Step 4: Add the Compression Script

Copy and paste this script into the shell script action:

Video Compression Script
#!/bin/bash

# This script compresses videos using HandBrake CLI
# It processes every file you select in Finder

for f in "$@"
do
    # Check if HandBrakeCLI exists
    HANDBRAKE_PATH=""
    
    # Common installation paths
    if [ -f "/opt/homebrew/bin/HandBrakeCLI" ]; then
        HANDBRAKE_PATH="/opt/homebrew/bin/HandBrakeCLI"
    elif [ -f "/usr/local/bin/HandBrakeCLI" ]; then
        HANDBRAKE_PATH="/usr/local/bin/HandBrakeCLI"
    else
        # Try to find it in PATH
        HANDBRAKE_PATH=$(which HandBrakeCLI)
    fi
    
    # Check if HandBrake was found
    if [ -z "$HANDBRAKE_PATH" ]; then
        osascript -e 'display notification "HandBrakeCLI not found. Please install via: brew install handbrake" with title "Video Compression Error"'
        exit 1
    fi
    
    # Get file info
    filename=$(basename "$f")
    directory=$(dirname "$f")
    name="${filename%.*}"
    
    # Create output filename
    output_file="${directory}/${name}compressed.mp4"
    
    # Show notification that compression started
    osascript -e "display notification \"Starting compression of $filename\" with title \"Video Compression\""
    
    # Run HandBrake compression
    # Parameters explained:
    # -i: input file
    # -o: output file
    # --modulus 2: ensures width/height are even numbers (required for some codecs)
    # --rate 30: limit frame rate to 30fps (reduces file size)
    # --vb 2000: video bitrate of 2000 kbps (adjust for quality vs size)
    # --ab 128: audio bitrate of 128 kbps
    # --encoder x264: use H.264 codec for broad compatibility
    "$HANDBRAKE_PATH" -i "$f" -o "$output_file" \
        --encoder x264 \
        --vb 2000 \
        --ab 128 \
        --rate 30 \
        --modulus 2 \
        --optimize \
        2>/dev/null
    
    # Check if compression was successful
    if [ $? -eq 0 ]; then
        # Get file sizes for notification
        original_size=$(du -h "$f" | cut -f1)
        compressed_size=$(du -h "$output_file" | cut -f1)
        osascript -e "display notification \"$filename compressed successfully! $original_size$compressed_size\" with title \"Video Compression Complete\""
    else
        osascript -e "display notification \"Failed to compress $filename\" with title \"Video Compression Error\""
    fi
done

Step 5: Save the Workflow

  1. Press Cmd + S to save
  2. Name it "Compress Video" (this will be the name that appears in the right-click menu)
  3. Click "Save"

Understanding the Script Logic

Let's break down what the script does:

File Processing Loop

for f in "$@"

This loops through all selected files passed to the script as arguments.

HandBrake Detection

if [ -f "/opt/homebrew/bin/HandBrakeCLI" ]; then
    HANDBRAKE_PATH="/opt/homebrew/bin/HandBrakeCLI"

The script automatically detects where HandBrakeCLI is installed, checking common locations for both Apple Silicon and Intel Macs.

File Naming

output_file="${directory}/${name}compressed.mp4"

Creates a new filename by adding "compressed" to the original name, ensuring you don't overwrite your original files.

Note that I didn't add a delimiter such as an underscore _ or hyphen - to the compressed filename. This way, the compressed file appears directly after the original file in the folder. If you use a delimiter, the compressed file will show up before the original, which I find less intuitive. It's a small detail, but feel free to adjust it to your preference.

Compression Settings

The HandBrake parameters are optimized for a good balance of file size and quality:

  • --encoder x264: Uses H.264 codec for maximum compatibility
  • --vb 2000: Video bitrate of 2000 kbps (adjust higher for better quality, lower for smaller files)
  • --ab 128: Audio bitrate of 128 kbps (good quality for most content)
  • --rate 30: Limits frame rate to 30fps (reduces file size significantly for high-fps recordings)
  • --modulus 2: Ensures even pixel dimensions (required for proper encoding)
  • --optimize: Enables additional compression optimizations

User Notifications

osascript -e "display notification \"...\" with title \"...\""

Shows macOS notifications to keep you informed about the compression progress and results.

Using Your New Workflow

Once saved, your workflow is ready to use:

  1. Navigate to any video file in Finder
  2. Right-click on the video file(s) you want to compress
  3. Select "Compress Video" from the context menu
  4. Wait for the notification indicating completion
  5. Find your compressed video in the same folder with "compressed" added to the filename

You can select multiple video files and compress them all at once — the script will process each one sequentially.

Customizing Compression Settings

You can modify the HandBrake parameters to suit your needs:

For Smaller File Sizes

# Lower bitrates for maximum compression
--vb 1000 --ab 96 --rate 24

For Higher Quality

# Higher bitrates for better quality
--vb 3000 --ab 192 --rate 60

For Specific Use Cases

# GitLab-optimized (targets ~5MB for typical recordings)
--vb 800 --ab 64 --rate 24 --maxWidth 1280

# Web-optimized
--vb 1500 --ab 128 --rate 30 --encoder x264 --optimize

Conclusion

This workflow transforms video compression from a tedious multi-step process into a simple right-click action. It's particularly valuable for developers who regularly work with screen recordings, demo videos, and need to meet file size constraints for various platforms.

The local processing approach is not only more efficient but also more secure since your videos never leave your machine. Plus, once set up, it saves considerable time compared to online compression services.

Next time you need to compress a video for GitLab, email, or any other platform with file size limits, just right-click and compress. It's that simple.

Have you tried this workflow? Let me know how it works for your use case or if you have suggestions for improvements!