Video-for-linux

silverblue fedora video4linux dslr obs

V4L Loopback device

This creates a loopback device that effectively creates a virtual webcam from any video source attached to your machine. Physical cameras can become the source of the webcam.. DSLR cameras, Android Devices or virtual devices .. Desktop capture, OBS stream etc.

Install v4l2loopback

Introduction

In SilverBlue you will need to compile v4l2loopback kernel module in a clean toolbox that has a kernel matching the host machine. You will need to create public and private signing keys for secure boot kernels. Your public key will need to be imported into the UEFI secure boot database of certificates. You will sign the newly compiled kernel module with your private key before you can then load the module on the host using insmod.

Compile v4l2loopback kernel module

toolbox create video
toolbox enter video
sudo dnf install gcc kernel-devel kernel-headers kernel-modules
cd ~/workspace/v4l-tools/v4l2loopback
make

Then check if Secure Boot is enabled

mokutil --sb-state

If secure boot is disabled, skip straight to 'Loading the kernel module' otherwise ...

Create Public and Private Secure Boot signing keys

Inside the video toolbox created above do ...

cd ~/workspace/v4l-tools/
openssl req -x5 09 -new -nodes -utf8 -sha256 -days 36500 -batch -config configuration_file.config -outform DER -out public_key.der -keyout private_key.priv

Create a password and then confirm it

Ref: RHEL docs

Import your Public signing key into the UEFI database

From the host, as sudo, do the following ...

sudo su -
cd ~/workspace/v4l-tools/
mokutil --import ~/workspace/v4l-tools/public_key.der

Reboot and you should be presented with a UEFI screen to import the public key and save the password you created above

Ref: RHEL docs

Sign the kernel module with the Private signing key and load it

On the host

sudo su -
cd ~/workspace/v4l-tools/
/usr/src/kernels/$(uname -r)/scripts/sign-file sha256 private_key.priv public_key.der ./v4l2loopback/v4l2loopback.ko
insmod v4l2loopback/v4l2loopback.ko

Setup the Camera(s)

Load 1 or more Loopback devices and label them. eg. this loads 2 devices .. EOS7D for a physical DSLR camera and OBS for a virtual webcam

modprobe v4l2loopback video_nr=8,9 card_label=EOS1100D,OBS

You can then attach the capture from the DSLR to the Loopback device as follows...

gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video8

And you can attach the output of OBS to the OBS virtual webcam from the OBS gui

  • Tools -> V4L2 Video Output
  • Choose /dev/video9 for the Path to V4L2 Device

Useful V4L utils

sudo dnf install v4l-utils

To see a list of attached devices

v4l2-ctl --list-devices

Refs: https://github.com/umlaeute/v4l2loopback https://jpetazzo.github.io/2020/06/27/streaming-part-4-linux/ http://www.gphoto.org/doc/remote/


Droidcam install

wget https://files.dev47apps.net/linux/droidcam_latest.zip
unzip droidcam_latest.zip -d droidcam && cd droidcam
sudo ./install

Set Capture to hi-res

sudo rmmod v4l2loopback_dc
sudo insmod /lib/modules/`uname -r`/kernel/drivers/media/video/v4l2loopback-dc.ko width=1920 height=1080

Start the cli client to connect to the Droidcam app running over wifi/usb

Change the IP to match the IP address shown on the Droidcam Android App

droidcam-cli -v 192.168.207.12 4747

Ref: https://www.dev47apps.com/droidcam/linux/


OBS Install

Install the dnf managed OBS

sudo dnf install obs-studio

OBS Build

You need to build but not install OBS

sudo dnf install \
  https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install \
         make \
         gcc \
         gcc-c++ \
         gcc-objc \
         cmake \
         git \
         libX11-devel \
         mesa-libGL-devel \
         libv4l-devel \
         pulseaudio-libs-devel \
         speexdsp-devel \
         x264-devel \
         freetype-devel \
         fontconfig-devel \
         libXcomposite-devel \
         libXinerama-devel \
         qt5-qtbase-devel \
         qt5-qtx11extras-devel \
         qt5-qtsvg-devel \
         libcurl-devel \
         systemd-devel \
         ffmpeg \
         ffmpeg-devel \
         luajit-devel \
         python3-devel \
         mbedtls \
         mbedtls-devel \
                swig

git clone --recursive https://github.com/obsproject/obs-studio.git
cd obs-studio
mkdir build && cd build
cmake -DUNIX_STRUCTURE=1 ..
make -j4
# sudo make install

You shouldn't need to install the built OBS .. dnf managed one should be fine.

To run OBS, you may need to start it without Wayland viewers. Create a file called 'obs' and place it in ~/bin/obs with the following contents. You'll then need to start OBS from the command line

#!/bin/bash
export QT_QPA_PLATFORM=xcb
exec /usr/bin/obs "$@"

Ref: https://github.com/obsproject/obs-studio/wiki/Install-Instructions#red-hatfedora-based-build-directions


OBS V4L Plugin Build

git clone https://github.com/CatxFish/obs-v4l2sink.git
cd obs-v4l2sink
mkdir build && cd build
cmake -DLIBOBS_LIB="../../obs-studio/build/libobs" \
      -DLIBOBS_INCLUDE_DIR="../../obs-studio/libobs" \
      -DCMAKE_INSTALL_PREFIX=/usr ..
make -j4
sudo make install

OBS Plugin Install

Install OBS plugins by ensuring appropriate built .so file is accessible from your lib64 path

sudo ln -s /usr/lib/obs-plugins/v4l2sink.so /usr/lib64/obs-plugins/v4l2sink.so

Then run OBS and configure the plugin as follows.

Ref: https://github.com/CatxFish/obs-v4l2sink


Troubleshooting

Could NOT find Libobs

Ensure you build OBS Studio then build OBS v4l2sink Make scripts hard code your filesystem paths into the build scripts, so don't rename directories mid way through the build steps for OBS or it's sink plugin.


Bonus Content

If you wanna fix crackling bluetooth audio in Fedora do this

$ sudo sed -i 's/load-module module-udev-detect.*$/load-module module-udev-detect tsched=0/g' /etc/pulse/default.pa

Ref: https://ask.fedoraproject.org/t/my-audio-is-making-horrible-crackling-sounds-what-should-i-do/174

Next Post