How to Use h264_videotoolbox in FFmpeg
This article provides a quick guide on how to hardware-accelerate
your video transcoding on macOS using the h264_videotoolbox
encoder in FFmpeg. You will learn the basic command syntax, how to
control bitrate and quality, and how to optimize your encoding workflow
for faster renders using Apple’s native hardware APIs.
What is VideoToolbox?
h264_videotoolbox is an FFmpeg encoder that utilizes
Apple’s VideoToolbox framework. This framework allows FFmpeg to access
the hardware-acceleration capabilities of Mac GPUs and Apple Silicon
chips (M1, M2, M3, etc.). Using this encoder significantly reduces CPU
usage and dramatically speeds up the transcoding process compared to
software encoders like libx264.
Basic Transcoding Command
To transcode a video using the VideoToolbox H.264 encoder, use the
-c:v h264_videotoolbox flag.
ffmpeg -i input.mov -c:v h264_videotoolbox output.mp4In this basic command: * -i input.mov specifies the
input file. * -c:v h264_videotoolbox selects the
hardware-accelerated H.264 encoder. * output.mp4 is the
transcoded output file.
Controlling Quality and Bitrate
Unlike software encoders that use Constant Rate Factor (CRF),
h264_videotoolbox handles quality control primarily through
bitrate flags or a dedicated quality scale.
Method 1: Constant Bitrate (CBR) or Target Bitrate
You can set a specific target bitrate using the -b:v
flag. This is ideal when you need to target a specific file size.
ffmpeg -i input.mov -c:v h264_videotoolbox -b:v 5M output.mp4-b:v 5Msets the video bitrate to 5 Megabits per second (Mbps).
Method 2: Quality-Based Variable Bitrate (VBR)
If you want to prioritize consistent visual quality over a strict
file size, use the -q:v flag.
ffmpeg -i input.mov -c:v h264_videotoolbox -q:v 50 output.mp4-q:vaccepts a value from1to100, where higher numbers yield higher quality (and larger file sizes). A value between50and75is generally recommended for a good balance of quality and file size.
Advanced Configuration Options
Specifying H.264 Profiles
You can specify the H.264 profile to ensure compatibility with older
playback devices using the -profile:v option.
ffmpeg -i input.mov -c:v h264_videotoolbox -profile:v high output.mp4Available profiles include: * baseline (highly
compatible, lower compression efficiency) * main (standard
compatibility) * high (best quality and compression,
recommended for modern devices)
Handling Audio
By default, if you do not specify audio settings, FFmpeg will attempt
to transcode the audio. To copy the audio stream without re-encoding it
(which saves time and preserves quality), use
-c:a copy.
ffmpeg -i input.mov -c:v h264_videotoolbox -b:v 6M -c:a copy output.mp4To transcode the audio to AAC, use -c:a aac:
ffmpeg -i input.mov -c:v h264_videotoolbox -b:v 6M -c:a aac -b:a 192k output.mp4