I just bought myself a little USB endoscope for looking into all those difficult to get to places for grand sum of £9.95. The trouble was I couldn’t the damn thing to connect up to VLC on Ubuntu 22.04 (installed as a snap package). In fact I couldn’t even get the built in camera to connect to VLC! All I ever got was errors like this in VLC on Ubuntu 22.04
I looked in in the system log (aka /var/log/syslog). This is what I found:
v4l2 demux error: cannot open device '/dev/video0': Operation not permitted
I tried loads of different thing all to no avail. Then I tried using Cheese, an web cam viewer application that gets bundled in with the standard install of Ubuntu 22.04. That worked fine with my integrated webcam in my laptop but had issues with the USB cam (aka the Endoscope) which cost me a lot of time.
Side Tracked by Cheese
Basically with Cheese if I start it up and the first cam it loads it the integrated cam I can then change over to the USB cam using the preferences menu (which for some bizarre reason lists the USB camera and the integrated camera twice). BUT if you then back out and it tries to load the USB camera first you get this.
I ended up thinking that cheese couldn’t use the USB camera. In fact if I started up with the integrated camera and switched over using the preferences then it worked. So somewhere along the line the integrated camera did some set up needed by the USB camera. I still don’t know what the problem is with Cheese. But if for some reason I wanted to use the USB camera with it instead of the integrated camera I’d have bring up the integrated camera first. Hey Ho.
Back to VLC
Anyway back to VLC. I could not get the damn thing to work at all. I Googled until I must have nearly brought Google’s server farm down. From my googling there were three things I did that fixed the problem. Arguably only the last one is really necessary.
First I added the user (aka chalkie) to the group video like this:
sudo usermod -a -G video chalkie
While that seemed a good idea it didn’t help.
Next I installed a set of tools which though very useful didn’t fix the problem either
sudo apt install v4l-utils
Finally I found a one-liner in a post (at the very bottom) that IMHO fixed the problem.
The issue is that my VLC is SNAP package! Canonical Snapcraft have this rather terse webpage on snap packages and how they access cameras. https://snapcraft.io/docs/camera-interface
As a result it does not have permission to access hardware like the integrated camera or the USB camera. So I needed to give VLC permission to link to the cameras. Like this
snap connect vlc:camera :camera
After that VLC could connect to the cameras via the menu media->open capture device->device name.
I selected v4l2:/dev/video0 and it worked.
Then I tried v4l2:/dev/video1. This failed.
Selection v4l2:/dev/video2 selected the second camera.
Finally I tried v4l2:/dev/video3. This also failed.
BUT… I had got the damn this to work. (of sorts) I Have no idea why I’ve got four entries yet only two cameras. But never mind. Time for a beer.
The rest of my Linux/Ubuntu posts can be found Here.