- Introduction
- 1. Choosing a Webcam
- 2. Testing Your Webcam Using Cheese
- 3. Webcam Software
- 3.1. Configuring Webcam Software
- 3.2. VLC
- 3.2.1. Using the GUI
- 3.2.2. Using the Command Line
- 3.3. FFmpeg
- 3.3.1. Recording Video
- 3.4. MPlayer
- 3.4.1. Recording Video
- 3.5. MEncoder
- 3.5.1. Recording Video
- 3.6. Skype
- 3.7. streamer
- 4. Identifying Your Webcam
- 5. Driver installation
- 6. See Also
- 7. External Links
- Выбор разрешения видеокамеры
Introduction
Please note that this document is intended for the current release: Ubuntu 10.10 (Maverick Meerkat).
1. Choosing a Webcam
Webcam support in Linux is mainly provided by the Linux UVC Project’s UVC driver. This aims to provide a universal driver in the same way that a generic driver handles USB storage devices (memory sticks, hard drives etc). However, other drivers also exist that may allow more devices to be used. When looking to purchase a webcam for use with Ubuntu, you should look for a UVC compatible camera. The Linux-UVC project has a good list of UVC compatible webcams.
2. Testing Your Webcam Using Cheese
Ubuntu aims to provide ‘out-of-the-box’ or ‘just-works’ functionality for webcams. This means that you should be able to plug-in your webcam and use it straight away: no driver disks or installation. To test whether or not your webcam works in this way, install Cheese, a GNOME program for capturing video and stills from a webcam. It can also apply some special effects. Cheese is included in the Main repositories since Ubuntu 8.04 LTS (Hardy Heron). It uses the gstreamer library, which utlilizes the video4linux2 API.
- Open a terminal window.
- Type in the following command:
sudo apt-get install cheese
- If Cheese doesn’t display the output from your webcam, test that the problem is not with Cheese before trying anything else by using one of the programs in the next section.
- If Cheese displays a garbled picture or one with poor colour/brightness/contrast, go to the Ubuntu wiki Webcam Troubleshooting page for steps to resolve this.
3. Webcam Software
- Empathy has been the default VoIP/Video Chat application since Ubuntu 9.10 (Karmic Koala), and can be used to establish whether or not your webcam is working.
3.1. Configuring Webcam Software
In some cases your media player (VLC, mplayer, amongst others) will need to know the video and audio device files for your webcam. Before you plug in your webcam, try the following two commands at a console:
Make a note of the devices appearing. Now plug in your webcam, allow the system a few seconds to register the device, and run the two commands again. The new appearances should belong to your webcam (for instance, /dev/video0 and /dev/audio2). If nothing new appears, you may need to switch your webcam on. For a built-in webcam, you may have a function key to do so.
3.2. VLC
3.2.1. Using the GUI
In VLC, choose ‘Open capture device’ from the file menu and enter the video and audio device files (see above) in video device name and audio device name, respectively. If you just want a ‘mirror’ (to see what the webcam is showing), click ‘OK’ and you’re done. If you wish to record, tick off ‘Stream/save’ in the ‘Advanced options’ section. Click the settings button right next to it. Tick ‘File’ off under ‘Outputs’ and enter a filename. Encapsulation method can be left at the default (MPEG TS). Under ‘Transcoding options’, tick ‘Audio codec’ and ‘Video codec’. These can also safely be left the defaults (obviously greater compression results in lower file sizes, so experiment). Click ‘OK’ in the Settings screen and once again in the main webcam screen (Video4linux). If you want to have more control, you can access several settings, including resolution, by clicking the Advanced options button.
3.2.2. Using the Command Line
A simple test of just the video from your webcam can be done as follows. This assumes the webcam is installed as ‘/dev/video0’.
If you wish to be able to quickly start a video session with your webcam, the resulting vlc command is printed in the Customize line at the bottom. You simply need to prepend ‘vlc’, e.g.
vlc v4l2:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2" :v4l-norm=3 :v4l-frequency=-1 :v4l-caching=300 :v4l-chroma="" :v4l-fps=-1.000000 :v4l-samplerate=44100 :v4l-channel=0 :v4l-tuner=-1 :v4l-audio=-1 :v4l-stereo :v4l-width=640 :v4l-height=480 :v4l-brightness=-1 :v4l-colour=-1 :v4l-hue=-1 :v4l-contrast=-1 :no-v4l-mjpeg :v4l-decimation=1 :v4l-quality=100
The recording instructions will similarly need to be appended. Copy the contents of the ‘Stream Output MRL’ box under ‘Settings’ and change «:sout=» to «—sout » and append it to your vlc command:, e.g.
vlc v4l2:// :v4l-vdev="/dev/video0" :v4l-adev="/dev/audio2" :v4l-norm=3 :v4l-frequency=-1 :v4l-caching=300 :v4l-chroma="" :v4l-fps=-1.000000 :v4l-samplerate=44100 :v4l-channel=0 :v4l-tuner=-1 :v4l-audio=-1 :v4l-stereo :v4l-width=640 :v4l-height=480 :v4l-brightness=-1 :v4l-colour=-1 :v4l-hue=-1 :v4l-contrast=-1 :no-v4l-mjpeg :v4l-decimation=1 :v4l-quality=100 --sout "#transcode:duplicate>"
To simple take a few snapshots, open the webcam without recording and choose ‘Snapshot’ under the ‘Video’ menu.
3.3. FFmpeg
FFmpeg is a cross-platform audio/video recording, conversion and streaming application.
3.3.1. Recording Video
sudo apt-get install ffmpeg
ffmpeg -f oss -i /dev/dsp -f video4linux2 -s 320x240 -i /dev/video0 out.mpg
With recent versions of Ubuntu (>= 12.10) you should use avconv instead of ffmpeg command:
avconv -f oss -i /dev/dsp -f video4linux2 -s 320x240 -i /dev/video0 out.mpg
3.4. MPlayer
MPlayer is capable of displaying a webcam video stream,
3.4.1. Recording Video
- Open a terminal window and type the following:
mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0
- This example assumes that your webcam device is at /dev/video0
- The resolution (width=. & height=. ) should be chosen to match the output of your device.
3.5. MEncoder
The companion to MPlayer, MEncoder can record from a webcam to video files.
3.5.1. Recording Video
mencoder tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0 -ovc lavc -o webcam.avi
mencoder tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0:forceaudio:adevice=/dev/dsp1 -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o webcam.avi
- Type ‘man mencoder’ for more info on the audio options.
- /dev/dsp1 refers to the webcam USB Audio device.
- /dev/dsp refers to the sound card.
You may need to install these programs with
sudo apt-get install mplayer mencoder
- Camera Monitor from chaos infinito shows a tray icon that lets you know when your webcam is on. It has been in the Universe repository since Ubuntu 10.10 (Maverick Meerkat) and is released under the GPL.
- luvcview is a good program you can use to test that the camera is working. It has been in the Universe repository since Ubuntu 8.04 LTS (Hardy Heron). If it doesn’t work, you may need to update the UVC driver (see Manual install instructions below).
- guvcview is based on luvcview and has a graphical user interface. It has been in the Universe repositories since Ubuntu 9.10 (Karmic Koala).
- Camorama (not updated since 2007), xawtv, aMSN, and Kopete can all be used to test and use your webcam. They have been in the Universe repositories since Ubuntu 6.06 LTS (Dapper Drake) apart from Kopete, which is in the main repositories.
3.6. Skype
See the dedicated Skype and SkypeWebCams pages.
3.7. streamer
The streamer package provides a very simple command line interface for taking pictures:
streamer -f jpeg -o /path/to/image.jpeg
The package can be installed as follows:
sudo apt-get install streamer
4. Identifying Your Webcam
Although webcams may look quite different from one another, they often share similar or identical major components. This means that drivers may work for many different makes and models with little or no modification.
- Make and Model Name/Number.
- Any version or revision information. This is often printed on the device or its packaging and will read something similar to REV 01 or VER. 2.2. This information can be particularly useful.
- The output of the lsusb. Type lsusb -v into a terminal window.
- This program prints information about the devices connected to the USB bus. If you scroll through it, you should find some information about your webcam.
- Type lsusb -n into a terminal window. This version of the command lists the device’s USB ID; a number that is unique to every device.
5. Driver installation
Linux Webcam drivers are provided by several different projects. Although the Linux UVC project covers many devices, support for others is provided elsewhere. This section aims to help you install your webcam’s drivers if they have not been automatically installed by Ubuntu.
- ov51x — The Ubuntu wiki page is here.
- ov51x-jpeg — This is a hacked driver by http://www.rastageeks.org/ and more info is available here.
- Suported Hardware — A list of webcams supported by the rastageeks driver.
6. See Also
- Troubleshooting Webcams — The Ubuntu wiki page.
- UVC — The Ubuntu wiki page for the Universal Video Class.
- Installing the Eyetoy as a Webcam with Kopete
7. External Links
- Using a USB Webcam to capture videos for upload to YouTube
- The Linux TV Project Homepage — This is the project responsible for the video4linux drivers for webcams and tv capture/tuner devices.
- The linuxtv.org V4L-DVB Wiki Webcam Page — This page contains lots of information about webcam support in Linux.
Webcam (последним исправлял пользователь ckimes 2017-08-23 23:00:23)
The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for detailsВыбор разрешения видеокамеры
Имею несколько USB-камер, везде указано какое-нибудь большое разрешение. Все они отдают только 640×480.
Сейчас пришла мне ещё одна камера. У неё указано максимальное разрешение 720×520 и минимальное 320×240. Отдаёт только 640×480. Думаю, в video4linux можно как-то установить разрешение. Но как?Выбор разрешения осуществляется в программе, которая работает с камерой, а не в общесистемных настройках.
А разве не для этого нужен v4l2-ctl?
v4l2-ctl -d /dev/video0 -v width=640,height=480
А как узнать все доступные разрешения?
Driver Info (not using libv4l2): Driver name : uvcvideo Card type : USB Camera Bus info : usb-0000:00:14.0-2 Driver version: 3.8.13 Capabilities : 0x84000001 Video Capture Streaming Device Capabilities Device Caps : 0x04000001 Video Capture Streaming Priority: 2 Video input : 0 (Camera 1: ok) Format Video Capture: Width/Height : 640/480 Pixel Format : 'YUYV' Field : None Bytes per Line: 1280 Size Image : 614400 Colorspace : SRGB Crop Capability Video Capture: Bounds : Left 0, Top 0, Width 640, Height 480 Default : Left 0, Top 0, Width 640, Height 480 Pixel Aspect: 1/1 Streaming Parameters Video Capture: Capabilities : timeperframe Frames per second: 30.000 (30/1) Read buffers : 0 brightness (int) : min=-127 max=127 step=1 default=0 value=0 contrast (int) : min=0 max=64 step=1 default=32 value=32 saturation (int) : min=0 max=100 step=1 default=50 value=50 hue (int) : min=-180 max=180 step=1 default=0 value=0 white_balance_temperature_auto (bool) : default=1 value=1 gamma (int) : min=100 max=500 step=1 default=220 value=220 gain (int) : min=0 max=100 step=1 default=0 value=0 power_line_frequency (menu) : min=0 max=2 default=1 value=1 white_balance_temperature (int) : min=2800 max=6500 step=10 default=4650 value=4650 flags=inactive sharpness (int) : min=0 max=8 step=1 default=4 value=4 backlight_compensation (int) : min=0 max=1 step=1 default=0 value=0 exposure_auto (menu) : min=0 max=3 default=3 value=3 exposure_absolute (int) : min=50 max=10000 step=1 default=166 value=166 flags=inactive
У меня тоже mplayer по умолчанию 640х480 показывает, а вот если явно укажешь нужный размер, отдает «родное» разрешение. v4l2ctl нужно дергать, если тебе какие-то доп. настройки захочется поменять (скажем, отрубить автоэкспозицию или изменить формат потока).
alias recwebcam='ffmpeg -b:v 1000k -f video4linux2 -s 720x520 -i /dev/video0 -sameq -f alsa -i hw:0,0 -f avi '
mplayer tv:// -tv driver=v4l:width=720:height=520
А можно ли каким-нибудь образом узнать, действительно ли камера отдаёт 720×520 или изображение просто растягивается v4l?
В выхлопе mplayer’а, в выхлопе v4l2ctl.