HEVC Hardware Acceleration in FFmpeg on macOS

This article provides a quick and direct guide on how to utilize macOS’s native VideoToolbox framework to perform hardware-accelerated HEVC (H.265) decoding and encoding using FFmpeg. By leveraging your Mac’s dedicated graphics hardware (Apple Silicon or Intel Quick Sync), you can significantly reduce CPU load and drastically speed up video transcoding times.

Prerequisites

To use hardware acceleration on macOS, you must have FFmpeg installed with VideoToolbox support. You can easily install it using Homebrew:

brew install ffmpeg

To verify that your FFmpeg installation supports VideoToolbox, run the following commands in your terminal:

# Check for hardware-accelerated decoders
ffmpeg -decoders | grep videotoolbox

# Check for hardware-accelerated encoders
ffmpeg -encoders | grep videotoolbox

You should see hevc_videotoolbox listed in both outputs.

The Transcoding Command

To transcode a video using both hardware-accelerated decoding and encoding, use the following FFmpeg command structure:

ffmpeg -hwaccel videotoolbox -i input.mp4 -c:v hevc_videotoolbox -c:a copy output.mp4

Command Breakdown:

Controlling Output Quality and Bitrate

Hardware encoders handle rate control differently than software encoders like x265. To control the quality and size of your output file, you can specify a target bitrate or a quality profile.

Specify a target bitrate using the -b:v flag. For example, to set the video bitrate to 5 Megabits per second (5000k):

ffmpeg -hwaccel videotoolbox -i input.mp4 -c:v hevc_videotoolbox -b:v 5000k -c:a aac output.mp4

Method 2: Constant Quality

You can use the -q:v flag to set a quality factor. For VideoToolbox, this is a scale from 1 to 100, where higher numbers represent better quality:

ffmpeg -hwaccel videotoolbox -i input.mp4 -c:v hevc_videotoolbox -q:v 65 -c:a aac output.mp4