Sometimes in meeting software screen sharing is needed but broken on linux somehow (thank you chrome) or you have to pay for it (slack …). This is, where sharing your screen by virtual WebCam comes in handy. You can do this via the video4linux loopback device. This will create a dummy camera device, that you can feed by ffmpeg grabbing your screen.

This might only work with kernel versions later then 6.8, at least this did not work on a Ubuntu with a kernel that old. You’ll need to install and enable v4l2loopback, install the linux-headers to if you haven’t done so, jet:

$ sudo apt install v4l2loobback-dkms linux-headers

Check your current video devices with ls -lha /dev/video* then load the module.

$ sudo modprobe v4l2loopback devices=1 max_buffers=2 exclusive_caps=1 card_label=VirtualCam

Check again which new device appeared, there should be a new one.

Make sure your user belongs to the group video. Add it by $ usermod -aG video $ME (log off and on!).

Now you can use ffmpeg to feed your screen into your virtual camera device:

$ ffmpeg -f x11grab -r 15 -s 1280×720 -i :0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video2

-r is the frame rate, -s the screens resolution, -i the screen shared. On my setup /dev/video2 is the virtual camera device, seen as VirtualCam in any WebCam software.

In complex display setups it is possible to share just part of the whole screen. In my case I’d like to share only my laptops native display. To get that part I ask xrandr for the current configuration.

$ xrandr
Screen 0: minimum 320 x 200, current 4320 x 1920, maximum 16384 x 16384
eDP-1 connected primary 1920×1080+2400+840 (normal left inverted right x axis y axis) 309mm x 174mm
1920×1080 60.05*+ 60.01 59.97 59.96 59.93 48.04
1680×1050 59.95 59.88
1400×1050 59.98
1600×900 59.99 59.94 59.95 59.82
1280×1024 60.02
1400×900 59.96 59.88
1280×960 60.00
1440×810 60.00 59.97
1368×768 59.88 59.85
1280×800 59.99 59.97 59.81 59.91
1280×720 60.00 59.99 59.86 59.74
1024×768 60.04 60.00
960×720 60.00
928×696 60.05
896×672 60.01
1024×576 59.95 59.96 59.90 59.82
960×600 59.93 60.00
960×540 59.96 59.99 59.63 59.82
800×600 60.00 60.32 56.25
840×525 60.01 59.88
864×486 59.92 59.57
700×525 59.98
800×450 59.95 59.82
640×512 60.02
700×450 59.96 59.88
640×480 60.00 59.94
720×405 59.51 58.99
684×384 59.88 59.85
640×400 59.88 59.98
640×360 59.86 59.83 59.84 59.32
512×384 60.00
512×288 60.00 59.92
480×270 59.63 59.82
400×300 60.32 56.34
432×243 59.92 59.57
320×240 60.05
360×202 59.51 59.13
320×180 59.84 59.32
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-1 disconnected (normal left inverted right x axis y axis)
DP-2 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)
DP-3 disconnected (normal left inverted right x axis y axis)
DP-1-1 disconnected (normal left inverted right x axis y axis)
DP-1-2 connected 1200×1920+0+0 left (normal left inverted right x axis y axis) 518mm x 324mm
1920×1200 59.95*+
1920×1080 60.00 50.00 59.94 30.00 25.00 24.00 29.97 23.98
1600×1200 60.00
1280×1024 75.02 60.02
1152×864 75.00
1280×720 60.00 50.00 59.94
1024×768 75.03 60.00
800×600 75.00 60.32
720×576 50.00
720×480 60.00 59.94
640×480 75.00 60.00 59.94
720×400 70.08
DP-1-3 connected 1200×1920+1200+0 right (normal left inverted right x axis y axis) 518mm x 324mm
1920×1200 59.95*+
1920×1080 60.00 50.00 59.94 30.00 25.00 24.00 29.97 23.98
1600×1200 60.00
1280×1024 75.02 60.02
1152×864 75.00
1280×720 60.00 50.00 59.94

On my whole Screen 0, made of 3 displays (4320 x 1920), this is eDP-1, sitting at the coordinates 2400,840. I have to change the -i option to -i:0.0+2400,840 and the resolution of the video to -s 1920x1080.

The complete ffmpeg line is:

$ ffmpeg -f x11grab -r 15 -s 1920×1080 -i :0.0+2400,840 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video2

Now your virtual webcam should stream the screens content.

(swg>