Monday, December 28, 2020

OBS on Linux: Green screen and virtual camera for video conferencing

OBS Studio: My monkey enjoys the beach
Similar to many of you, part of my work and hobbies consists of video conferencing. For some time now, I have been using OBS Studio (Open Broadcaster Software) to create a virtual camera on my Linux system. Recently, I had to upgrade my kernel. It required to recompile some file and reminded me that I wanted to blog about it. As usual, this is how I remember all the interesting stuff. So what is needed to create a virtual camera with OBS Studio and can you use a green screen for some beach feeling like shown?

OBS Studio and Video4Linux

The main ingredients to the virtual camera are OBS Studio (or just OBS) and Video4Linux (V4L / V4L2). The former is a powerful tool for video recording and live streaming. It allows to combine multiple sources, add effects and either record or stream the result to various platforms and formats. The latter, V4L2 - version 2 of V4L, is a set of drivers and utilities for video capturing and processing. I am using a so-called virtual loopback device provided by  v4l2loopback to make my output stream available as new input device. Thus, my output from OBS can be made accessed as a webcam in tools like Webex, Teams, Alfaview, Slack, Zoom and others.

For OBS to write to the virtual device, it needs to have the plugin obs-v4l2sink (V4L2 Video Output) installed. Once installed, it is available in OBS under Tools.

The steps to download, build and install the loopback device and the plugin are embedded as gist at the end. The files for the loopback device need to be built for the Linux kernel on your machine. If, like in my case, the kernel is updated, perform a "make clean", then rebuilt and install the files again.

Webcam with green screen

With the virtual loopback device and the OBS plugin in place, it is fairly simple to create the virtual camera. I even bought an inexpensive ("cheap") green screen to improve my virtual backgrounds.

In OBS, I have set up multiple scenes. Typically, they have my webcam on top and use a static image, a specific other window (Firefox / Chrome / Iridium browsers) or parts of my workspace as background. For the webcam I have added two (2) effect filters. One is the Crop/Pad to select only parts of the webcam image. The second is the Chroma Key to use the green screen and tune it to the current lighting and more. See the screenshot below with the stacked effects on the left and the Chroma Key settings on the right.

Chroma Key effect to work with green screen


To touch up video conferencing, even on Linux, is fairly simple and only requires few steps. Of course, the green screen can also be used in recorded videos. To produce a video like the one shown at the top I simply ran a YouTube or Vimeo video in fullscreen mode and configured that window as backdrop.

If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.

Gist with steps