Skip to content

Instantly share code, notes, and snippets.

@kiryasolod
Last active August 24, 2024 01:40
Show Gist options
  • Save kiryasolod/4f9ef434092c91030f3e654f216cc4fc to your computer and use it in GitHub Desktop.
Save kiryasolod/4f9ef434092c91030f3e654f216cc4fc to your computer and use it in GitHub Desktop.
Discord Wayland full-screen streaming in ArchLinux (tested on Hyprland)

1. Add yourself to video group

sudo usermod -aG video <username>

2. Add some variables (I'm not sure it's necessary)

export XDG_RUNTIME_DIR="/run/user/$(id -u)"

3. Install packages

sudo pacman -S wf-recorder v4l2loopback-dkms v4l2loopback-utils

4. Execute the following commands. They will create config files for modprobe service

echo "v4l2loopback" | sudo tee /etc/modules-load.d/v4l2loopback.conf

echo 'options v4l2loopback video_nr=10 card_label="Wayland Virtual Webcam"' | sudo tee /etc/modprobe.d/v4l2loopback-options.conf

The video_nr=10 is a /dev/video10 device

The Wayland Virtual Webcam is your webcam name than you will see in apps like Discord

5. Reload the modprobe service to get loopback module loaded automatically when system starts

sudo systemctl enable --now systemd-modules-load.service

6. Create a file /usr/bin/sharescreen

with the following content:

#!/bin/bash

wf-recorder --pixel-format=yuv420p -fflags +genpts --geometry="0,0 1920x1080" --filter=hflip --muxer=v4l2 --codec=rawvideo --file=/dev/video10 -t

You can adjust your geometry that you want to stream. If your watchers get a flipped picture, you can remove --filter=hflip. Beware that Discord can show a flipped picture only for you, and people who watch your stream should get normal picture. Anyway you can play with it.

Your /dev/video10 device was created by setting video_nr=10 in v4l2loopback options

7. Make your /usr/bin/sharescreen executable

sudo chmod +x /usr/bin/sharescreen

8. Then execute it! Then you can choose your Wayland Virtual Webcam in Discord and start your stream! By the way, without any resolution and framerate limits for free! You can also bind some shortcut in Sway of Hyprland. For example here is my binding in Hyprland: bind = $mainMod SHIFT, F1, exec, pkill wf-recorder || sharescreen to start and to stop streaming I use Win + Shift + F1 shortcut

@salehjg
Copy link

salehjg commented Aug 24, 2024

wf-recorder: invalid option -- 't'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment