Search by Tags

Webcam (Linux)

 

Article updated at 30 Mar 2021
Compare with Revision




Select the version of your OS from the tabs below. If you don't know the version you are using, run the command cat /etc/os-release or cat /etc/issue on the board.

BSP 5

Introduction

Linux kernel drivers for regular USB Video Class (UVC) Webcam devices are enabled in our BSP Layers and we provide a Reference Multimedia Image with a graphical back-end, GStreamer and Video4Linux2 (V4L2).

The driver exports the webcam through the Video4Linux2 (V4L2) API. User-space video utilities such as GStreamer can be used to display or store the video stream.

For supported UVC compatible webcams have a look at www.ideasonboard.org/uvc.

Here is an excerpt of kernel log after a webcam is plugged in:

[30262.107825] usb 1-1.2: new high-speed USB device number 5 using xhci-hcd
[30264.475698] uvcvideo: Found UVC 1.00 device C922 Pro Stream Webcam (046d:085c)
[30264.485550] input: C922 Pro Stream Webcam as /devices/platform/32f10108.usb/38200000.dwc3/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/input/input4

GStreamer and Video4Linux2

Installation

GStreamer comes pre-installed in the Reference Multimedia Image.

You must Build a Reference Image with Yocto Project/OpenEmbedded if you want to add or remove packages from the image. In any case, you must customize the reference images as they are not production-ready.

If you don't want to do a custom OpenEmbedded build, consider using Torizon, where you can install libraries and packages inside Debian Containers with commands as apt install. Have a look at our collection of Multimedia, Camera and Video Processing articles for Torizon.

How to Use

Most likely, for the basics you won't need to run any V4L2, and you can focus on searching how to capture video from a webcam using a GStreamer pipeline.

Both the GStreamer documentation and the SoC vendor documentation are good places to look for examples. For instance, the NXP i.MX Linux User's Guide has a section dedicated to webcam usage. Please refer to our article Video Encoding and Playback (Linux) to find instructions on how to access the GStreamer and the NXP documentation.

BSP 3

Introduction

While Linux kernel drivers for regular USB Video Class (UVC) Webcam devices are enabled in our BSP Layers, we don't provide a reference image with a graphical back-end, you must add packages as GStreamer and Video4Linux2 (V4L2) in your own custom image built on top of our Console Image.

The driver exports the webcam through the Video4Linux2 (V4L2) API. User-space video utilities such as GStreamer can be used to display or store the video stream.

For supported UVC compatible webcams have a look at www.ideasonboard.org/uvc.

[  102.903321] usb 2-1: new high speed USB device using tegra-ehci and address 2
[  103.233213] usb 2-1: New USB device found, idVendor=046d, idProduct=0805
[  103.241038] usb 2-1: New USB device strings: Mfr=0, Product=0, SerialNumber=2
[  103.248335] usb 2-1: SerialNumber: FC377070
[  103.253237] uvcvideo: Found UVC 1.00 device  (046d:0805)
[  103.297988] input: UVC Camera (046d:0805) as /devices/platform/tegra-ehci.2/usb2/2-1/2-1:1.0/input/input1

GStreamer and Video4Linux2

Installation

You must Build a Reference Image with Yocto Project/OpenEmbedded and add the GStreamer and Video4Linux2 packages. You can search for them in the OpenEmbedded Layer Index - Zeus Branch.

If you don't want to do a custom OpenEmbedded build, consider using Torizon, where you can install libraries and packages inside Debian Containers with commands as apt install. Have a look at our collection of Multimedia, Camera and Video Processing articles for Torizon.

How to Use

Most likely, for the basics you won't need to run any V4L2, and you can focus on searching how to capture video from a webcam using a GStreamer pipeline.

While our article Video Encoding and Playback (Linux) may help you with some tips, we strongly encourage you to study the GStreamer documentation. The command-line tools section may be particularly useful to get started.

BSP 2.8

Drivers for regular USB Video Class (UVC) Webcam devices are enabled in our pre-built images. The driver exports the webcam through the Video4Linux2 (V4L2) API. User-space video utilities such as GStreamer can be used to display or store the video stream.

For supported UVC compatible webcams have a look at www.ideasonboard.org/uvc.

[  102.903321] usb 2-1: new high speed USB device using tegra-ehci and address 2
[  103.233213] usb 2-1: New USB device found, idVendor=046d, idProduct=0805
[  103.241038] usb 2-1: New USB device strings: Mfr=0, Product=0, SerialNumber=2
[  103.248335] usb 2-1: SerialNumber: FC377070
[  103.253237] uvcvideo: Found UVC 1.00 device  (046d:0805)
[  103.297988] input: UVC Camera (046d:0805) as /devices/platform/tegra-ehci.2/usb2/2-1/2-1:1.0/input/input1

Gstreamer Video4Linux2

Installation

Our latest V2.x images for Tegra and i.MX6 based modules come with the required GStreamer Video4Linux2 source pre-installed.

On Vybrid based modules one has to install GStreamer, Video4Linux2 and some additional packages:

# opkg update
# opkg install gst-plugins-good-video4linux2 gst-plugins-base-ximagesink gst-plugins-base-ffmpegcolorspace gst-plugins-bad-fbdevsink

For images V2.6 and newer the GStreamer 1.x series needs to be used:

# opkg update
# opkg install gstreamer1.0-plugins-base-ximagesink gstreamer1.0-plugins-good-video4linux2 gstreamer1.0-plugins-base-videoconvert gstreamer1.0-plugins-bad-fbdevsink

Gstreamer Video4Linux2 piplines

Pipeline to store the unconverted raw video stream in a file:

gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv, framerate=10/1, width=320, height=240 ! filesink location=test.raw

Pipline for Tegra based modules using nvxvimagesink (accelerated)

gst-launch v4l2src device=/dev/video0 ! 'video/x-raw-yuv, framerate=30/1, width=640, height=480, format=(fourcc)YUY2' ! nvvidconv ! nvxvimagesink -v

Pipeline for i.MX6 based modules using i.MX6 optimized sink (V2.5: imxv4l2sink, V2.4 and earlier: mfw_v4lsink):

gst-launch v4l2src device=/dev/video0 ! 'video/x-raw-yuv, width=(int)640, height=(int)480, format=(fourcc)YUY2' ! imxv4l2sink disp-width=640 disp-height=480

Pipeline for Vybrid based modules using X-Server window (Software only, tested on Colibri VF61):

gst-launch v4l2src device=/dev/video0 ! 'video/x-raw-yuv,width=320,height=240,framerate=30/1' ! ffmpegcolorspace ! ximagesink

Using GStreamer 1.x series, applicable for Colibri i.MX7 and Colibri i.MX6 ULL after running GStreamer 1.x installation command lines.

# gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,width=640,height=480,framerate=30/1' ! videoconvert ! ximagesink

Using an Embedded Linux Image that runs over framebuffer, interchange ximagesink with fbdevsink

# gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,width=640,height=480,framerate=30/1' ! videoconvert ! fbdevsink

Pipeline for Vybrid based modules using framebuffer (fbdev) sink (Software only, tested on Colibri VF61):

gst-launch v4l2src device=/dev/video0 ! 'video/x-raw-yuv,width=640,height=480,framerate=15/1' ! ffmpegcolorspace ! fbdevsink

Using GStreamer 1.x series

# gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw,width=640,height=480,framerate=15/1' ! videoconvert ! fbdevsink

This pipeline is using the CPU to convert color space and composite the video. However, on Colibri VF61, VGA (640x480) with up to 15 frames per second has been tested successfully (~80% CPU load).

Note: The format capabilities of a UVC Webcam can be displayed using v4l2-ctl:

v4l2-ctl --list-formats-ext

Troubleshooting

uvcvideo: Failed to submit URB 0 (-28) / system error: No space left on device

If you get the following error when trying to concurrently stream video from multiple USB cameras you may have run out of available USB bandwidth. Try connecting your cameras to independent USB host controllers:

root@colibri-t30:~# gst-launch v4l2src device=/dev/video1 ! 'video/x-raw-yuv, framerate=30/1, width=640, height=480, format=(fourcc)YUY2' ! nvvidconv ! nvxvimagesink -v
Setting pipeline to PAUSED ...
[ 1762.593772] uvcvideo: Failed to submit URB 0 (-28).
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Error starting streaming on device '/dev/video1'.
Additional debug info:
/build/linuxdev/oe-core_V2.6.1/build/tmp-glibc/work/armv7at2hf-vfp-neon-angstrom-linux-gnueabi/gst-plugins-good/0.10.31-r8/gst-plugins-good-0.10.31/sys/v4l2/gstv4l2object.c(2230): gst_v4l2_object_start_streaming (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
system error: No space left on device
Setting pipeline to NULL ...
Freeing pipeline ...