Inhaltsverzeichnis

v4l2loopback devices for preproduction of webcam streams

Privacy and Home Office

As the Covid19 pandemia leads to a certain need of adaption I had to think about managing my consultant work from my home office. After finding a way to use an unused smartphone as a high level webcam with my PC I found myself exposed to another problem. That wide screen, high resolution cam also meant that my consultees would receive a very exclusive insight in my privacy.

HowTo cut out and make use of a Green Screen

So I thought about buying some printed gradient cardboard background and started my searx instance. And stumbled upon an offer introducing the Elgato Green Screen. You know - green fabric as an background so you can easily cut out a person and let it appear on any other picture behind it. Like you've seen thousands of times in movies, news shows or - of course - YouTube channels!

So I ordered the green screen (which is unfortunately yet to come) and bothered about which software might allow me to preproduce a video stream like this and loop it back to my conferencing services like e.g. browsers' WebRTC. On Linux. And finally came to the following answers:

HowTo edit a video stream

Of course! OBS. The OpenBroadcasterSoftware project is the default solution for any amateur video streamer. And even most famous YouTubers do their work predominantly with that great piece of software. It comes with filters like 'chroma key' for replacing any coloured screen with another picture. And to cut out a smaller fraction of the stream so that not your whole living room goes to public but only your face and some margin around. Not to speak of any combination of multiple camera streams, clips, pictures and whatever visual source one could think of. With a quite handy user interface if you'd ask me. But as I didn't want to record a Let's Play and neither live stream it on twitch ...

HowTo send the processed stream back to my Video Chat application?

As I want to communicate with others via Matrix, JitsiMeet, Nextcloud Talk or any other WebRTC solution I needed a way to send the altered stream back to a /dev/video[n] file on my Linux PC. Fortunately I was obviously not the first to have that idea an a quick search took me to loopback device plugin for OBS. Even better: Someone decided to produce a plugin even for linux! After some fiddling around with that solution I learned:

<cli> sudo apt install obs-studio libobs-dev libobs0 git clone https://github.com/umlaeute/v4l2loopback.git make && sudo make install sudo depmod -a sudo modprobe v4l2loopback devices=1 video_nr=10 card_label=„OBS Cam“ exclusive_caps=1 git clone –recursive https://github.com/obsproject/obs-studio.git git clone https://github.com/CatxFish/obs-v4l2sink.git cd obs-v4l2sink mkdir build && cd build cmake -DLIBOBS_INCLUDE_DIR=„../../obs-studio/libobs“ -DCMAKE_INSTALL_PREFIX=/usr .. make -j4 sudo make install mkdir -p ~/.config/obs-studio/plugins/v4l2sink/bin/64bit cp /usr/lib/obs-plugins/v4l2sink.so ~/.config/obs-studio/plugins/v4l2sink/bin/64bit </cli>

If you experience annoying video lag

You may experience some annoying asynchronicity of video and audio following this procedure (only inside OBS! Iriun App shows perfect synchronicity.). Especially if you use a smartphone as webcam like obviously me.

By some desperate trials and errors I found a solution which actually works fine for me: