Linux上摄像设备的使用

在Linux上配置网络摄像头,用到的一些软件,以及如何录制和播放设备的视频输入

1. 查找设备

  • 插上摄像设备(通常是通过USB)

  • 列出所有的 video4linux 设备:

ls -ltr /dev/video*
  • 得到的输出类似于:
crw-rw----+ 1 root video 81, 0 Nov 11 09:06 /dev/video0

这里的摄像设备名称是 */dev/video0*,如果没有看到任何 /dev/video 文件,查看#排查问题。如果有多个 video4linux 设备,比如是一个tv card,摄像头设备应该显示为 /dev/video1 或类似的。但它的时间(在这个例子中是 Nov 11 09:06)应该是你插上它的时间。

2.测试设备

  • 如果安装有 vlc,可以启动它,选择 Media -> Open Capture Device -> Video device name = /dev/video0 -> Play

  • 如果安装有mplayer,可以使用:

  mplayer tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -fps 30

3.使用设备

3.1录制视频

要捕获设备的视频输入,可以使用 cheese,一个不错的图形界面软件,你可以用它边看边录制设备的视频输入,录制保存的文件格式不太常见(.webm),但用vlc可以播放。

You can also automate video recording so you can capture the camera stream with sitting in front of the computer. To do this you can

  • use the software mencoder:
  mencoder tv:// -tv driver=v4l2:width=320:height=240:device=/dev/video0 -nosound -ovc lavc -o myvideo.avi
  • or use the software streamer. Here are two examples:
  streamer -c /dev/video0 -f jpeg -F stereo -o myvideo.avi -t 0:05

3.2视频通话

视频通话,在Linux上使用skype.

3.3查看视频输入

查看摄像设备的视频输入,使用cheesemplayer:

mplayer -fps 30 -cache 128 -tv driver=v4l2:width=640:height=480:device=/dev/video0 tv://

或者用vlc,你可以用root权限运行vlc,来查看你的摄像设备 /dev/video0,启动vlc并选择 Media -> Open Capture Device -> Video device name = /dev/video0 -> Play

排查问题

Troubleshooting heavily depends on the distribution and version you are using. If you have done cabling correctly and a device file /dev/video* does not appear, your kernel probably does not know the hardware. In this case you may have to install the device driver separately because it may not be part of the kernel.

SUSE Linux 11.0 and earlier

This has been tested with SUSE Linux 11.0 x64 but should work with any earlier SUSE version. You will need to log in as user root. To find out what driver you need, open a console and call

hwinfo --usb

If a Logitech Quickcam Messenger is plugged in the answer will be like:

06: USB 00.2: 0000 Unclassified device
  [Created at usb.122]                
  UDI: /org/freedesktop/Hal/devices/usb_device_46d_8da_noserial_if2
  Unique ID: Eopr.vE+cdFBwClB                                      
  Parent ID: uIhY.uOe2OKugI8D                                      
  SysFS ID: /devices/pci0000:00/0000:00:1a.2/usb3/3-1/3-1:1.2      
  SysFS BusID: 3-1:1.2                                             
  Hardware Class: unknown                                          
  Model: "Logitech QuickCam Messanger"                             
  Hotplug: USB                                                     
  Vendor: usb 0x046d "Logitech, Inc."                              
  Device: usb 0x08da "QuickCam Messanger"                          
  Revision: "1.00"                                                 
  Driver: "snd-usb-audio"                                          
  Driver Modules: "snd_usb_audio"                                  
  Speed: 12 Mbps                                                   
  Module Alias: "usb:v046Dp08DAd0100dc00dsc00dp00ic01isc02ip00"    
  Driver Info #0:                                                  
    Driver Status: quickcam_messenger is active                    
    Driver Activation Cmd: "modprobe quickcam_messenger"
  Driver Info #1:                                                  
    Driver Status: gspca is active                                 
    Driver Activation Cmd: "modprobe gspca"
  Config Status: cfg=new, avail=yes, need=no, active=unknown       
  Attached to: #20 (Hub)

This means you can install and load the webcam driver like this:

yast -i gspcav-kmp-default
modprobe gspca

Now you should see a video device:

ls /dev/video*
/dev/video  /dev/video0

That means you can install and start your webcam-viewer-software. We choose gqcam:

yast -i gqcam
gqcam

It works. You see a video what from what is going on in front of your webcam.

Ubuntu

This has been tested with Ubuntu 8.10 x32 but should work with any Ubuntu version. Find out the driver activation command of your webcam. For this, first install the software hwinfo. Open a consoleand type:

sudo apt-get install hwinfo

Then call hwinfo:

hwinfo --usb

If a Logitech Quickcam Messenger is plugged in the response will be like:

04: USB 00.2: 0000 Unclassified device
  [Created at usb.122]
  UDI: /org/freedesktop/Hal/devices/usb_device_46d_8da_noserial_if2
  Unique ID: 4ajv.vE+cdFBwClB
  Parent ID: k4bc._Mkd+LmXb03
  SysFS ID: /devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb1/1-1/1-1:1.2
  SysFS BusID: 1-1:1.2
  Hardware Class: unknown
  Model: "Logitech QuickCam Messanger"
  Hotplug: USB
  Vendor: usb 0x046d "Logitech, Inc."
  Device: usb 0x08da "QuickCam Messanger"
  Revision: "1.00"
  Driver: "snd-usb-audio"
  Driver Modules: "snd_usb_audio"
  Speed: 12 Mbps
  Module Alias: "usb:v046Dp08DAd0100dc00dsc00dp00ic01isc02ip00"
  Driver Info #0:
    Driver Status: gspca_zc3xx is active
    Driver Activation Cmd: "modprobe gspca_zc3xx"
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #8 (Hub)

Activate the driver:

sudo modprobe gspca_zc3xx

Now you should be able to see the video device:

ls /dev/video*
/dev/video0

You can now test your webcam using the software cheese:

sudo apt-get install cheese
cheese

Other webcams

If you have another webcam, try the above nevertheless. If it does not work, exchange the driver gspca against uvcvideo:

yast -i uvcvideo_kmp_default
modprobe uvcvideo

and start gqcam again.

Testbed

The following webcams have been found working with this tutorial:

  • Logitech Quickcam messenger
  • Philips Webcam SPC220NC

A general list of working webcams can be found at http://mxhaard.free.fr/spca5xx.html.

The guide has been tested with SUSE Linux 11.4 till 13.2 and Ubuntu.

See also

上一页
下一页