Introduction.
Unlike many Linux distributions the FreeBSD operating system comes quite crude out of the box. What others will interpret as a disadvantage, with some knowledge on the system, others see the power to serve. Anyone willing to have a nice FreeBSD desktop experience with little effort, there are a couple of BSD-based distributions, like GhostBSD, MidnightBSD, NomadBSD or helloSystem. However, if you, like me, like to tinker and go from a crude system to a one configured to serve my purposes only, this how to configure FreeBSD to use a webcam will come handy to you.
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.
Pre-requisites.
In order to configure a webcam on FreeBSD there are little pre-requisites to fulfill prior to it. These are:
- A box, either a laptop, or desktop computer with FreeBSD installed on it.
- An already existing DE installed on such system. If you like Mate, you can follow this guide.
- Basic command line knowledge (editing files, permissions, etc)
- Patience
Synopsis.
In this guide we will install software to use a webcam on FreeBSD. We will edit core files such as /etc/rc.conf to enable services we’ll need to use. We will also load kernel modules, configure entries in the /boot/loader.conf for those modules to be present at boot time. Finally, we will use some software to test the webcam and audio settings. We will even use Microsoft Teams conference software in a call!!
Disclaimer. Milage may vary and your experience may not be as flawless as mine or others. I’ve been using Lenovo laptops for years and have had very good experiences when using FreeBSD on them. I do also tend to use the Mate desktop on laptops or, alternatively, KDE on desktops.
Step 1.- Install software.
In order to configure FreeBSD to use a webcam we need to install some software. Webcamd is the first piece of the puzzle, but there are other programs to be used. Issuing the following command will install all of the pieces.
$ sudo pkg install v4l-utils v4l_compat webcamd
With these pieces installed we move onto the next step and configure some bits here and there.
Step 2.- Configure Webcamd on FreeBSD.
Webcamd will run as a service. For that purpose, we need to place an entry in /etc/rc.conf, the file where all services need to be declared in order to be fired at boot time.
$ sudo sysrc webcamd_enable="YES"
As a second bit to configure we also need to add the user to be engaged into using the webcam to be included in the webcamd group. For that issue the following command, adjusting the ‘USERNAME’ bit to yours.
$ sudo pw groupmod webcamd -m USERNAME
The other bit missing is identifying which device entry the webcam is. For that we can use webcamd itself. For example, in an old Lenovo T430 this is the list of devices.
[albert@BSDTest ~]$ sudo webcamd
Available device(s):
webcamd [-d ugen0.1] -N Intel-XHCI-root-HUB -S unknown -M 0
webcamd [-d ugen1.1] -N Intel-EHCI-root-HUB -S unknown -M 0
webcamd [-d ugen2.1] -N Intel-EHCI-root-HUB -S unknown -M 1
webcamd [-d ugen0.2] -N vendor-0x2357-TP-Link-UB500-Adapter -S E848B8C82000 -M 0
webcamd [-d ugen0.3] -N Lenovo-H5321-gw -S A44798C5E0DC6FM0 -M 0
webcamd [-d ugen1.2] -N vendor-0x8087-product-0x0024 -S unknown -M 0
webcamd [-d ugen2.2] -N vendor-0x8087-product-0x0024 -S unknown -M 1
webcamd [-d ugen1.3] -N Lenovo-Integrated-Smart-Card-Reader -S unknown -M 0
webcamd [-d ugen1.4] -N Auth-Biometric-Coprocessor -S unknown -M 0
webcamd [-d ugen1.5] -N Broadcom-Corp-BCM20702A0 -S 3C77E6F22095 -M 0
webcamd [-d ugen1.6] -N Chicony-Electronics-Co---Ltd--Integrated-Camera -S unknown -M 0
Show webcamd usage:
webcamd -h
[albert@BSDTest ~]$
We are interested in the device named “Camera”, of course.
Tip. Your entries will probably be different, depending on the hardware pieces assembled in your machine. Find an entry with the webcam, or camera words in it. That is the device entry you will need to use as shown below.
We will now, again, add an entry in /etc/rc.conf for webcamd to load the options we need. In my particular case I’ve used the following:
$ sudo sysrc webcamd_0_flags="-d ugen1.6 -N Chicony-Electronics-Co---Ltd--Integrated-Camera -S unknown -M 0"
This said, it may well work with just this:
$ sudo sysrc webcamd_0_flags="-d ugen1.6”
Once this is in place we need to load the kernel modules in order to configure FreeBSD to use a webcam.
Step 3.- Load kernel modules.
We need to enable a particular kernel module in FreeBSD to make use of a webcam. As a quick reminder, keep the following in mind to dynamically interact with kernel modules in FreeBSD.
# kldlist à lists loaded kernel modules
# kldunload à unloads a kernel module
# kldload à loads a kernel module
Now, we will do two things. One, we will load a kernel module dynamically, while running the system. But two, we will edit the /boot/loader.conf file in order to have it loaded at every boot.
The kernel module we need to load is called cuse. To accomplish that we will issue this command.
$ sudo kldload cuse
To check it is loaded issue this other command.
$ sudo kldstat | grep cuse
Once it’s been loaded we will edit the /boot/loader.conf file and at the end of it we will add a line as this below.
cuse_load="YES"
Tip: You can also load kernel modules by declaring them into /etc/rc.conf but using a different kind of entry. This said, I prefer them to be declared in /boot/loader.conf
Now the kernel module is in place we can move on to the next step and configure USB use. Yes, integrated webcams are typically identified as USB devices.
Step 4.- Configure USB mounting to the user.
We have used webcamd before to search for the webcam device in our system. However, there’s an alternative way to do so, and that is by using the ubsconfig utility installed on the base system.
This utility displays even more information than webcamd.
So, since FreeBSD identifies this webcam as a USB (as many others are too) we need to edit the /etc/sysctl.conf file in order to a regular use be able to mount it.
We only need to edit /etc/sysctl.conf and add the following entry at the very bottom.
vfs.usermount=1
For this to be used with immediate effect and not wait for the next reboot, we need to issue this following command.
$ sudo sysctl vfs.usermount=1
With this in place we can now move ahead in this how to configure FreeBSD to use a webcam.
Step 5.- Initialize the webcamd service.
As any FreeBSD user knows, to start up a service one issues a command like this:
$ sudo service start <servicename>
In our case we need to start webcamd.
$ sudo service start webcamd
To check if the service is running we can issue this next one.
$ sudo service webcamd status
Alternative use ps like this:
$ ps auxww | grep webcamd
Tip. We can start webcamd but it is not a bad idea to reboot the whole system.
Step 6.- Test the system’s webcam.
To test if what we’ve configured works, we can install some software. The package pwcview will allow us to do so.
$ sudo pkg install pwcview
Once installed we have installed this piece, we should be able to issue this next command and see a video window pop up in our screens with what the webcam is currently capturing.
$ pwcview -s svga -f 30
This resulted into this nice video capture. Lightning wasn’t good for video capture, but hey, it was working.
Troubleshooting tips.
Check if webcamd is up and running.
$ sudo service webcamd status
Check if the cuse kernel module is loaded.
$ sudo kldstat | grep ‘cuse’
If there’s no output it is not loaded. If you see a .ko file as a result it’s loaded.
Check if the current user is in the webcamd group.
$ id <username>
Example:
[albert@BSDTest ~]$ id albert
uid=1001(albert) gid=0(wheel) groups=0(wheel),5(operator),145(webcamd)
[albert@BSDTest ~]$
Verify the user is able to mount usb devices.
$ grep 'vfs.usermount' /etc/sysctl.conf
The value should be set to 1 and not 0.
Check if the video devices’ permissions are correct.
If nothing works you can try and modify /dev/video0 and /dev/video1 permissions to 666.
$ sudo chmod 666 /dev/video0
$ sudo chmod 666 /dev/video1
My result was satisfactory after some tinkering and checking. The problem was webcamd wasn’t properly started and had to run webcamd with sudo. Once it was properly configured in /etc/rc.conf everything worked flawlessly.
Step 7.- Testing web services to use the webcam.
This is a crucial step in this guide to configure FreeBSD to use a webcam. Many are using Microsoft Teams and other web services for meetings, formal or informal. While some of them work in Firefox, some do only work with Chromium, the free open source base for Google’s Chrome web browser.
To install Chromium issue this next command.
$ sudo pkg install chromium
Once installed you can visit some testing links, but the real deal is using Microsoft’s Teams, Zoom or similar platforms such as the open source Jitsi.
Alternatively, we can use a test website to see if video capture on a web browser is working using the following site link.
As it can be seen in the video capture above, I was successful in using Teams while running it on the Chromium web browser. And of course, running FreeBSD.
Conclusion.
Configuring FreeBSD to use a webcam isn’t that hard if you know what and where to look for. I hope this helps many newcomers and other users from FreeBSD based distributions to engage on conference calls using their platform of choice.
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.