home Get a blog for free contact login

Linux and webcams

Posted: Sun, 30 Oct 2011 03:01:45 +0200 (Updated: Sun, 30 Oct 2011 12:48:25 +0200)
Author: Делян Кръстев

I've recently got a nice webcam - Logitech C600

The supported camera outputs are:

The best video quality is in the YUYV mode, however it is using less(or no) compression, so the high frame rates are available at 640x480@30 fps, and 800x600@25 fps.

Strangely, the webcam does some cropping when used at high video resolution & high frame rates. The controls pan/tilt are only usable in this crop mode. Skype also does a switch to one of the crop modes after e.g. 30 seconds of the call (I'm using the skype option to capture at 640x480 which it probably uses initially ).

Useful software:

GUVCView

GUVCview is able to show what your webcam can do. You can easily switch resolutions, frame rates, camera output format . It can record video in different formats and capture still images. All of V4L2 settings which your camera supports could be changed. By default it presents a preview screen, so you can see how the switch of settings is affecting the captured video. The actual frames per seconds are also displayed on the video preview window. You can also use it as a camera control application when the capture is done by another app (e.g. skype). Just start it like:

guvcview -o

Another very nice feature is that you can capture video with sound. You can easily choose which mic to use - the camera built in or the one sitting on your desktop.

It is a good idea to keep an eye of the processor load (and on the terminal window) while capturing. Some formats use the CPU heavily and video/audio can easily get out of sync.

MPlayer

MPlayer is usable for fast preview. To play video with mplayer you can just do:

mplayer tv://

or give it some more options:

mplayer -tv driver=v4l2:input=0:width=640:height=480:device=/dev/video0

It appeared hard to get mencoder to capture the video right, especially when it does frame rate switching during the capture. Mine does that when it has the option "Exposure auto priority" checked. I was not able to get mplayer play video and audio at the same time too. But may be I've not tried hard enough. VLC on the other hand can do this.

VLC

VLC needs to know the video and sound devices when you open a capture device. I've specified them as:

/dev/video0 (the webcam)
hw:1 (or hw:1,0) (this was my webcam mic)

You can list your capture devices by:

arecord -l

VLC output is a little laggish in comparison to mplayer or guvcview preview window. I was able to fix this by specifying a smaller buffer time (300ms by default), however at a later try this did not work. I've not played with VLC enough too. As you might know it is quite powerful - may be the most mature video player with a GUI available for Linux. I still use mplayer from the command line for video playing though and haven't found a reason to replace it with anything else :-)

v4l2ucp/luvcview

v4l2ucp is covered by the "Image control" tab of guvcview. Luvcview looks like older version of his G brother. You can get the list of video modes your camera support by doing:

luvcview -L

Another software which I've barely tried is the popular "cheese".

The ultimate webcam software for linux is GUVCView.

Some extra commands to test sound from your webcam mic:

$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: Intel [HDA Intel], device 0: ALC883 Analog [ALC883 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 2: ALC883 Analog [ALC883 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: U0x46d0x808 [USB Device 0x46d:0x808], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

# No sound here
$ arecord -D hw:U0x46d0x808,0 | aplay
Recording WAVE 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
arecord: set_params:1065: Sample format non available
Available formats:
- S16_LE
aplay: playback:2467: read error


# This played the sound. Note that some of the times I started a command
# the sound did not show up. Next time I've tried it it did. The same was
# true for VLC sound capture tests. So I guess the device is not
# always initialized right.
$ arecord -D hw:U0x46d0x808,0 -f S16_LE | aplay
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono
Warning: rate is not accurate (requested = 8000Hz, got = 16000Hz)
         please, try the plug plugin 
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
^CAborted by signal Interrupt...
Aborted by signal Interrupt...

# Specify the proper rate
$ arecord -D hw:U0x46d0x808,0 -f S16_LE -r 16 | aplay
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
^CAborted by signal Interrupt...
Aborted by signal Interrupt...

# Use mmap instead of read:
$ arecord -D hw:U0x46d0x808,0 -f S16_LE -r 16 -M | aplay
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
underrun!!! (at least -1900024418,571 ms long)
^CAborted by signal Interrupt...
Aborted by signal Interrupt...
$

Another note here is that kmix was not always showing the webcam mic. Sometimes it showed unplug events without me actually touching the camera. Thus the webcam mic became unmanageble with it. Thus alsamixer was my friend.

Links:


Posted in dir: /articles/
Tags: guvcview Linux webcam

Show comments Report article PermaLink

All tags SiteMap Owner Cookies policy [Atom Feed]