FFmpeg VideoToolbox Encoder Settings and Parameters

This article provides a comprehensive overview of the configuration parameters available for Apple’s VideoToolbox hardware encoder within FFmpeg. It covers essential settings for controlling bitrate, quality, profiles, and hardware acceleration options, enabling you to optimize video encoding performance on macOS and iOS devices.

Apple’s VideoToolbox framework allows FFmpeg to access hardware-accelerated video encoding for codecs like H.264 (h264_videotoolbox), HEVC (hevc_videotoolbox), and ProRes (prores_videotoolbox). Configuring these encoders properly requires using a mix of standard FFmpeg options and VideoToolbox-specific private flags.

Standard FFmpeg Parameters

These standard options are supported by the VideoToolbox wrappers and control the primary aspects of the encoding process:

VideoToolbox Private Options

Private options are specific to the VideoToolbox encoder wrappers. You can apply these parameters using the -option value syntax in your FFmpeg command.

Parameter Type Description
profile string Sets the encoder profile (e.g., baseline, main, high for H.264; main, main10 for HEVC).
level string Sets the encoder level (e.g., 4.1, 5.1, auto).
allow_sw boolean Allows fallback to software encoding if hardware acceleration is unavailable (0 or 1). Default is 0 (hardware only).
require_hardware boolean Forces the encoder to fail if hardware-accelerated encoding is not available (0 or 1). Default is 0.
realtime boolean Optimizes the encoder for real-time latency, which is ideal for live streaming (0 or 1). Default is 0.
prioritize_speed boolean Prioritizes encoding speed over visual quality (0 or 1). Default is 0.
max_ref_frames integer Sets the maximum number of reference frames (H.264 only).
frames_before integer Specifies how many frames must be queued before the encoder starts outputting packets.

Color and Metadata Parameters

These parameters ensure that high dynamic range (HDR) or specific color spaces are passed correctly to the hardware encoder:

Example Configuration Commands

Standard H.264 VBR Encoding:

ffmpeg -i input.mp4 -c:v h264_videotoolbox -b:v 4M -profile:v high -level 4.1 output.mp4

High-Quality HEVC (H.265) 10-bit Encoding:

ffmpeg -i input.mp4 -c:v hevc_videotoolbox -profile:v main10 -q:v 65 output.mp4

Low-Latency Real-Time Streaming:

ffmpeg -i input.mp4 -c:v h264_videotoolbox -b:v 2M -realtime 1 -allow_sw 1 output.mp4