VideoToolbox HEVC Hardware Encoding in FFmpeg
This article provides a practical guide on utilizing Apple's VideoToolbox framework to achieve fast, hardware-accelerated HEVC (H.265) video encoding using FFmpeg on macOS. It covers verifying system support, fundamental encoding commands, managing video quality and bitrates, enabling 10-bit color, and ensuring compatibility with Apple ecosystem players like QuickTime.
Verifying VideoToolbox Support
Before encoding, verify that your FFmpeg build includes VideoToolbox support. Run the following command in Terminal:
ffmpeg -encoders | grep videotoolboxLook for hevc_videotoolbox in the output. If it appears,
your installation is ready to use hardware acceleration on your Apple
Silicon or supported Intel Mac.
Basic HEVC Encoding Command
To encode a video to HEVC using the hardware encoder, set the video
codec flag (-c:v) to hevc_videotoolbox.
ffmpeg -i input.mp4 -c:v hevc_videotoolbox -c:a copy output.mp4This command copies the audio stream without re-encoding and compresses the video stream using the default VideoToolbox HEVC settings.
Controlling Output Quality and Bitrate
VideoToolbox handles rate control differently than software encoders
like libx265. Traditional Constant Rate Factor (CRF) is not
supported; instead, you use quality-based variable bitrate or target
bitrates.
Variable Bitrate via
Quality Scale (-q:v)
You can set a quality target using a scale from 1 to 100, where higher values yield better visual quality at the expense of larger file sizes:
ffmpeg -i input.mp4 -c:v hevc_videotoolbox -q:v 65 -c:a copy output.mp4A value between 50 and 75 is typically suitable for general video preservation and web sharing.
Target Bitrate (-b:v)
If you need to hit a specific file size or bandwidth limit, specify an explicit average bitrate:
ffmpeg -i input.mp4 -c:v hevc_videotoolbox -b:v 4M -c:a copy output.mp4Apple Ecosystem
Compatibility (-tag:v hvc1)
By default, FFmpeg may tag HEVC streams as hev1, which
causes playback issues in Apple QuickTime, Finder preview, and iOS
devices. Always append -tag:v hvc1 when encoding for Apple
devices:
ffmpeg -i input.mp4 -c:v hevc_videotoolbox -q:v 65 -tag:v hvc1 -c:a copy output.mp410-Bit Color Encoding
Hardware-accelerated 10-bit encoding reduces color banding in
gradients and is required for HDR workflows. Specify the 10-bit pixel
format (p010le):
ffmpeg -i input.mp4 -c:v hevc_videotoolbox -pix_fmt p010le -q:v 70 -tag:v hvc1 -c:a copy output.mp4Performance Profiles
VideoToolbox provides profiles to optimize for specific use cases:
- Main Profile (8-bit default):
-profile:v main - Main 10 Profile (10-bit):
-profile:v main10
Additionally, you can toggle -realtime true if you are
streaming live content, though omitting it yields better compression
efficiency for offline file encoding.