Skip to content
systemcoding.dev
Media

Encode With VideoToolbox in FFmpeg on macOS

Use FFmpeg 7.1 with h264_videotoolbox and hevc_videotoolbox on Apple silicon: quality and bitrate options, the hvc1 tag for QuickTime, and hardware decoding.

6 min read
Summarize in AI
Flat illustration of video frames passing through a codec, with the FFmpeg, macOS and Apple logos.

Apple silicon Macs include dedicated media engines that encode H.264 and HEVC far faster than a CPU core and with little power. Applications reach them through the VideoToolbox framework, and FFmpeg wraps that framework in encoders named h264_videotoolbox and hevc_videotoolbox. You do not need to install a driver or a vendor SDK. This post covers a first working command on FFmpeg 7.1 and macOS 15, the options that control quality and size, the one tag that makes HEVC files open in QuickTime and Safari, and how to turn on hardware decoding as well. Read the explainer on hardware decoding versus hardware encoding first if those two terms are new.

Check that FFmpeg has the encoders

Homebrew's ffmpeg formula builds with VideoToolbox enabled. Confirm it before anything else:

Shell
ffmpeg -hide_banner -encoders | grep videotoolbox
Text
 V....D h264_videotoolbox    VideoToolbox H.264 Encoder (codec h264)
 V....D hevc_videotoolbox    VideoToolbox H.265 Encoder (codec hevc)
 V....D prores_videotoolbox  VideoToolbox ProRes Encoder (codec prores)

The three letters at the start of each line tell you it is a video encoder, and the descriptions may differ slightly between releases. If the grep prints nothing, the binary was built without VideoToolbox, and you need another build. A binary from a source build must be configured with --enable-videotoolbox, which is the default on macOS.

The first command

Encode an H.264 file at a target bitrate:

Shell
ffmpeg -i input.mov -c:v h264_videotoolbox -b:v 8M -c:a aac -b:a 160k out.mp4

-b:v 8M asks for an average of 8 megabits per second. The hardware encoder aims at that value, and it is a target, not a guarantee, so measure the result:

Shell
ffprobe -v error -select_streams v -show_entries stream=codec_name,profile,bit_rate -of default=nw=1 out.mp4
Text
codec_name=h264
profile=High
bit_rate=7915312

The measured value varies a little below or above the request. The profile depends on the input and the encoder defaults. You can set it with -profile:v, using values such as baseline, main or high for H.264.

Use quality instead of bitrate

A fixed bitrate wastes space on easy scenes and starves hard ones. VideoToolbox accepts a quality target through -q:v, a number from 0 to 100 where higher is better. Support for constant quality in these encoders depends on the hardware and on the FFmpeg version, and it works on Apple silicon with current releases:

Shell
ffmpeg -i input.mov -c:v hevc_videotoolbox -q:v 60 -tag:v hvc1 -c:a aac -b:a 160k out-hevc.mp4

Quality values between 50 and 70 are a sensible place to start, but the scale is not linked to x264's CRF, so there is no formula that converts one into the other. Encode a short section at three values, look at each, and pick the lowest that you accept. The FFmpeg codecs documentation lists the encoder's options, and ffmpeg -h encoder=hevc_videotoolbox prints the set your build supports.

If the encoder rejects -q:v on an older Mac, fall back to -b:v. Intel Macs with a T2 chip or a supported GPU can use the encoders, but their feature set differs from Apple silicon.

Why the hvc1 tag matters

HEVC can be stored in MP4 with two different sample entry names, hev1 and hvc1. FFmpeg writes hev1 by default for HEVC in MP4. QuickTime Player, Safari and most Apple software only accept hvc1, so an HEVC file tagged hev1 may show a black picture or refuse to open. The fix is the output option -tag:v hvc1, as used above. Confirm it:

Shell
ffprobe -v error -select_streams v -show_entries stream=codec_tag_string -of default=nw=1 out-hevc.mp4
Text
codec_tag_string=hvc1

The tag changes only the label in the container, not the encoded data, so you can fix an existing file without re-encoding by remuxing with -c copy -tag:v hvc1.

Real-time and software fallback

Two options change how the encoder behaves. -realtime 1 asks VideoToolbox to prioritise speed over quality, as for live capture. -allow_sw 1 lets the framework use a software encoder if the hardware one is unavailable. Leave the second option off when you want to be sure that the hardware is in use, because with it on a command can succeed on a machine without the engine and run very slowly.

-prio_speed 1 is a related option that also trades quality for speed. Setting it without a reason makes files larger or blurrier for no benefit in a non-real-time job.

Hardware decoding on macOS

Add the decoder when the source is heavy, such as 4K HEVC from a camera:

Shell
ffmpeg -hwaccel videotoolbox -i camera.mov -c:v hevc_videotoolbox -q:v 60 -tag:v hvc1 -c:a aac out.mp4

-hwaccel videotoolbox is an input option, so it comes before -i. The decoded frames are copied back to system memory by default, which suits the encoder since it accepts ordinary frames. For a chain with no filters that is simple and effective. The log shows which path ran:

Text
Stream #0:0 -> #0:0 (hevc (native) -> hevc (hevc_videotoolbox))

If the decoder cannot handle the stream, FFmpeg falls back to software decoding and prints a warning, and the encode still completes.

ProRes for editing

prores_videotoolbox encodes Apple ProRes on the media engine, which suits an editing workflow where you convert camera files to an intermediate format. The -profile:v option picks the flavour: proxy, lt, standard, hq, 4444 and xq are the names the encoder accepts.

Shell
ffmpeg -i camera.mp4 -c:v prores_videotoolbox -profile:v hq -c:a pcm_s16le edit.mov

ProRes files are large, because the format spends bits to stay easy to decode and to survive repeated editing, so use a fast disk. The 4444 profiles keep an alpha channel when the source has one, and the other profiles do not. Whether a given Mac encodes a particular profile in hardware depends on its generation, and FFmpeg reports an error when it cannot open the session.

Compare against software before you commit

A hardware encode is fast, but it is not free. The media engine uses a fixed algorithm with limited look-ahead, and at the same bitrate it usually gives a lower quality than x264 or x265 with a slow preset. Test on your own footage. Encode a clip with libx264 -preset slow -crf 20 and with h264_videotoolbox -b:v set to the same size as the software result, then compare visually, or with a metric such as VMAF if your build has libvmaf. If the hardware file looks as good to you, take the speed. If it does not, use the hardware encoder for previews and drafts, and software for the final file.

Troubleshooting

  • The picture is black in QuickTime. Missing -tag:v hvc1 on an HEVC MP4.

  • "Unknown encoder 'h264_videotoolbox'". The build lacks VideoToolbox. Install FFmpeg from Homebrew or rebuild with --enable-videotoolbox.

  • **-q:v has no effect.** Your encoder or hardware does not support constant quality, so use -b:v.

  • Colours look wrong. Tag the colour properties explicitly with -colorspace bt709 -color_primaries bt709 -color_trc bt709 for HD video that has no tags.

Also inGPU
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.