How To Use Your Webcam On Linux
Any trained gerbil can use a webcam on Linux. It takes a real Linux enthusiast to troubleshoot webcam issues successfully. Best read while listening to The Joker - Steve Miller Band.
There was a time not too many years ago when using secondary devices like webcams would have been a nightmare with most Linux distributions. Then one day, a single individual changed everything with a single focus - making webcams work with Linux distributions of the era.
French programmer Michel Xhaard took the bull by the horns and forever charged history for Linux-loving webcam users. He did so for free, and I thank him for getting us where we are today. Well, at least for those of us with webcams working flawlessly.
Thanks for reading Gloves Off Linux! Subscribe for free to receive new posts and support my work.
My webcam isn't working
As we flash-forward into 2022, our current Linux community has many newer Linux enthusiasts coming into the fold. And while I welcome our new brothers and sisters to the community, their expectations and assumptions sometimes frustrate me. Even though modern Linux kernels are nearly on-par with new hardware compatibility, there will always be that one rogue issue that crops up.
A common one is a user stressing out because they don't believe their webcam is working. In truth, this isn't usually the issue. Most of the time, this is a matter of understanding how any given Linux distribution is talking to the device in question.
Look, I get it. When you come from Windows, having a Linux distribution, not magically "just work," must seem like a bummer deal.
Unlike the "magic school bus of screams" that is the Windows Device Manager with its ever-helpful Unknown device error, Linux users have a multitude of command line tools to detect hardware at various levels. See, in Linux, it's either detected or not. While there have been rare exceptions, if it's detected, it's detected. This means any functional failure may not be a problem with drivers at all.
Short of hardware failure, I will bet you money if you run the correct commands; the distribution you're running "sees" the webcam. Not to worry, your Linux distribution isn't looking at you through your webcam. After all, your webcam isn’t working, right?
Stop blaming drivers for software problems
Okay, say it with me - your inability to get Cheese or Zoom to see your webcam does not translate into "Linux sucking." Some Linux users opt to toss in the towel instead of the user trying other software to see if the problem repeats itself.
I've seen instances where someone believes nothing is using their webcam, but the user is unable to activate the camera with their webcam software. How can we be sure?
Open a terminal and paste in the following (tested on Ubuntu/Debian-based distributions):
sudo fuser -v /dev/video*
Did it report that an application such as a browser is using it? Then as you look closer, you realize you still have a WebRTC instance showing video in another browser tab. It happens a lot.
Look, your Linux distribution likely has nothing using your webcam despite a random GUI application indicating the web camera is the problem. But why do so many people always conclude that something is "wrong" at the operating system level when using Linux? I believe it all starts with perspective.
Linux software isn’t made for chocolate
If I thought it would help, I'd be inclined to climb onto a tall mountain, dress in a long white robe, and dispense the following wisdom; "Stop relying exclusively on GUI applications."
I get it. Making buttons go "clickity-clack" is more straightforward than typing in a bunch of commands. And when it comes to launching and running an application, GUIs are "a bucket of giggles." But I take issue with the idea that the Linux distribution is broken if a GUI application fails. This is wrong on every level. Think I'm all wet on this one? Check this out…
Close your eyes for a second. Yes, close them. Okay, now imagine you have your favorite candy bar in front of you. Stop, don't even claim you don't have one. I'm looking at you, John-Bob!
Now in your mind's eye, attempt to unwrap the candy bar you envision. You realize you can't quite get it open no matter how much you struggle with it. After the better part of five minutes, you realize that despite the promise of an easy-to-open wrapper…that candy bar isn't going to unleash its chocolaty goodness without intervention from a sharp-bladed object.
This presents a problem.
Here you are, finally sitting down for the evening, and now your future is dictated by a freakin' candy bar! Surely there has to be a better way? After all, getting up and walking to another room for scissors is for chumps! These stupid wrappers are supposed to "just work!" You know what, forget it.
After tossing the candy bar into the trash can, you decided that you're no longer going to support "Big Chocolate" and their false advertising of easy unwrapping if you are forced to use scissors!
Alright, everyone, do you see how silly this is? Now take everything mentioned above and apply it to the software for your webcam.
No, stop. Put the chocolate away - it was merely a plot device. There is no need to soak your webcam in chocolate syrup. Then again, it might make for an interesting visual filter. Ugh, I digress.
The point is that just because your webcam isn't working in a GUI doesn't mean it won't work with your Linux distribution.
Webcam troubleshooting 101 - let the CLI reign supreme
Previously we used the “fuser command” to determine that nothing else was using the webcam, thus preventing your software from accessing the device. Great, but we need to triple-check that the webcam is detected.
Rather than taking the lower-level approach of listing USB devices, I want to use a command that is better suited for those of you who use laptop webcams (shudder). Sorry, not a fan of those little buggers.
First, we need to install "the happy bits" to ensure the commands we’re using will work. As usual, this article will assume you're on an Ubuntu-based distribution. If not, your installer and CLI commands will likely differ.
Open a terminal window, run the following:
sudo apt-get install v4l-utils ffmpeg
With v4l-utils installed, let's see if your computer sees any webcams or not.
Now on my computer, I have a Brio webcam hooked up. So my results look like this:
Logitech BRIO (usb-0000:00:14.0-4.1):
Fantastic. Now we know that your webcam is detected on /dev/video0. This gives us something to point at for additional commands.
A moment ago, we installed two packages - one of which was FFmpeg. This powerful tool comes with some extra goodies like FFplay. This will allow us to play media from a terminal prompt inside its separate window. Let's use it to see if our webcam can function at its most basic level.
This will launch a video window displaying what your webcam sees. Depending on several factors, the video displayed before you will be awesome or terrifying. These factors include the default settings for frame rate, resolution, and what you decided to wear that day. Unfortunately for me, today was laundry day.
At this stage of the game, we've determined the following:
The webcam isn't already in use.
You now know what your default resolution and frame rate look like.
Today is laundry day, and your "fresh from the hamper" shirt is covered in Cheeto dust.
The next step is to create a video file from your webcam with specific presets. We'll adjust the frame rate and resolution used to record video to an mkv container.
ffmpeg -f v4l2 -frame rate 30 -video_size 1280x720 -input_format mjpeg -i /dev/video0 -c copy out.mkv
The above command provides us with the following settings:
The settings use v4l2 to grab from your webcam.
A 30 FPS frame rate.
Set the video recording resolution at 1280x720.
We're using mjpeg (aka motion jpeg) as it's a reliable input format used for testing.
We're "copying out" to a file called "out.mkv" in your user's home directory.
Fantastic! A new video file appeared in your home directory - bet you feel accomplished! Before we break out the good china set from the cupboard to celebrate, let's ensure everything pops out correctly. We'll be using FFprobe for this task.
Unlike an alien probe from Martians, no abduction or long metal instruments are required - only your terminal will be employed for this operation. You will want to maximize your terminal for this as it makes for easier reading.
Here, FFprobe assumes the file is in your home directory, and once you get past the text vomit that is FFmpeg bragging about its configuration abilities, you'll find the part we care about.
Input #0, matroska,webm, from 'out.mkv':
ENCODER : Lavf58.76.100
Duration: 00:00:15.79, start: 0.000000, bitrate: 26797 kb/s
Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 1280x720, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
DURATION : 00:00:15.786000000
Wow, what a fantastic wall of text! Hang on, let me break this down for you.
Input #0, matroska,webm, from 'out.mkv' (we used webm in from the camera and spit it out as an mkv container. Not going to dive into this right now, but I encourage you to explore what these containers are.)
ENCODER : Lavf58.76.100 (The encoder used to produce the created mkv file.)
Duration: 00:00:15.79, start: 0.000000, bitrate: 26797 kb/s (Duration of the recording, bitrate it was recorded with.)
Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 1280x720, 30 fps, 30 tbr, 1k tbn, 1k tbc (default) (Without going too deep, video was motion jpeg, the color space used, the resolution did record at 1280x720 with a 30 FPS frame rate.)
At this point in the article, most of you may be pondering some variation of the following; "That's great, Matt. But I still can't Zoom-call my sister's cat!"
Fair enough, but even though Zoom or Cheese or whatever else hasn't been addressed yet - something else very important has been touched on directly. If the previous commands worked, then your webcam works flawlessly in Linux. Now let's not keep "Mr. Frisky the cat" waiting for his weekly Zoom interaction. Let's look at what may be happening with the non-functional GUI software.
Diagnosing why your webcam isn't working in _______
Causes as to why a particular piece of software isn't being detected or working with your webcam will vary. The reasons are vast and mysterious. The causality is meaningless unless you're a software developer maintaining the application.
As a general rule, here are some things we can do right off the bat as end users.
Test all the commands above. Especially using the previously mentioned fuser command.
Update the packages for your distribution. In short, run those updates. This means dpkg, flatpak, and snaps.
Check the software provider's website for an update if the software in question was a deb package. I noticed this helped with a sound input issue on Zoom - updated to a newer version of the software, rebooted, problem solved.
Accept that software often runs behind current Linux distribution releases - especially proprietary applications on Linux.
If the above commands aren't working, try a previous kernel. Pop OS makes this easy. Just follow this guide and choose Pop_OS-oldkern. Ubuntu users, holding down the shift key while booting, will display the Grub menu. You can now select an older kernel version. Odds are this will get your webcam working. Now wait for a bug fix and keep running your updates. These things are rare and are usually fixed quickly.
Fine-tuning your settings with Guvcview
Speaking personally, I like to use an application called Guvcview to make my webcam adjustments. While its video recording abilities are hit and miss, the adjustments I adjust myself work. Each webcam has different abilities.
My Logitech Brio, for example, has all the usual features listed. From setting a custom frame rate, resolution, and focus. But it also has pan and tilt functionality as well. If something doesn't appear as a feature in Guvcview, then your webcam doesn't support that specific feature in Linux.
On Pop OS 22.04, I have found that Guvcview seems to remember my settings when I make changes.
And that's all there is to it. No big celebratory send-off - it's just a matter of some basic troubleshooting and understanding where things are falling off. Once you know, the webcam is working. The rest is determining if your problem software has an update to fix whatever the problem is.
For example, if Cheese is failing…try Guvcview. It has much of the same functionality and has a better track record for just working right the first time. Then again, the latter has UVC in the application's name. It makes you think that perhaps some applications are more reliable than others. Could be.
Thanks for reading Gloves Off Linux! Subscribe for free to receive new posts and support my work.