Webcam SliTaz 5.1

Most USB webcams and the cameras built into laptops follow the UVC standard: the Linux driver uvcvideo handles them, with nothing to download. This page tells how to get the driver on SliTaz, check the camera, and take photos and videos with a window or from a terminal.

Get the driver

The webcam drivers are in the linux-lts-media package (webcams, TV and video capture), which the desktop images do not include. Install it as root and load the driver:

# spk-add linux-lts-media
# modprobe uvcvideo

Older cameras that are not UVC use the gspca drivers of the same package: unplug and plug the camera again to load the right one.

Check that the camera is there:

$ ls /dev/video*
$ cat /sys/class/video4linux/video*/name
$ dmesg | grep -i uvc

A UVC camera shows up twice, for example /dev/video0 and /dev/video1: the first one gives the picture, the second only data about it. Use /dev/video0.

To use the camera, your user must be in the video group. Desktop users created by SliTaz are; check with id, and add a user as root with:

# trame user group add tux video

The change counts from the next login.

With a window: guvcview

guvcview shows the camera, takes photos and records videos. Its settings tabs change the brightness, contrast, resolution and frame rate.

# spk-add guvcview
$ guvcview

It opens /dev/video0; guvcview -d /dev/video2 opens another camera.

From a terminal: ffmpeg

# spk-add ffmpeg

List the formats and sizes the camera offers:

$ ffmpeg -hide_banner -f v4l2 -list_formats all -i /dev/video0

Take a photo:

$ ffmpeg -f v4l2 -video_size 1280x720 -i /dev/video0 -frames:v 1 photo.jpg

Record ten seconds of video, readable by every player:

$ ffmpeg -f v4l2 -video_size 640x480 -i /dev/video0 -t 10 \
    -c:v libx264 -pix_fmt yuv420p video.mp4

Press q to stop earlier. To watch the camera in a window, install ffplay:

# spk-add ffplay
$ ffplay -f v4l2 -i /dev/video0

The ffmpeg of SliTaz records the picture only, not the sound: it has no ALSA input.

Photos with fswebcam

fswebcam is a tiny tool for photos only, handy in scripts:

# spk-add fswebcam
$ fswebcam -r 1280x720 -S 10 --no-banner photo.jpg

-S 10 skips the first ten frames, while the camera sets its exposure: the first ones are often dark. Without --no-banner, fswebcam writes the date at the bottom of the picture. -l 60 takes a photo every 60 seconds into the same file, until Ctrl+C.

fswebcam also lists and sets the controls of the camera:

$ fswebcam --list-controls
$ fswebcam -s Brightness=20 -S 10 photo.jpg

A control set this way lasts until the camera is unplugged or the machine stops.

Tips

Troubleshooting

No /dev/video0: check that linux-lts-media is installed, run modprobe uvcvideo and read the end of dmesg. On a laptop, the camera may be turned off by a key or a switch, or in the firmware setup.

"Permission denied" on /dev/video0: your user is not in the video group, see above, or did not log in again after being added.

"Device or resource busy": another program uses the camera.

guvcview says "ERROR opening V4L2 interface for /dev/video1": harmless, that device holds no picture.

Dark or green pictures: skip the first frames (-S 10 with fswebcam), or try another size from the list of formats.