Transcode Video with FFmpeg hevc_videotoolbox
This article provides a quick guide on how to transcode video files
to the HEVC (H.265) format using the hardware-accelerated
hevc_videotoolbox encoder in FFmpeg. You will learn the
basic command syntax, how to control video quality and bitrate, and how
to apply the correct metadata tags to ensure compatibility with macOS
and iOS devices.
What is hevc_videotoolbox?
hevc_videotoolbox is a hardware-accelerated HEVC (H.265)
video encoder built into macOS. By leveraging Apple’s VideoToolbox
framework, FFmpeg can offload the encoding process to your Mac’s
dedicated hardware (Apple Silicon or Intel Quick Sync), resulting in
significantly faster transcoding speeds and lower CPU usage compared to
software encoders like libx265.
Basic Transcoding Command
To convert a video to HEVC using hardware acceleration, use the following basic FFmpeg command:
ffmpeg -i input.mp4 -c:v hevc_videotoolbox output.mp4-i input.mp4: Specifies the input video file.-c:v hevc_videotoolbox: Selects the VideoToolbox HEVC encoder.
Controlling Video Quality and Bitrate
Hardware encoders handle quality differently than software encoders.
Instead of using Constant Rate Factor (-crf), you should
control output quality using either target bitrate or quality-based
scaling.
Option 1: Quality-Based Encoding (Recommended)
To encode using a constant quality target, use the -q:v
flag. The value ranges from 1 (lowest quality) to
100 (highest quality). A value between 50 and
65 usually offers a good balance between visual quality and
file size.
ffmpeg -i input.mp4 -c:v hevc_videotoolbox -q:v 60 output.mp4Option 2: Bitrate-Based Encoding
If you need to target a specific file size, you can set a target
video bitrate using the -b:v flag.
ffmpeg -i input.mp4 -c:v hevc_videotoolbox -b:v 4M output.mp4Adding QuickTime and Apple Device Compatibility
By default, FFmpeg might write the HEVC video stream with a tag that
Apple’s native player (QuickTime) does not recognize. To ensure your
transcoded video plays seamlessly on macOS, iOS, and Apple TV, force the
hvc1 pixel format tag using -tag:v hvc1.
You can also copy the original audio stream without re-encoding it by
using -c:a copy to save processing time.
Complete Optimized Command
Here is the recommended production-ready command for Mac users:
ffmpeg -i input.mp4 -c:v hevc_videotoolbox -q:v 60 -tag:v hvc1 -c:a copy output.mp4