Sunshine
Sunshine copied to clipboard
Hardware encoders do not work on macOS Ventura
Is there an existing issue for this?
- [x] I have searched the existing issues
Is your issue described in the documentation?
- [X] I have read the documentation
Is your issue present in the nightly release?
- [X] This issue is present in the nightly release
Describe the Bug
Sunshine fails to use hardware encoders on macOS despite the fact that other applications (e.g. Hanbrake, videoproc) can. It falls back to default software encoder but it's full of graphical glitches/atrifacts.
Expected Behavior
Hardware encoder should be found and used by Sunshine (on macOS)
Additional Context
I see the following message in logs: Error: [h264_videotoolbox @ 0x7f9470706140] Error: cannot create compression session: -12902 [h264_videotoolbox @ 0x7f9470706140] Try -allow_sw 1. The hardware encoder may be busy, or not supported. Error: Could not open codec [h264_videotoolbox]: Generic error in an external library Info: Encoder [videotoolbox] failed
Host Operating System
macOS Ventura
Operating System Version
13.6.5
Architecture
64 bit
Sunshine commit or version
0.22.1
Package
macOS - brew
GPU Type
AMD
GPU Model
RX 6600
GPU Driver/Mesa Version
n/a
Config
vt_software = allowed
Apps
No response
Relevant log output
[2024:03:15:16:07:26]: Info: Sunshine version: 0.22.1
[2024:03:15:16:07:26]: Info: // Testing for available encoders, this may generate errors. You can safely ignore those errors. //
[2024:03:15:16:07:26]: Info: Trying encoder [videotoolbox]
[2024:03:15:16:07:26]: Info: SDR color coding [Rec. 601]
[2024:03:15:16:07:26]: Info: Color depth: 8-bit
[2024:03:15:16:07:26]: Info: Color range: [JPEG]
[2024:03:15:16:07:27]: Error: [h264_videotoolbox @ 0x7f9471d05480] Error: cannot create compression session: -12902
[2024:03:15:16:07:27]: Error: [h264_videotoolbox @ 0x7f9471d05480] Try -allow_sw 1. The hardware encoder may be busy, or not supported.
[2024:03:15:16:07:27]: Error: Could not open codec [h264_videotoolbox]: Generic error in an external library
[2024:03:15:16:07:27]: Info: SDR color coding [Rec. 601]
[2024:03:15:16:07:27]: Info: Color depth: 8-bit
[2024:03:15:16:07:27]: Info: Color range: [JPEG]
[2024:03:15:16:07:27]: Error: [h264_videotoolbox @ 0x7f9470707900] Error: cannot create compression session: -12902
[2024:03:15:16:07:27]: Error: [h264_videotoolbox @ 0x7f9470707900] Try -allow_sw 1. The hardware encoder may be busy, or not supported.
[2024:03:15:16:07:27]: Error: Could not open codec [h264_videotoolbox]: Generic error in an external library
[2024:03:15:16:07:27]: Info: Encoder [videotoolbox] failed
[2024:03:15:16:07:27]: Info: Trying encoder [software]
[2024:03:15:16:07:27]: Info: SDR color coding [Rec. 601]
[2024:03:15:16:07:27]: Info: Color depth: 8-bit
[2024:03:15:16:07:27]: Info: Color range: [JPEG]
[2024:03:15:16:07:27]: Info: [libx264 @ 0x7f9471f05540] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[2024:03:15:16:07:27]: Info: [libx264 @ 0x7f9471f05540] profile High, level 4.2, 4:2:0, 8-bit
[2024:03:15:16:07:28]: Info: [libx264 @ 0x7f9471f05540] frame I:1 Avg QP:49.35 size: 2486
[2024:03:15:16:07:28]: Info: [libx264 @ 0x7f9471f05540] mb I I16..4: 98.7% 1.3% 0.0%
[2024:03:15:16:07:28]: Info: [libx264 @ 0x7f9471f05540] 8x8 transform intra:1.3%
[2024:03:15:16:07:28]: Info: [libx264 @ 0x7f9471f05540] coded y,uvDC,uvAC intra: 0.2% 5.1% 0.0%
[2024:03:15:16:07:28]: Info: [libx264 @ 0x7f9471f05540] i16 v,h,dc,p: 79% 17% 4% 0%
[2024:03:15:16:07:28]: Info: [libx264 @ 0x7f9471f05540] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 3% 4% 40% 33% 3% 1% 4% 4% 9%
[2024:03:15:16:07:28]: Info: [libx264 @ 0x7f9471f05540] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 0% 0% 100% 0% 0% 0% 0% 0% 0%
[2024:03:15:16:07:28]: Info: [libx264 @ 0x7f9471f05540] i8c dc,h,v,p: 94% 5% 0% 0%
[2024:03:15:16:07:28]: Info: [libx264 @ 0x7f9471f05540] kb/s:1193.28
[2024:03:15:16:07:28]: Info:
[2024:03:15:16:07:28]: Info: // Ignore any errors mentioned above, they are not relevant. //
[2024:03:15:16:07:28]: Info:
[2024:03:15:16:07:28]: Info: Found H.264 encoder: libx264 [software]
[2024:03:15:16:07:28]: Error: Couldn't find any of the following libraries: [libavahi-common.3.dylib, libavahi-common.dylib]
[2024:03:15:16:07:28]: Info: Configuration UI available at [https://localhost:47990]
[2024:03:15:16:10:26]: Info: // Testing for available encoders, this may generate errors. You can safely ignore those errors. //
[2024:03:15:16:10:26]: Info: Trying encoder [videotoolbox]
[2024:03:15:16:10:26]: Info: SDR color coding [Rec. 601]
[2024:03:15:16:10:26]: Info: Color depth: 8-bit
[2024:03:15:16:10:26]: Info: Color range: [JPEG]
[2024:03:15:16:10:26]: Error: [h264_videotoolbox @ 0x7f9470706140] Error: cannot create compression session: -12902
[2024:03:15:16:10:26]: Error: [h264_videotoolbox @ 0x7f9470706140] Try -allow_sw 1. The hardware encoder may be busy, or not supported.
[2024:03:15:16:10:26]: Error: Could not open codec [h264_videotoolbox]: Generic error in an external library
[2024:03:15:16:10:26]: Info: Encoder [videotoolbox] failed
[2024:03:15:16:10:26]: Info: Trying encoder [software]
[2024:03:15:16:10:26]: Info: SDR color coding [Rec. 601]
[2024:03:15:16:10:26]: Info: Color depth: 8-bit
[2024:03:15:16:10:26]: Info: Color range: [JPEG]
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] profile High, level 4.2, 4:2:0, 8-bit
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] frame I:1 Avg QP:49.82 size: 2414
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] mb I I16..4: 98.7% 1.2% 0.0%
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] 8x8 transform intra:1.2%
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] coded y,uvDC,uvAC intra: 0.2% 4.7% 0.0%
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] i16 v,h,dc,p: 83% 13% 3% 0%
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 8% 14% 31% 27% 2% 1% 2% 3% 11%
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 0% 0% 100% 0% 0% 0% 0% 0% 0%
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] i8c dc,h,v,p: 97% 2% 1% 0%
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f9471b0ea00] kb/s:1158.72
[2024:03:15:16:10:26]: Info:
[2024:03:15:16:10:26]: Info: // Ignore any errors mentioned above, they are not relevant. //
[2024:03:15:16:10:26]: Info:
[2024:03:15:16:10:26]: Info: Found H.264 encoder: libx264 [software]
[2024:03:15:16:10:26]: Info: Executing [Desktop]
[2024:03:15:16:10:26]: Info: CLIENT CONNECTED
[2024:03:15:16:10:26]: Info: SDR color coding [Rec. 601]
[2024:03:15:16:10:26]: Info: Color depth: 8-bit
[2024:03:15:16:10:26]: Info: Color range: [MPEG]
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f947191b680] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[2024:03:15:16:10:26]: Info: [libx264 @ 0x7f947191b680] profile High, level 4.2, 4:2:0, 8-bit
[2024:03:15:16:10:26]: Error: opening microphone '' failed. Please set a valid input source in the Sunshine config.
[2024:03:15:16:10:26]: Error: Available inputs:
[2024:03:15:16:10:26]: Error: PRO X Wireless Gaming Headset
[2024:03:15:16:10:26]: Error: HD Pro Webcam C920
[2024:03:15:16:10:26]: Error: Unable to initialize audio capture. The stream will not have audio.
[2024:03:15:16:10:44]: Info: CLIENT DISCONNECTED
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] frame I:3 Avg QP:10.93 size:127457
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] frame P:1022 Avg QP: 2.25 size: 13227
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] mb I I16..4: 74.8% 8.4% 16.8%
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] mb P I16..4: 0.5% 0.0% 0.0% P16..4: 16.8% 0.0% 0.0% 0.0% 0.0% skip:82.6%
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] 8x8 transform intra:4.0% inter:6.7%
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] coded y,uvDC,uvAC intra: 27.9% 21.7% 19.1% inter: 6.6% 2.1% 2.0%
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] i16 v,h,dc,p: 49% 49% 1% 1%
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 10% 35% 20% 11% 2% 3% 2% 8% 9%
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 50% 10% 3% 2% 3% 5% 2% 8%
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] i8c dc,h,v,p: 49% 39% 11% 2%
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] Weighted P-Frames: Y:0.0% UV:0.0%
[2024:03:15:16:10:44]: Info: [libx264 @ 0x7f947191b680] kb/s:6509.43
Would it be possible to add more encoders supported by Sunshine or to add the ability to explicitly specify what device should be used for encoding. Or do you think it's not really a solution?
I went with Apple's own "Screen Sharing" for the time being but it would be lovely to have it all in my place (Moonlight) =)
I might be hitting this in #1603 as well. I'm not sure if what I'm seeing is exactly the same though.
https://github.com/LizardByte/Sunshine/actions/runs/8313001334/job/22748528257#step:12:5742
Did you grant screen sharing permission?
screen sharing permission
I did grant screen sharing permission.
And here's a video of the problem I'm having: even with software encoder it fails to properly capture the screen (it looks like the mouse cursor and some other UI elements are "shaking") but in reality (on the actual screen) mouse cursor moves properly. It's just that Sunshine/Moonlight fails to capture/reproduce the image properly
https://github.com/LizardByte/Sunshine/assets/12252940/3c31a20b-1736-401a-b195-a193a7f9a288
I'm getting the exact same issue on macOS Monterey, using Sunshine installed with brew. However, I'll mention that my setup is a little unusual because I am running all this on a virtual machine with GPU (AMD Radeon Pro WX4100) passthrough using QEMU. Games are able to utilize the GPU just fine.
Same log output and same "shaking" or "stuttering" effect when connecting through Moonlight on Linux.
@lulzsun that's actually my setup here 😁 macOS VM running under QEMU with GPU passthrough (RX 6600)
Did a little digging around, appears that #2347 might be the exact same issue described here. A user says an older build of sunshine worked, will try later when I get the chance.
Tried version 0.14.1 of sunshine and surprisingly software encoding works and that shaking/freezing issue is resolved. Hardware encoding still doesn't work and the error logs still output the same thing as the latest version.
[2024:04:26:20:52:57]: Info: Trying encoder [videotoolbox]
[2024:04:26:20:52:57]: Info: Color coding [Rec. 601]
[2024:04:26:20:52:57]: Info: Color range: [JPEG]
[2024:04:26:20:52:58]: Error: Could not open codec [h264_videotoolbox]: Generic error in an external library
[2024:04:26:20:52:58]: Info: Color coding [Rec. 601]
[2024:04:26:20:52:58]: Info: Color range: [JPEG]
[2024:04:26:20:52:58]: Error: Could not open codec [h264_videotoolbox]: Generic error in an external library
[2024:04:26:20:52:58]: Info: Encoder [videotoolbox] failed
@lulzsun did you install sunshine using brew or something else?
version 0.14.1 of sunshine doesn't seem to be available in brew and I'm having trouble building it myself
You shouldn't even attempt to use a version that old... that are several security issues we have fixed in the past 2 years.
@ReenigneArcher I see.. any idea as to why there might be a regression on macOS between those versions?
Sorry, I don't know... we would need to know the first version that doesn't work, then try to narrow it down to a specific commit between the last working version and the first broken one.
@ReenigneArcher @lulzsun I did a short test of different versions of Sunshine on macOS and here's what I got:
v0.21.0 - doesn't work properly (see my video above) v0.20.0 - crashes during start (zsh: segmentation fault ./sunshine) v0.19.1 - works properly (including HEVC encoding) v0.19.0 - works properly (including HEVC encoding) v0.18.4 - work properly (including HEVC encoding)
I'm happy to find a version of Sunshine that works propertly (v0.19.1) for me and now I'm happy ♥️
Tried v0.19.1 and unfortunately hardware encoding still doesn't work for me, but at least software encoding is still usable.
@lulzsun and does your hardware encoder gets detected and working properly with other applications? (e.g. Hanbrake, videoproc)
You should see something like this: https://github.com/LizardByte/Sunshine/issues/2272#issuecomment-2000077184
@VasylBaran Apparently it doesn't... I just assumed it was working. I installed VideoProc to check and it says HEVC and H264 were both unavailable/disabled.
Not sure why that is the case. I think my GPU should be able to support it, but I'll have to look into it further myself as it seems like it is unrelated to Sunshine now.
+1 Encountering this issue on an RX 550 Lexa card spoofed to 67FF in Mac OS Ventura OSX-KVM under Proxmox (Ryzen 7 1700)
@lulzsun @xXTeraXx I did a small “research” on this topic in the past. Here’s a list of articles and guides that I found useful enough to save them:
- GUIDE How to Enable H.264 and HEVC/H.265 encoding on macOS - [link]
- Hackintosh on ASRock B550M Steel Legend with AMD RX 6800 XT via OpenCore - [link]
- Googel query on the topic: [link]
- iMac19,1(Headless) vs iMacPro1,1 Video Encoding Performance Test. - [link]
- INTEL/AMD GPU SUPPORT FÜR H265/HEVC MAIN10 (10 BIT) UHD ENCODING AM MAC - [link]
- Hacking in 2022, the criticality of the GPU [link]
@VasylBaran thank you for testing the different versions!
I'm not sure the cause of the issue at this point, but here is all the changes from v0.19.1 to v0.20.0. https://github.com/LizardByte/Sunshine/pull/1115/files
Can confirm, version 0.19.1 works for me too. Newer versions don't.
macOS 14.4.1 AMD Radeon RX 570 Not Virtualizing
I did a small “research” on this topic in the past. Here’s a list of articles and guides that I found useful enough to save them
@VasylBaran Thanks, this was helpful in figuring out that I was using the wrong SMBIOS required for enabling hardware acceleration. It seems like it "works" now (using version 0.19.1), but this time I ran into another problem.
Not sure if it is related to Moonlight/Sunshine, but I get this weird color artifact in addition to higher latency compared to using the software encoder.
Screenshot: With hardware encoder
Screenshot: With software encoder
Sorry if my issue is now off topic since it might no longer be related to the original issue.
@lulzsun how about the current version when using the correct SMBIOS?
@lulzsun how about the current version when using the correct SMBIOS?
Unfortunately still getting the same initial issue on version 0.23.1 installed using brew (no hardware encoder detected and shaking/freezing issue with software encoder).
Will be sticking to 0.19.1 and forcing software encoder for the time being until the issue is figured out in latest version.
@ReenigneArcher found the issue.
First it was in commit 036aa2e470cf72e63f036b6b4ec23446a4fdf140
, it freed the frame too soon in video.cpp:1735
, so the encoder failed, then eed27d3
broken macOS for a while. It then was fixed in a29d2e11ea4b46590dab0ea97586bbc5152a8c7a
, which worked if I reverted 036aa2e
changes after line 1735, but got broken again in the next commit... After poking around a bit, found out that now the culprit was mostly e535706a09f1849d2799fd72e889e4d7182f7fe5
, this commit changes av_img_t
and how it retains/release the frame buffers, which again, breaks something with how the frame is available to the encoder when needed.
So after trying to fix the retain/release cycle of this change without success, I decided to just revert the necessary changes, taking care to not remove newer unrelated changes, and it's now working for me even with the nightly
branch.
If you have any improvement suggestion, for example how to fix without fully reverting av_img_t
like I did, but only fixing the retain/release issues, I can run it here to try out.
PR: https://github.com/LizardByte/Sunshine/pull/2485
@Hazer just wanted to say 'thank you!' for taking the time and looking into it. Kudos! ♥️
If anyone using homebrew wants to try out my branch (@VasylBaran I'm looking at you), you can download the file here: https://github.com/Hazer/Sunshine/actions/runs/9024651951/artifacts/1489439570
unzip the file downloaded, then run in the same folder:
brew install --build-from-source sunshine.rb
This should install the version with my most recent changes. While reverting those changes helped, I think now I got a proper implementation of the fix, testers welcome.
Hi, I've been trying to install this version or the last one that worked (v19 apparently) without succes. I'm using macports, not homebrew. Do you know when will it be merged with 'nightly' so I can try that branch?
Thanks for all the work!