OBS Studio Virtual Camera on FreeBSD
Update 2021-11-05: the patch for OSB Studio mentioned below is now included in the OBS Studio port on FreeBSD, and no longer needs to be manually applied. All that's needed now is to start the virtual camera device & install OBS Studio, either from ports or pkg.
The Virtual Camera feature in OBS Studio allows a scene to be output to a virtual webcam that can be used by other applications. For example, video from a screen recording or an network camera can be captured and processed in OBS Studio, with the final video made available to other programs such as video conferencing applications.
Recently, support for virtual cameras was ported from v4l2loopback
on Linux into FreeBSD through webcamd
. This page documents how to use the OBS Virtual Camera on FreeBSD, tested on 13.0-RELEASE. (I use the OBS Virtual Camera for videoconferencing with Droidcam, which also can support FreeBSD.)
First, install webcamd
:
# pkg install webcamd
Load the required cuse
kernel model with
# kldload cuse
Next, create a v4l2loopback
device using webcamd
. We'll simply create the device and run webcamd
in the foreground:
# webcamd -c v4l2loopback
For more options, take a look at man 8 webcamd
.
Next, we'll need to build OBS Studio. As of October 2020, support for the Virtual Camera on FreeBSD has not been merged. We'll need to apply the patch ourselves.
If your ports tree is up-to-date, navigate to /usr/ports/multimedia/obs-studio
. Download the patch from Github into the files
directory:
# fetch -o /usr/ports/multimedia/obs-studio/files/patch-plugins_linux-v4l2_v4l2-output.c https://patch-diff.githubusercontent.com/raw/obsproject/obs-studio/pull/5069.diff
You'll need to modify the patch slightly to match the expected format for the ports system. Open it up, remove the first two lines, and get rid of the a/
and b/
prefixes on the next two lines. (If you'd like, you can download the edited patch here.) This is what the start of the patch should look like when you're done:
$ head /usr/ports/multimedia/obs-studio/files/patch-plugins_linux-v4l2_v4l2-output.c
--- plugins/linux-v4l2/v4l2-output.c
+++ plugins/linux-v4l2/v4l2-output.c
@@ -27,6 +27,7 @@ static void virtualcam_destroy(void *data)
bfree(data);
}
+#ifdef __linux__
Now, you should be able to simply build and install the port. From the /usr/ports/multimedia/obs-studio
directory,
# make install
You should now be able to open OBS, compose scenes, and start the virtual camera: