How To Cast Your GNOME Shell Desktop To A Chromecast (With Audio, Wayland / X11 Support) Using Cast to TV

Cast to TV, a GNOME Shell extension to cast files and more to Chromecast devices (and more), was updated recently with support for casting your desktop, with sound, which works with both Wayland and X11. This is done with the help of a helper add-on called Cast to TV - Desktop Stream Add-on, which recently had its first release on the GNOME extensions website.

For desktop streaming to work, you need Cast to TV version 14 or newer, which only supports GNOME Shell 3.36 and 3.34 (Ubuntu 20.04 and 19.10, and Fedora 31 and 32 for example). This means that this isn't available for older Linux distributions that use older GNOME Shell versions, like Ubuntu 18.04 or Fedora 30.

Stream GNOME Shell desktop to Chromecast

This article explains how to use Cast to TV (and its helper add-on) to cast your GNOME Shell desktop to a Chromecast device, with sound, which works with both X11 and Wayland. The step-by-step instructions are for Debian / Ubuntu / Pop!_OS, Fedora and Arch Linux / Manjaro (the steps should be the same on any GNOME Shell based Linux distribution, but the packages might have different names).

Officially, you can stream your Linux desktop to a Chromecast by using Google Chrome. Cast to TV has some advantages over Google Chrome for Chromecast desktop streaming though:

  • it's not tied to Google's browser
  • it streams your desktop with working audio, which doesn't work on Linux with Google Chrome
  • it supports Wayland, this probably being the only way to cast your desktop to a Chromecast device from Wayland
  • it has customizable video bitrate and fps
  • it has hardware acceleration (VAAPI for Intel/AMD and NVENC for Nvidia graphics)
  • and you also get the option of showing or hiding your mouse cursor.

Google Chrome has a couple of advantages over Cast to TV too: it has a lower stream delay (Cast to TV currently has a delay of about 3 seconds), and it works with desktop environments other than GNOME Shell. So use whichever solution suits your needs best.

Cast to TV can do a lot more than cast your desktop to a Chromecast. It can also cast local pictures, video and audio files with optional transcoding, GPU-accelerated video encoding for low CPU usage, subtitles, and more. Check out its project page for details.

You might also like: Chromecast Extension For Firefox fx_cast 0.0.5 Adds Support For YouTube, Subtitles For Local Media.

Setting up Cast to TV for casting your desktop to a Chromecast, in Debian / Ubuntu / Pop!_OS, Fedora or Arch Linux / Manjaro


To use Cast to TV to stream your GNOME Shell desktop (version 3.34 or 3.36 only!) to a Chromecast, you'll need to install Cast to TV version 14 (or newer) and Cast to TV Desktop Add-on, install some GStreamer plugins, and tweak some PulseAudio settings. This is what you need to do in detail, on Debian / Ubuntu, Fedora or Arch Linux / Manjaro.

Using these steps, the whole Cast to TV functionality will be enabled, so you won't have just the ability to cast your desktop, but also cast video, music and pictures from your GNOME Shell desktop.

More ways of streaming to a Chromecast from Linux:


1. Install the required Cast to TV and Cast to TV - Desktop Add-on dependencies.

Cast to TV extension requires npm and Node.js for some modules, and FFmpeg for transcoding. Cast to TV - Desktop Stream Add-on has some dependencies too: the GStreamer base, good, bad and ugly plugins.

PulseAudio (and pacmd) are also required, but these should already be installed in most cases.

Install the dependencies using:

  • Debian / Ubuntu / Pop!_OS:
sudo apt install ffmpeg npm nodejs gstreamer1.0-plugins-{base,good,bad,ugly}

  • Fedora:
You need to enable the RPM Fusion repository to install FFmpeg and some GStreamer plugins (in case you haven't enabled this repository already), then install the packages:

sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

sudo dnf install ffmpeg gstreamer1-plugins{base,good,bad-free,ugly}

  • Arch Linux / Manjaro:
sudo pacman -S ffmpeg npm nodejs gst-plugins-{base,good,bad,ugly}

2. Install the optional dependencies.

There are some optional dependencies too. While to use hardware accelerated recording with Nvidia drivers (NVENC) you don't need to install any extra package because it's already available in the GStreamer1-plugins-bad package (it depends if your Linux distributions enables this though, it might not be available), for VAAPI (Intel/AMD) you need to install the GSttreamer1-vaapi package:

  • Debian / Ubuntu / Pop!_OS:
sudo apt install gstreamer1.0-vaapi

  • Fedora:
sudo dnf install gstreamer1-vaapi

  • Arch Linux / Manjaro:
sudo pacman -S gstreamer-vaapi

It's very important to take into consideration that the GStreamer implementation of hardware acceleration (both VAAPI and NVENC) is "kind of experimental", notes the Cast to TV Desktop Add-on wiki, and using it might crash GNOME Shell. I did not try using hardware acceleration in my test of streaming my GNOME Shell 3.36 desktop to a Chromecast, because my Nvidia graphics doesn't support NVENC.

So if your desktop crashes or you're not able to cast your desktop to a Chromecast while using hardware acceleration, disable it (Cast to TV preferences -> Add-ons > Desktop -> Hardware acceleration: None).

On Debian / Ubuntu, there's one more optional dependency. The GStreamer plugins don't have the fdkaac and faac AAC audio encoders enabled by default, with only voaacenc being available, which is rather old. For better audio streaming on Debian / Ubuntu you can use the FFmpeg GStreamer plugin (which in recent Debian / Ubuntu versions is using FFmpeg, despite libav being in the package name), which provides support for avenc_aac AAC audio encoding. Install this package:

sudo apt install gstreamer1.0-libav

3. Install Cast to TV and Cast to TV Desktop Stream Add-on.

The extensions are available on the GNOME Shell extensions website. You could install Cast to TV, followed by Cast to TV Desktop Stream Add-on, by using GNOME Software, if it allows installing GNOME Shell extensions on your Linux distributions.

Or you can follow the instructions from the GNOME wiki to integrate GNOME Shell with Google Chrome and Firefox, and then you'll be able to install GNOME Shell extensions using these 2 web browser. After following those instructions, visit the Cast to TV extension page from the GNOME Shell extensions website and click the OFF button in the upper right-hand side corner of the web page to install it. Then do the same for the Cast to TV - Desktop Stream Add-on.

The extensions installation is not done at this point, as you need to install some npm modules. You'll need to open the Cast to TV preferences.

I need to make an important note here. The Cast to TV v14 release notes mention that a bug in GNOME Shell 3.36.1 prevents opening the extension preferences from the GNOME system menu ("Cast settings"). This doesn't happen for me on Ubuntu 20.04 with GNOME Shell 3.36.1 though, probably thanks to some patch that gets this to work, but if you stumble onto this issue on another Linux distribution, open the Cast to TV preferences by using the new GNOME Extensions app (introduced with GNOME 3.36).

Cast to TV install npm modules

In the Cast to TV preferences, switch to the Modules tab and click Install npm modules at the bottom of the window (screenshot above). Do this after installing both Cast to TV and Cast to TV Desktop Add-on, as both require installing some npm modules.

4. Enable streaming your desktop with audio to the Chromecast.

There are two requirements for getting the GNOME Shell desktop streaming to Chromecast devices to work with audio.

The first is to select an AAC plugin that's available on your system, in the Cast to TV extension preferences. To see which AAC GStreamer plugins are available on your system, use (you don't need all, one is enough):

gst-inspect-1.0 fdkaac
gst-inspect-1.0 faac
gst-inspect-1.0 avenc_aac
gst-inspect-1.0 voaacenc

If you get "No such element or plugin" as output, e.g. on Ubuntu:

$ gst-inspect-1.0 faac
No such element or plugin 'faac'

That means the plugin is not available so you can't use it in the Cast to TV settings to stream your desktop with audio to a Chromecast.

If instead you get some output, like this:

$ gst-inspect-1.0 avenc_aac
Factory Details:
Rank                     none (0)
Long-name                libav AAC (Advanced Audio Coding) encoder
Klass                    Codec/Encoder/Audio
Description              libav aac encoder
Author                   Wim Taymans <wim.taymans@gmail.com>, Ronald Bultje <rbultje@ronald.bitfreak.net>

Plugin Details:
Name                     libav
Description              All libav codecs and formats (system install)
Filename                 /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstlibav.so
Version                  1.16.2
License                  LGPL
Source module            gst-libav
Binary package           GStreamer libav Plugins (Ubuntu)
Origin URL               https://launchpad.net/distros/ubuntu/+source/gst-libav1.0
........

This means that particular plugin is available on your system and you can select it from the Cast to TV extension preferences (Add-ons -> Desktop -> Audio encoder). Also enable Stream with audio for casting your desktop with audio:

Cast desktop linux preferences

On Debian and Ubuntu, fdkaac and faac are not available in GStreamer, that's why I recommended installing gstreamer1.0-libav, to be able to use avenc_aac. On Arch Linux / Manjaro, both fdkaac and faac should be available after installing the GStreamer base, good, bad and ugly plugins so use one of those. On Fedora, after installing the GStreamer plugins you should have fdkaac as available, so use that.

If you don't choose an available AAC encoder in the Cast to TV preferences, casting your desktop to a Chromecast will fail (you won't even get video casting). If for whatever reason you don't have any AAC encoder available on your system, disable audio streaming (available in the Cast to TV preferences) to at least get desktop streaming to work.

And the second requirement needed for casting your GNOME Shell desktop to a Chromecast with audio is to change the PulseAudio /etc/pulse/default.pa configuration with any text editor as root, for example Gedit (Text Editor), the default GNOME text editor:

gedit admin:///etc/pulse/default.pa

and change the line containing:

load-module module-stream-restore

to:

load-module module-stream-restore restore_device=false

Save the file, and restart PulseAudio:

pulseaudio -k

Native audio sink selection in GJS is planned for a future Cast to TV Desktop Add-on, but until then you need to use this manual tweak of the PulseAudio configuration file.

5. Cast your GNOME Shell desktop to a Chromecast device.

Cast to TV desktop streaming

Cast to TV remote desktop stream

Now you can cast your Linux GNOME Shell desktop to a Chromecast. From the GNOME Shell system menu expand the Cast Media item, then click on Desktop.

Once you start casting your desktop to the Chromecast device, see a yellow-orange dot (it means that the GNOME Shell built-in screen recorder is active), as well as the Cast to TV remote on the top panel - from there you can stop casting your desktop by pressing the stop button (this isn't shown until you start casting).