[macOS] Unconditional AV_CODEC_FLAG_LOW_DELAY (EnableLowLatencyRateControl) makes third-party VideoToolbox encoders unusable — falls back to libx264
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 68/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- cpp, macos
- 领域
- backend, performance
调研方向
Read src/video.cpp, especially make_avcodec_encode_session and the H.264 VideoToolbox encoder definition; compare where AV_CODEC_FLAG_LOW_DELAY is set with the fallback options that clear it. Reproduce the failure with a VideoToolbox encoder that rejects low latency rate control, then verify that hardware encoding succeeds when the flag is disabled or configurable. The issue also links #5814 for context.
由索引模型根据 Issue 内容生成。
描述
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?
Not verified as a binary. I ran the stable v2026.914.233613 build and checked the code path on master (src/video.cpp, make_avcodec_encode_session) — it is unchanged there, so a pre-release build should behave the same. Say the word if you want me to install the latest pre-release and retest; it is a disposable VM.
Describe the Bug
make_avcodec_encode_session sets AV_CODEC_FLAG_LOW_DELAY for every encoder, and on macOS FFmpeg's videotoolboxenc turns that into kVTVideoEncoderSpecification_EnableLowLatencyRateControl in the encoder specification. Apple's own VideoToolbox encoders accept that key, but a third-party VideoToolbox encoder that does not implement low-latency rate control is rejected outright: VTCompressionSessionCreate returns -12902 (kVTVideoEncoderNotFoundErr) and Sunshine falls back to libx264, even though the hardware encoder works fine without that one key.
Same root flag as #5814 (there it caps Apple Silicon at ~55 FPS at 4K; here it removes hardware encoding entirely), so if you add the vt_low_latency_rc knob proposed there, please consider it a fix for this too.
Environment where it happens
- macOS 26.7.1 (25G241), x86_64, QEMU/Proxmox VM with an RTX 5060 passed through
- Third-party VideoToolbox/Metal driver
nullmoth/nvidia-macos-driver2.5.2 (com.nvmtl.videoencoder.avc.nvenc,…hevc.nvenc); Metal 3 works, and the encoders encode real frames when LLRC is not requested - Sunshine 2026.914.233613 (stable, macOS - dmg), capture = AVCaptureScreen, H.264, no config overrides beyond
sw_preset/min_threads
What Sunshine logs
Info: Trying encoder [videotoolbox]
Info: Creating encoder [h264_videotoolbox]
Error: [h264_videotoolbox @ 0x…] Cannot create compression session: -12902
Error: [h264_videotoolbox @ 0x…] Try -allow_sw 1. The hardware encoder may be busy, or not supported.
Info: Retrying with fallback configuration options for [h264_videotoolbox] after error: Generic error in an external library
Error: [h264_videotoolbox @ 0x…] Error retrieving the supported property dictionary err=-12908
Encoder [videotoolbox] failed
Trying encoder [software] -> libx264
Evidence 1 — what Sunshine actually passes. Interposing VTCompressionSessionCreate inside the Sunshine process shows every attempt carries the same specification:
spec = { EnableLowLatencyRateControl = 1; RequireHardwareAcceleratedVideoEncoder = 1; }
imgAttrs = (null)
-> status = -12902
Sunshine's fallback attempt (Retrying with fallback configuration options for [h264_videotoolbox]) fails the same way, and every create call captured in that process carried the key: the only place that clears it is the fallback options block {"flags"s, "-low_delay"}, while ctx->flags is reset and set to include AV_CODEC_FLAG_LOW_DELAY in make_avcodec_encode_session.
Evidence 2 — isolating the key. In a plain process where a Metal device has been created (so the third-party encoders are registered and appear in VTCopyVideoEncoderList), 1920x1080 H.264:
| encoderSpecification | result |
|---|---|
nil / {} |
0 (session created) |
EnableHardwareAcceleratedVideoEncoder |
0 |
RequireHardwareAcceleratedVideoEncoder |
0 |
EnableLowLatencyRateControl |
-12902 |
RequireHardwareAcceleratedVideoEncoder + EnableLowLatencyRateControl (what Sunshine sends) |
-12902 |
same + EncoderID = com.nvmtl.videoencoder.avc.nvenc |
-12902 |
Removing only EnableLowLatencyRateControl makes the same create succeed and the encoder produces frames (VTCompressionSessionEncodeFrame callback status=0, one sample out).
Evidence 3 — the encoder never advertises the property. VTSessionCopySupportedPropertyDictionary on a session created without LLRC returns 65 keys including RealTime, ProfileLevel and MaxFrameDelayCount, but no EnableLowLatencyRateControl. So VideoToolbox filters that encoder out of the candidate list instead of ignoring the request.
Relevant source (master)
src/video.cpp,make_avcodec_encode_session:ctx->flags |= AV_CODEC_FLAG_CLOSED_GOP | AV_CODEC_FLAG_LOW_DELAY;src/video.cpp, h264 VideoToolbox encoder definition: the only place that clears it is the fallback options block,{"flags"s, "-low_delay"}.
Expected Behavior
- A third-party VideoToolbox hardware encoder that does not support low-latency rate control should still be usable; the flag should not be applied unconditionally to
*_videotoolbox. - Or expose it, e.g.
vt_low_latency_rc = enabled/disabled(as proposed in #5814), so users can turn it off for such encoders.
Additional Context
Minimal reproduction of the underlying VideoToolbox behaviour (needs any process that has created a Metal device first, so the third-party encoders are registered):
#import <Metal/Metal.h>
#import <VideoToolbox/VideoToolbox.h>
MTLCreateSystemDefaultDevice(); // registers com.nvmtl.videoencoder.*.nvenc
NSDictionary *bad = @{ @"EnableLowLatencyRateControl": @YES,
@"RequireHardwareAcceleratedVideoEncoder": @YES };
NSDictionary *good = @{ @"RequireHardwareAcceleratedVideoEncoder": @YES };
VTCompressionSessionRef s = NULL;
VTCompressionSessionCreate(NULL, 1920, 1080, kCMVideoCodecType_H264,
(__bridge CFDictionaryRef)bad, NULL, NULL, NULL, NULL, &s); // -12902
if (s) { CFRelease(s); s = NULL; }
VTCompressionSessionCreate(NULL, 1920, 1080, kCMVideoCodecType_H264,
(__bridge CFDictionaryRef)good, NULL, NULL, NULL, NULL, &s); // 0
This host is a disposable VM, so I can test builds or gather any additional logs (min_log_level = 0, VT-level traces) you want. I did not attach a full log bundle because the above is the whole failure; say the word and I will paste one.
Host Operating System
macOS
Operating System Version
macOS 26.7.1 (25G241), x86_64, QEMU/Proxmox VE VM
Architecture
amd64/x86_64
Package
macOS - dmg
GPU Type
NVIDIA
GPU Model
NVIDIA GeForce RTX 5060 (GB206), passed through to the VM
GPU Driver/Mesa Version
nullmoth/nvidia-macos-driver 2.5.2 (third-party Metal + VideoToolbox plugin; kexts NVRM/NVAccel/NVRMFB/NVRMAGDC 2.5.2)
Capture Method
AVCaptureScreen (macOS)
- 主要语言
- C++
- 星标
- 43k
- 派生
- 2.4k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
LizardByte/Sunshine 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
LizardByte/Sunshine#6051 ·
-
PIN pairing fails with "Missing CSRF token" - web UI never fetches/attaches the token可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
LizardByte/Sunshine#5467 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
LizardByte/Sunshine#6080 ·
-
难度 5/5 一周以上 新手友好度 18/100
LizardByte/Sunshine#6072 ·
-
难度 4/5 3-5 天 新手友好度 45/100
LizardByte/Sunshine#6063 · 1 条评论 ·
查看 LizardByte/Sunshine 的全部 Issue
相似的 Issue
-
mlir
难度 2/5 1-3 小时 新手友好度 72/100
llvm/llvm-project#241070 · 1 条评论 ·
维护者通常 1 天内回复
-
help wanted new command
难度 2/5 1-3 小时 新手友好度 76/100
tldr-pages/tldr#25111 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 77/100
NVIDIA/cuda-quantum#5886 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复