macOS (Apple Silicon): 4K stream capped at ~55 FPS because AV_CODEC_FLAG_LOW_DELAY forces VideoToolbox low-latency rate control
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
- Domain
- audio-video-rtc, performance
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 whetherAV_CODEC_FLAG_LOW_DELAYis set for*_videotoolbox, or - not setting
AV_CODEC_FLAG_LOW_DELAYfor 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 withDupe. Instream.cpp,frame_is_dupeis set whenpacket->frame_timestampis empty, and the AVFoundation capture path never setsimg->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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from LizardByte/Sunshine
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
LizardByte/Sunshine#5795 ·
Maintainers usually reply within 1 day
-
PIN pairing fails with "Missing CSRF token" - web UI never fetches/attaches the tokenMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
LizardByte/Sunshine#5467 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 22/100
LizardByte/Sunshine#5894 ·
Maintainers usually reply within 1 day
-
[Windows 11 Insider] Black screen when capturing secondary monitor (negative coordinates / AMD GPU)Open
Difficulty 4/5 3-5 days Newbie friendliness 15/100
LizardByte/Sunshine#5884 ·
Maintainers usually reply within 1 day
-
macOS: remote mouse input silently dies after uptime — keyboard survives, fixed by process restartPossibly taken @ReenigneArcher claimed this 2 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
LizardByte/Sunshine#5874 · 3 comments ·
Maintainers usually reply within 1 day
All issues in LizardByte/Sunshine
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
mesonbuild/wrapdb#2961 ·
Maintainers usually reply within 1 day
-
80 Instance - Raid - Northrend
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
azerothcore/azerothcore-wotlk#28075 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
objectionary/eo-graphs#80 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
scanaislop/aislop#476 ·
Maintainers usually reply within 1 day