VideoToolbox

From wiki.selur.net
Jump to navigation Jump to search

VideoToolbox is Apple's framework for hardware video encoding on the Mac. Hybrid uses it through ffmpeg's h264_videotoolbox and hevc_videotoolbox encoders to encode H.264 and H.265 on the media engine of the Mac instead of the CPU. In Hybrid the encoder is called FFVideotoolbox; it only exists in the macOS version and is marked as experimental there.

Base → Video: FFVideotoolbox, then the FFVideotoolbox tab

What it does

The encoding runs on the hardware encoder of the Mac, which is many times faster than a software encoder and hardly loads the CPU. In exchange there are few settings: a profile, a rate target and a speed/quality priority. At the same bit rate the result is usually less efficient than a slow x264 or x265 encode.

The rate is set in one of three ways, which exclude each other:

  • Bitrate: an average bit rate, optionally held constant.
  • Target size: a file size; Hybrid computes the bit rate for it.
  • Constant quality: a quality value from 1 to 100, the size follows the content.

There is only one pass. VideoToolbox does not produce the same bytes twice for the same call, so two encodes of the same job differ slightly in size.

Requirements

  • macOS; the encoder is not offered on Windows and Linux. ffmpeg with VideoToolbox support is part of Hybrid's macOS package.
  • H.264 is encoded in 8 bit 4:2:0 only. H.265 offers 8 bit 4:2:0, 10 bit 4:2:0 and 10 bit 4:2:2; 4:4:4 is not available. What the hardware encodes itself depends on the Mac; where it cannot, Hybrid allows VideoToolbox to fall back to its software encoder.
  • VideoToolbox cannot encode AV1. ProRes through VideoToolbox is part of the ProRes encoder.

Settings

Control ffmpeg option Range / values Hybrid default Meaning
Encoder -vcodec H.264, H.265 H.265 Video format: h264_videotoolbox or hevc_videotoolbox. H.265 needs less bit rate for the same quality and is the only one with 10 bit; H.264 plays on more devices. Profile and Level switch to the versions for the chosen format.
Profile (H.264) -profile:v Baseline, Main, High High H.264 profile, the set of coding tools a decoder must support. High is the normal choice; Baseline and Main are only for old players that need them.
Profile (H.265) -profile:v none, Main, Main 10, Main 4:2:2 10 Main H.265 profile. Main is 8 bit 4:2:0, Main 10 is 10 bit 4:2:0, Main 4:2:2 10 is 10 bit 4:2:2. With none no profile is passed and VideoToolbox chooses. The profile decides Bit depth and Color sampling.
Level (H.264) -level auto, 1.3, 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1, 5.2 auto Upper limit for frame size, frame rate and bit rate that the stream declares. auto lets the encoder pick the level the video needs. Level 1.3 only exists for Baseline; with another profile Hybrid passes auto instead. Set a fixed level only when the playback device demands one.
Level (H.265) – auto auto Display only. hevc_videotoolbox has no level option, VideoToolbox always picks the H.265 level itself.
Bit depth -pix_fmt 8-bit, 10-bit 8-bit Bit depth of the output. It is not chosen here but follows the profile: 10 bit with the H.265 profiles Main 10 and Main 4:2:2 10, 8 bit otherwise.
Color sampling -pix_fmt i420, i422 i420 Chroma subsampling of the output. It follows the profile as well: 4:2:2 with Main 4:2:2 10, 4:2:0 otherwise.
Bitrate (kbit/s) -b:v 16 – 245760 on, 1500 Average bit rate to aim at. Selecting it sets Target mode back to custom.
Target size (MiB), Target mode -b:v 0.2 MiB and up; custom, 1/4 CD … 1 BD 50 off; custom, 700 Aim at a file size instead; Hybrid computes the video bit rate from the size, the length and the size of audio and other streams. Choosing a media size in Target mode selects the target size and fixes it; the size can only be typed in with custom. With a single pass the size is hit approximately, not exactly.
Constant quality -q:v 1 – 100 off, 65 Encodes at a constant quality instead of a bit rate. 1 is the lowest quality and smallest file, 100 the highest. The value field is only available with this choice selected.
Constant bitrate -constant_bit_rate on/off off Keeps the bit rate constant instead of letting it vary with the content, which lowers the peaks; for streaming and fixed channels. Needs a bit rate, so it is locked with Constant quality.
Priority -prio_speed auto, speed, quality auto Tells VideoToolbox what to favour. speed (-prio_speed 1) encodes faster, quality (-prio_speed 0) spends more time per frame. auto writes nothing and leaves the decision to VideoToolbox.

The Configuration row at the bottom saves, loads and deletes named sets of these settings.

Example

Typical call (composed from the settings, not measured): H.265, profile Main 10, 4000 kbit/s, priority quality, on a 10-bit 640x352 source with 25 fps and square pixels:

vspipe "encodingTempSynthSkript.vpy" - --outputindex 0 -c y4m --progress | ffmpeg -y -noautorotate -nostdin -threads 8 -f yuv4mpegpipe -i - -an -sn -color_primaries bt470bg -color_trc smpte170m -colorspace bt470bg -color_range tv -pix_fmt yuv420p10le -strict -1 -fps_mode auto -r 25/1 -vcodec hevc_videotoolbox -profile:v main10 -b:v 4000k -prio_speed 0 -g 250 -aspect 640:352 -allow_sw 1 -metadata encoding_tool="Hybrid 2026.11.22.1" "test.265"

With H.264, profile High, level auto and Constant quality 65 the encoder part becomes:

-vcodec h264_videotoolbox -profile:v high -level 0 -coder cabac -q:v 65 -g 250 -aspect 640:352 -allow_sw 1

How Hybrid calls it

  • The filter script (Vapoursynth or AviSynth) is piped into ffmpeg; without a script ffmpeg reads the source itself.
  • ffmpeg writes a raw .264 or .265 stream, which Hybrid muxes into the chosen container afterwards.
  • Profiles are passed by name (baseline, main, high; main, main10, main42210). For H.264 Hybrid also writes -level (0 for auto, otherwise the level without the dot, e.g. 41) and, except with Baseline, -coder cabac.
  • The pixel format follows the profile: yuv420p, yuv420p10le for Main 10 and yuv422p10le for Main 4:2:2 10; ffmpeg hands them to VideoToolbox as p010le and p210le.
  • The key frame distance is fixed at 250 frames (-g 250); there is no control for it.
  • -aspect carries the display aspect ratio computed from the output size and the pixel aspect ratio.
  • -allow_sw 1 is always written, so VideoToolbox may use its software encoder where the hardware cannot encode the format.
  • Either -b:v (bit rate and target size) or -q:v (constant quality) is written, never both; -constant_bit_rate 1 only together with -b:v.
  • Color matrix, transfer, primaries and range of the video are passed to ffmpeg as -colorspace, -color_trc, -color_primaries and -color_range.

Background

What is not offered

ffmpeg's VideoToolbox encoders have a few more options. Hybrid leaves out the ones that showed no measurable effect or did not change the stream (number of reference frames, spatial adaptive quantization, the power-efficiency switch) and alpha channel encoding, for which Hybrid has no input path.

Speed and bit rate

In Hybrid's own tests Priority speed encoded 1080p H.265 about 30 % faster than the default, and Constant bitrate roughly halved the highest one-second bit rate of a 1500 kbit/s encode. Target sizes were hit within about 2 %.

Sources