Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

macOS (Apple Silicon): 4K stream capped at ~55 FPS because AV_CODEC_FLAG_LOW_DELAY forces VideoToolbox low-latency rate control

Open
#5,814 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, macos

Research direction

Start in src/video.cpp at make_avcodec_encode_session and trace how AV_CODEC_FLAG_LOW_DELAY and the VideoToolbox fallback options are applied. Review the related FFmpeg VideoToolbox behavior and the reported benchmark before choosing between a configuration option and conditional handling. Done means high-resolution Apple Silicon streams can exceed the current 55 FPS cap without breaking existing encoder behavior; stream.cpp's macOS duplicate diagnostics are separate context.

Written by the indexing model from the issue text.

Description

Is there an existing issue for this?
  • I have searched the existing issues
Is your issue described in the documentation?
  • I have read the documentation
Is your issue present in the latest beta/pre-release?

Tested on stable v2026.914.233613. I did not run the latest pre-release, but the same code is still on master (src/video.cpp, make_avcodec_encode_session).

Describe the Bug

On Apple Silicon, a 3840×2160 stream is capped at about 55 FPS even though the client requests 120 FPS and the VideoToolbox HEVC encoder can do about 97 FPS at 4K on the same machine.

The cause is that make_avcodec_encode_session always sets:

ctx->flags |= AV_CODEC_FLAG_CLOSED_GOP | AV_CODEC_FLAG_LOW_DELAY;

In FFmpeg's videotoolboxenc.c, AV_CODEC_FLAG_LOW_DELAY on H.264 (and on HEVC on arm64) turns on kVTVideoEncoderSpecification_EnableLowLatencyRateControl. With that on, each 4K HEVC frame takes about 18–20 ms to encode on an M4, which limits the stream to about 50–55 FPS. Without it (still RealTime = true, no frame reordering, one frame in and one frame out), each frame takes about 10 ms, or about 97 FPS.

AV_CODEC_FLAG_LOW_DELAY is only removed in the VideoToolbox fallback options ({"flags", "-low_delay"}), so users cannot turn it off from the config.

What Sunshine sends: with min_log_level = 0, I counted Sent Frame lines per second while Moonlight requested 3840×2160 at 120 FPS and 150 Mbps. The result was 55.1 FPS on a static desktop (10 s) and 55.2 FPS with a window animating the whole time (16 s). The two numbers being the same points to a fixed cost per encoded frame, not to capture.

Standalone VideoToolbox benchmark (encoder otherwise idle, one frame at a time with VTCompressionSessionCompleteFrames after each frame, 150 Mbps, desktop-like content, M4):

Resolution / codec Low-latency rate control on (Sunshine today) off
3840×2160 HEVC 50–55 FPS (18.3–20.1 ms/frame) 97 FPS (10.3 ms/frame)
3840×2160 H.264 54 FPS (18.4 ms/frame) —
3200×1800 HEVC 68 FPS (14.7 ms/frame) 136 FPS (7.4 ms/frame)
2880×1620 HEVC 81 FPS (12.4 ms/frame) —
2560×1440 HEVC 98 FPS (10.2 ms/frame) 201 FPS (5.0 ms/frame)
1920×1080 HEVC 182 FPS (5.5 ms/frame) —

Capture is not the limit: AVCaptureScreenInput on a 3840×2160 @ 120 Hz virtual display delivers about 90–100 FPS.

Expected Behavior

There should be a way to reach the encoder's real throughput at high resolutions on Apple Silicon. For example:

  • a VideoToolbox option (for example vt_low_latency_rc = enabled/disabled) that decides whether AV_CODEC_FLAG_LOW_DELAY is set for *_videotoolbox, or
  • not setting AV_CODEC_FLAG_LOW_DELAY for VideoToolbox when the requested resolution × FPS is higher than what the low-latency mode can sustain.
Additional Context
  • Side note on diagnostics: on macOS, every verbose Sent Frame ... line ends with Dupe. In stream.cpp, frame_is_dupe is set when packet->frame_timestamp is empty, and the AVFoundation capture path never sets img->frame_timestamp. As a result, every frame looks like a duplicate on macOS, which makes the duplicate/new frame count unusable there.
  • I can share the benchmark source if useful (about 60 lines of C against VideoToolbox).
  • Client: Moonlight 6.1.0 on Windows 11 (RTX 5070 Ti, hardware HEVC decode), 3840×2160 @ 120 FPS, 150 Mbps, V-Sync off. The host display is a CGVirtualDisplay, 3840×2160 HiDPI, at 170 Hz.
Host Operating System

macOS

Operating System Version

macOS 27.0 (26A428)

Architecture

arm64/aarch64

Package

macOS - dmg

GPU Type

Apple Silicon

GPU Model

Apple M4 (10-core GPU)

GPU Driver/Mesa Version

n/a (macOS 27.0 26A428)

Capture Method

AVCaptureScreen (macOS)

Dominant language
C++
Stars
42k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
125

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LizardByte/Sunshine

All issues in LizardByte/Sunshine

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.