Eric Niquette UI, UX, Accessibility

High-quality, low-latency in-home game streaming with Sunshine and Moonlight

Published Updated

A guide on streaming high-quality, low-latency video and inputs from your gaming machine to almost any other device in your house using the Sunshine server and Moonlight client.

Introduction

In no small part due to the pandemic and the scarcity of next-generation consoles, cloud and remote gaming has exploded in popularity. Sunshine and Moonlight are powerful software solutions that enable the streaming of high-quality, low-latency gaming from a powerful machine to client device.

It should be noted that, as Sunshine has greatly matured since I originally wrote this article, much of the troubleshooting and configurations sections are no longer relevant and have been trimmed.

What to expect

With a sufficiently powerful host and a client with decent video-decoding hardware on a wired network, you can expect a 4k HDR stream at 60 or 120 FPS with very little input delay in 7.1 linear PCM surround, with controller support.

Sunshine and Moonlight can also be used as a remote desktop solution, allowing access to your PC on the go and offering mouse emulation on touch screen devices.

What are Sunshine and Moonlight?

Sunshine is streaming server service that serves as a replacement — or upgrade, depending on who you ask — to NVidia's defunct GameStream service. In conjunction with the Moonlight client, Sunshine provides a high-quality, low latency stream from your desktop to your laptop, mobile, media box, and other devices.

While in-home streaming clients like Parsec and Steam In-Home Streaming may offer a simpler initial setup, Sunshine and Moonlight offer what is arguably the best performance and image quality.

Will it work on wifi?

Streaming requires a lot of bandwidth and network stability to be responsive. Assuming a decent wifi network, yes, it will work but your performance may suffer at higher bitrates. Your results will vary based on your device's capabilities, the wifi noise in your area, and the general quality of your network.

However, I strongly recommend against having both the host and the client on a wireless connection. I find that solutions like Parsec are a little more resilient at the cost of image quality and input delay. If wifi is all you have access to, give it a try and reduce the bitrate, resolution, and/or refresh rate if you run into issues.

Requirements

Host

The Sunshine host server (the one you'll be streaming from) is typically your gaming PC but pretty much any modern device should be work fine as long as it supports hardware-accelerated video encoding. The official website has the nitty gritty on Sunshine's hardware requirements but really anything with a relatively recent dedicated GPU or APU should be compatible.

Note: Some devices with built-in displays may require an external monitor or a virtual display to capture output from, as is the case for Windows installations on the Steam Deck. This is apparently due to security restrictions of certain API calls.

See the Virtual displays section for a couple of options.

Client

The Moonlight client is available on an wide array of devices and platforms, or as a Chrome extension if that's more your thing.

For the best performance, the client should have the hardware to decode H.265 video but H.264 or software decoding options are available as fallbacks. Newer hardware can now also take adavantage of AV1 video compression, which promises even better performance than H.265, assuming both the host and client devices support it.

Configuring Sunshine

Installation

A handful of Sunshine builds are available for Windows and Linux. Assuming you're on Windows, you have the option to either install the full Sunshine package, or run it as a portable application.

  • The full installation (sunshine-windows-installer.exe) is installed as a service which allows it to run on the login screen and control elevated prompts. The full package also includes Steam audio device drivers and other useful tools.
  • The portable package (sunshine-windows-portable.zip) can be run locally without administrative permissions but lacks some of the features the full installation provides.

If you plan on using Sunshine regularly, the full installer is probably your best bet as in includes everything you need to get started. Both options perform equally and are configured the same way.

Accessing the Sunshine web GUI

After the installation (and unless configured otherwise) Sunshine will run a web service on port 47990. You can access the GUI by navigating to https://localhost:47990 on the host machine's browser.

Screenshot of the Sunshine web interface

You will need to setup a username and password the first time you access the GUI. If you're not concerned about local security, you can create a bookmark and include the ID and password in the URL for quick access, though this isn't something you should do carelessly:

https://username:password@localhost:47990

Sunshine settings

Audio sink

The audio sink — not to be confused with audio sync — is the device Sunshine will capture audio from. In other words, it'll set this device as the output in Windows and capture from it. If present, Sunshine will default to the Steam Virtual Audio Speaker which has the benefit of having no audible sound on the host and is highly configurable. The Steam Virtual Audio Speaker is installed alongside Sunshine unless checked off in the installation wizard.

Should you need to use a specific device, a list of can be found by running the audio-info.exe tool in the Sunshine tools folder, by default found at the following location:

C:\Program Files\Sunshine\tools\audio-info.exe

Note that the tool cannot be run directly and should be launched from a command prompt or via PowerShell.

Virtual sink

The virtual sink is the device Sunshine will output audio to so you don't hear audio on the host machine. If you're using a virtual audio device like the Steam Virtual Speaker, you can leave this field empty. Otherwise, specify a device to output to.

HEVC and AV1 Support

High Efficiency Video Coding (HEVC), also known as H.265, provides higher quality video at the expense of a slightly higher CPU overhead. Modern devices typically have dedicated hardware for encoding and decoding H.265 streams but should you find your devices struggling to keep up, you can disable HEVC in the Advanced settings. Note that HEVC must be enabled for HDR.

AV1 is a newer codec that promises up to 30% better performance than H.265. If your both your host and client devices support it, AV1 will probably yield better performance overall.

Advanced encoding settings

In the various encoding option tabs are preset quality and compression settings. Unless your devices are struggling to encode or decode the stream, leave these as-is. They've already been optmized to offer the best bang for buck while prioritizing low latency.

Use realtime priority in hardware accelerated gpu scheduling

Hardware-accelerated GPU scheduling (HAGS) is a Windows feature that is required to, amongst other things, use DLSS3 features such as raytracing, frame generation, and other enhancements. However, HAGS has shown to be problematic when encoding and can cause the stream to abruptply halt when when terminating or toggling between Hardware-accelerated windows.

A common symptom of a HAGS-related issue is the video feed freezing but the audio keeps playing. It typically lasts for about a minute before the client is disconnected. If that happens to you, you can disable the option at the cost of some performance and image quality in certain games and scenarios.

Controller support

If you plan on gaming with a controller, you'll need to install ViGEmBus on your host machine. The driver emulates a gaming peripheral and is compatible with Sunshine. It does not require any configuration or customization - install it and you're done. ViGEmBus is now bunbled in with Sunshine and simply needs to be enabled during the installation.

Configuring Moonlight

Moonlight is available on phones, TV boxes, consoles, Linux, Windows, and various other systems. I won't go into the specifics for its installation but its all very straightforward. For the sake of this article, I'm assuming your client is a Windows machine but the configuration is pretty much the same for all platforms.

Adding a host machine

When you first launch Moonshine it should automatically discover Sunshine installations on your network. If that's not the case, as it often is for me, you can manually add a device using the host machine's local IP.

When connecting to a new host for the first time, Moonlight will generate a four-digit security PIN. That PIN must be entered on the client machine's Sunshine GUI, in the "PIN" section, to validate the connection. You should only have to do this once.

Resolution and FPS

The resolution and refresh rates specified here refer to the client's display, not the host's. Where possible, try to match the client and host resolutions to avoid scaling. If you're streaming to a mobile device, you can adjust this setting to match the device's resolution if desired.

In other words, Moonlight's resolution does not affect the host machine's resolution. Using a lower resolution on the Moonlight client will cause the image to scale.

Bitrate

The optimal bitrate depends largely on the resolution, framerate, network speed, and the capabilities of the host and client. Moonlight will provide a suggestion as you change the resolution and refresh rates but I find these to be a little conservative and can simply be bumped up a tad.

If the host and clients are both on a wired connection and have decent hardware, you can consider setting the bitrate to 60-80 or higher, depending on the resolution. In my experience, going beyond a 100-120 Mbps bitrate offers diminishing returns unless you're streaming in 4k HDR, which can require a bit more in some scenarios. The difference in image quality isn't noticeable enough to justify the processing overhead that can increase input delay.

As a general rule, try Moonlight's suggested rate and increase it a little if you find the image quality isn't up to par.

Keep in mind that the greater the bitrate the greater the bandwidth and processing power required to encode and decode the stream. If your devices or network struggle to keep up, reduce the bitrate, resolution, or refresh rate. Moonlight will let you know if it's struggling to keep up.

V-sync

As it can potentially introduce input delay, v-sync should only be enabled if you're experiencing tearing. In my experience, this is typically more of an issue on a 60hz display than it is on 120hz or higher.

Where possible, try to match the host and client's refresh rates ratios. For example, if the host outputs 144hz but the client can only display 60hz, change the host to 120hz so it divides cleanly (2:1) to 60hz on the client to prevent tearing and juddering.

Keep in mind that you should disable your game's vsync options when streaming.

Decoder settings

Unless you're using an old client that does not support hardware video decoding, leave these as-is. On connection, Sunshine and Moonlight will automatically negotiate and figure out what encoder to use.

If your device struggles with H.265, you may find some respite with H.264 at the cost of image quality. Conversely, some devices may find that H.264 offers lower latency than H.265 so give it a shot!

Surround sound

To get surround sound on the client, adjust the number of channels in Moonlight's Audio Settings accordingly. The host's audio sink must be able to ouput the number of desired channels. The default Steam Virtual Speaker device offers up to 7.1 channels.

If you've specified a custom audio device as the audio sink, you may need to configure Windows to output to the correct number of channels as well.

Note that encoded audio such as Dolby Digital, DTS, or Atmos are not supported. Surround sound is only possible in PCM 5.1 or 7.1.

Automatic resolution switching

If your host and client resolutions don't match, you may notice scaling, bluriness, black bars, or other issues. In my case, my desktop feeds a 165hz ultrawide but my television supports 120hz at 1440p; I want Sunshine to automatically switch to 1440p at 120hz when I connect. There are several ways to achieve this, depending on your needs.

QRes

When used in conjunction with Sunshine's Command Preparations, QRes facilitates automatic switching the host's resolution and refresh rate. While it hasn't been updated in a long (long) time, QRes surprisingly still works just fine on Windows 11.

For example, the following command will change the host's resolution to 1440p at 120hz:

C:\Tools\QRes\QRes.exe" /x 2560 /y 1440 r:120
Screenshot of Sunshine's task panel

Sunshine also offers a handful of useful environment variables that can be called, including the client's resolution height and width, if you want to try and match the client's values:

C:\Tools\QRes\QRes.exe /X:%SUNSHINE_CLIENT_WIDTH% /Y:%SUNSHINE_CLIENT_HEIGHT%

Be careful with this, though. If your host's display does not support the client's reported display size, it can prevent the client from connecting. What I like to do is setup a second application (e.g., "Desktop with Resolution Matching") for this so I have a fallback option.

Resolution Automation

Specifically built for Sunshine and Moonlight, Resolution Automation, as its name implies, automatically changes the host's resolution based on the client's configuration.

The tool features a one-click installation script but does require a small Windows configuration and a full installation of Sunshine; the portable version is not supported.

In my experience, Resolution Automation tends to be hit and miss and has broken a few times. To its credit, I hop between different devices and configurations fairly often, which may be causing issues. Give it a shot, though! It's an elegant solution when it works.

Monitor Profile Switcher

If you use multiple monitors or swap between display configurations, Monitor Profile Switcher is an insanely handy tool that can toggle through preset display profiles including layouts, resolutions, and refresh rates using shortcut keys. In my case, I use it to toggle between multi-monitor display mode, TV gaming mode, and movie mode, and a few others with the press of shortcut keys.

It can also be used with command-line arguments that can be input in Sunshine so you could easily toggle off your secondary monitors, change resolution, and change the refresh rate on connection and restore it on termination.

The current build of Monior Profile Switcher does not correctly apply refresh rates on Windows 11. Until implemented to the main branch, you can download this specific build from the discussion forums, which I've archived locally in case the thread goes missing.

Overall, I can't recommend this tool enough. It's lightweight and is extremely reliable as long as you grab the modified version.

Virtual displays

Virtual displays are a way to provide Sunshine with a resolution that is either not supported by your monitor, or if you want to stream with your monitor off to save on power or to reduce light output in a dark room or what have you.

In some cases, a virtual display may be required to workaround certain security restrictions inhibiting Sunshine from capturing video.

Solutions

Software

While not the most intuitive of tools, Indirect Display Driver Sample can create a virtual display customized to your needs. Once configured, tools like Monitor Swap Automation can be used in conjunction to automatically swap to the correct monitor.

Another option is a utility developed by Amyuni for their USB-based displays that can also be used to create virtual displays. I've never tried it but from what I could gather it seems to have a pretty good success rate.

Dummy adapters

A simple hardware approach is with the use of a dummy display. Offered in USB-C, HDMI, and DisplayPort variants, the adapter tricks the machine into thinking an external display is connected. The dummy display can configured the same way you would a physical monitor, which can then be used by Sunshine.

When looking at adapters, be mindful of their supported resolutions and refresh rates to find one that'll suit your needs. If you can't find an exact match, you might be able to create a custom resolution through tools like the NVidia Control Panel, but your mileage may vary.

Configuring Sunshine to use a virtual display

If you opt for a virtual display, you'll need to configure Sunshine to utilize it. In the Sunshine UI, navigate to the Configuration section and to the Audio/Video tab. Find the "Output name" field at the bottom of the page. You'll nede to enter your desired display's ID here.

To find your display's ID value, find the Tools folder in the Sunshine directory. By default, Sunshine installs itself at the following directory:

C:\Program Files\Sunshine\tools

Right-click an empty spot in the folder and select "Show more options" from the pop-up and "Open in terminal" from the context menu.

Once you're in PowerShell, enter the following command to launch the tool:

.\\dxgi-info.exe
Screenshot of the dxgi-info tool's output

You'll be presented a list of devices. Scroll down to find your preffered video adapter and its connected displays' ID values. You may also need to set the virtual display as your primary monitor. This will ensure games and windows will launch on that display by default.

External access over the internet

By default, Sunshine can only be accessed from machines on the local network. However, it can easily to configured to allow external connections so you can connnect to your machine from anywhere.

Warning: Exposing a remote desktop solution to the internet is not something you should do carelessly. If compromised, it could allow full control your PC. Be sure to use a complex password to prevent brute force attacks.

Configuring Sunshine for external access

To enable external access, we'll first need to enable Sunshine's UPnP rule. To enable the feature, navigate to the Sunshine GUI and enable UPnP in the General tab. This will add a rule to your machine's firewall and send a configuration request to your router. Once enabled, restart Sunshine.

In most cases, this should be all you need to enable remote connections.

Sunshine Network Ports

Should your network not support automatic configration, you may need to manually set your firewall or forward traffic to a specific machine. Should that be the case, the following table outlines the ports Sunshine needs to operate:

Description Port Protocol
HTTPS 47984 TCP
HTTP 47989 TCP
Web 47990 TCP
RTSP 48010 TCP
Video 47998 UDP
Control 47999 UDP
Audio 48000 UDP

If you need to configure Sunshine to utilize ports other than the default set, check the Sunshine Documentaition guide for more information.

Configuring Moonlight to access an external machine

To connect to a machine via internet, you'll need to manually add the machine as it won't automatically appear in your list.

In Moonlight, press the "Add PC Manually" button as type in the IP. You should not need to specify the port.

Finding your public IP

To connect to the host from an external network, we'll need its public IP; the address that's exposed to the internet. You can use websites like WhatIsMyIP.com from the client machine to find it.

Useful shortcuts

Depending on the platform you're using, there are a few shortcuts available in Moonlight that can be quite helpful. You can find a full list of them on the Moonlight Github wiki but I've listed the ones I use regularly below.

Gamepad

Shortcut Description
Start (Hold 2 secs.) Toggle virtual mouse mode
Start + Select + L1 + R1 Disconnect the client

PC/Windows

Shortcut Description
Ctrl + Alt + Shift + D Minimize the client
Ctrl + Alt + Shift + Q Disconnect the client
Ctrl + Alt + Shift + M Toggle mouse capture mode
Ctrl + Alt + Shift + S Toggle on-screen performance display
Ctrl + Alt + Shift + X Toggle fullscreen/windowed mode
Ctrl + Alt + Shift + Z Toggle key capture (alt-tab and the like)

Other resources

Moonlight Setup Guide

Moonlight Docs | GitHub

Sunshine Installation

Sunshine Documentation | Lizardbyte

Moonlight Streaming subreddit

reddit

CloudyGamer subreddit

reddit