Ubuntu 18.04 Webcam streaming problem

I am required to run some video processing algorithms on IP camera stream. I don't have an IP Camera so my idea is to use a webcam as an IP cam for RTSP streaming, which the client machines can acquire and run the algorithms on. I learned that VLC can perform streaming from a webcam. I attached an old webcam to an Ubuntu machine. Here is the information.

$ v4l2-ctl --list-devices
SAMSUNG (SPC-A30M): SAMSUNG (SP (usb-0000:00:14.0-7):
    /dev/video0
    /dev/video1

$ v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUYV 4:2:2

Here is the driver info.

/dev/video0
Driver Info (not using libv4l2):
    Driver name   : uvcvideo
    Card type     : SAMSUNG (SPC-A30M): SAMSUNG (SP
    Bus info      : usb-0000:00:14.0-7
    Driver version: 5.3.18
    Capabilities  : 0x84A00001
            Video Capture
            Metadata Capture
            Streaming
            Extended Pix Format
            Device Capabilities
    Device Caps   : 0x04200001
            Video Capture
            Streaming
            Extended Pix Format
ioctl: VIDIOC_ENUM_FMT
    Index       : 0
    Type        : Video Capture
    Pixel Format: 'YUYV'
    Name        : YUYV 4:2:2

==========================================================
/dev/video1
Driver Info (not using libv4l2):
    Driver name   : uvcvideo
    Card type     : SAMSUNG (SPC-A30M): SAMSUNG (SP
    Bus info      : usb-0000:00:14.0-7
    Driver version: 5.3.18
    Capabilities  : 0x84A00001
            Video Capture
            Metadata Capture
            Streaming
            Extended Pix Format
            Device Capabilities
    Device Caps   : 0x04A00000
            Metadata Capture
            Streaming
            Extended Pix Format
ioctl: VIDIOC_ENUM_FMT

When i open MediaStream, do all the steps correctly, I get this error:

Your input can't be opened:
VLC is unable to open the MRL 'v4l2:///dev/video0'. Check the log for detail.

The log file contains:

-- logger module started --
main: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
main: playlist is empty
v4l2 error: cannot open device '/dev/video0': Operation not permitted
v4l2 error: cannot open device '/dev/video0': Operation not permitted
v4l2 error: cannot open device '/dev/video0': Operation not permitted
v4l2 error: cannot open device '/dev/video0': Operation not permitted

When i open Cheese, the camera is working fine and i can see the video.

For testing purpose, i set the /dev/video0 permissions to 777, still i get the same error.

This Post suggested to add the user to video group, i did that using sudo usermod -aG video ${USER} but no joy.

I also tried Motion in this post, but i couldn't get it working.

I also tried FFmpeg in this post, but i couldn't get that working as well.

I studied and tried this post, this post, this post, and many others, but nothing seems to help.

In the Driver Info section (above), i see not using libv4l2, could it be the cause of the problem? If so, how to solve this issue?

What am i doing wrong? My objective to to provide an RTSP stream form the USB Webcam attached to the Ubuntu Machine, to the client machines for processing in Java or Python. I am not bound to VLC, so i can use anything that gets the job done.

Can anyone suggest a working solution to the VLC problem or suggest any other tool that can do the job?

I tried many posts/solutions but none helped.


Solution 1:

Following up on @JEL's answer, there is a permissions issue where snap doesn't allow vlc to access the /dev/video devices.

$ snap connections vlc

    Interface               Plug                        Slot                     Notes
    audio-playback          vlc:audio-playback          :audio-playback          -
    audio-record            vlc:audio-record            -                        -
    camera                  vlc:camera                  -                        -
    desktop                 vlc:desktop                 :desktop                 -
...

To fix this, run: snap connect vlc:camera :camera

This creates a connection between the interface and the slot:

$ snap connections vlc
Interface               Plug                        Slot                     Notes
audio-playback          vlc:audio-playback          :audio-playback          -
audio-record            vlc:audio-record            -                        -
camera                  vlc:camera                  :camera                  manual
desktop                 vlc:desktop                 :desktop                 -
...

see: https://snapcraft.io/docs/interface-management

Solution 2:

Short answer :

sudo apt install vlc

And then :

/usr/bin/vlc v4l2:///dev/video0

should work. You won't get exactly the same interface but this should be OK for most usages.

Explanations : under ubuntu 18.04, the default VLC installation is a "snap" installation (you run /snap/bin/vlc by default). Many links suggest that there are permissions problems when installing VLC with snap (see for instance https://forum.videolan.org/viewtopic.php?t=149231).

Since gksu doesn't work anymore and vlc doesn't accept pkexec, it's hard to investigate but I suspect that the problem comes from a module not being loaded. However, the "dirty" "solution" :

\# modprobe -a $(find /lib/modules/4.18.0-15-generic/ -name *v4l2*.ko | while read i ; do basename -- $i; done | cut -d'.' -f1)

didn't work.

Hope this helps ...

Solution 3:

This is a permission issue as describe in previous answers. You can provide permission to cam from UI too.

  1. Open "Ubuntu Software" click on VLC (that you have already installed)
  2. Click Permission button
  3. Switch On "Use your camera"

Now you can play video from your cam !