Skip to content

Videotoolbox low latency - #4

Closed
ghbogarin wants to merge 1 commit into
masterfrom
videotoolbox-low-latency
Closed

ghbogarin wants to merge 1 commit into
masterfrom
videotoolbox-low-latency

Conversation

@ghbogarin

@ghbogarin ghbogarin commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds a low_latency setting to the VideoToolbox H.264/HEVC hardware encoders. Not a user-facing feature, the idea is that a service turns it on through apply_encoder_settings when it streams over a real-time protocol.

With it set, the session is created with kVTVideoEncoderSpecification_EnableLowLatencyRateControl. VT only allows that on the dedicated .rtvc encoders (com.apple.videotoolbox.videoencoder.h264.rtvc / hevc.rtvc), so the encoder asks VT for that one and uses it instead of the selected one. RealTime is turned on too.

A few things work differently in this mode. CBR isn't supported (ConstantBitRate fails with kVTPropertyNotSupportedErr), so it falls back to ABR. Spatial AQ isn't supported either, so it's skipped. And the encoder won't produce B-frames even if bframes is on.

Software and ProRes encoders just ignore the setting. If VT has no low latency encoder for the codec/resolution, it logs that and encodes normally. The mode is picked when the session is created, so later updates (dynamic bitrate, for example) don't change it.

Motivation and Context

We use this from a service that needs low encoder delay. WHIP could potentially use it too.

I measured encode latency outside OBS with the same session properties (1080p30 camera footage, ABR 6 Mbps, M4 chip):

  • default: 50.5 ms median, 113 ms p95, largest frame 124 KB
  • low latency mode: 4.7 / 4.9 ms, largest frame 49 KB

How Has This Been Tested?

MacBook Pro M4, macOS 26.6.2, streaming over RTMP to a local ffmpeg:

  • low_latency on in the stream encoder settings: uses h264.rtvc, CBR falls back to ABR, and changing the bitrate while live works.
  • Started a normal session, then sent low_latency=true plus a bitrate change while live: it stays a normal session and keeps CBR.
  • Software H.264 encoder with low_latency: logs the fallback and encodes normally.
  • Camera at 1080p30 with the mode on and off: both decode fine.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

This change is Reviewable

Add a "low_latency" encoder setting, not exposed in the UI, that
services can enable through apply_encoder_settings for real-time
protocols. On hardware H.264/HEVC encoders it creates the session with
EnableLowLatencyRateControl, which selects the low latency (.rtvc)
encoder, and sets RealTime. CBR falls back to ABR and Spatial AQ is
skipped, as neither is supported in this mode. Other encoders ignore
the setting and encode normally.
@ghbogarin ghbogarin closed this Nov 6, 2026
@ghbogarin
ghbogarin deleted the videotoolbox-low-latency branch November 6, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants