How does Linux detect your webcam?

Source: Internet
Author: User
Tags documentation

This article is reproduced to: http://www.netinstructions.com/automating-picture-capture-using-webcams-on-linuxubuntu/

If it's a USB webcam, plug it in. If it ' s a integrated webcam built into the laptop, there ' s nothing to plug in. Ubuntu should automatically detect and install drivers for the webcam. To the if it ' s detected, let's run some commands:

Here's a command to the device nodes exist:

stephen@ubuntu:~$ ls-l/dev/video*  
crw-rw----+ 1 root video bayi, 0 Mar 20:29/dev/video0  
crw-rw----+ 1 root vid EO 1 APR 2 08:03/dev/video1

And here's another command to find out about the devices:

stephen@ubuntu:~$ Lsusb Bus  
001 Device 003:id 046d:0990 Logitech, Inc. quickcam Pro 9000 bus  
001 Device 002:id 1 3d3:5111 IMC Networks integrated WEBCAM bus 004 Device 002:id 0b05:1788 ASUSTek Computer  
, Inc.  
Bus 001 Device 001:id 1d6b:0002 linux Foundation 2.0 root hub bus  
002 Device 001:id 1d6b:0002 Linux Foundation 2.0 R Oot Hub bus  
003 Device 001:id 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001:id 1d6b:0001  
linux Foun Dation 1.1 Root Hub

More information on LSUSB can is found by reading the Lsusb ' man page ' (otherwise known as the manual). can also use the LSUSB command to learn more about the resolution of the webcams. Just Change the "bus" and Device numbers that for you found above.

stephen@ubuntu:~$ Lsusb-s 001:002-v | Egrep "width| Height "  
wwidth 640  
wheight wwidth-wheight-wwidth 1024-wheight 768 wwidth  
1280  
Wheight 720
If for some reason your plug in the webcam but it doesn "t show up" (in/dev/video* or LSUSB), try looking at the recent Driver messages for clues:

stephen@ubuntu:~$ Dmesg|tail
Fswebcam, FFmpeg, MPlayer, and VLC

There are a few command line tools that'll let you take a the picture using your webcam. I ' ve tried three different tools and found that I liked Fswebcam the most, but I ' ve listed all of the options here:

Note This might need to change your device from/dev/video0 to perhaps/dev/video1! Check the above section to-what webcam is detected.

FFmpeg

Ffmpeg-f video4linux2-i/dev/video0-vframes 1 test.jpg  
ffmpeg-f video4linux2-s 640x480-i/dev/video1-vframes 1 /home/stephen/webcamphotos/$ (date +\%y\%m\%d\%h\%m). jpg
FFmpeg man page ffmpeg documentation
Fswebcam
fswebcam-d/dev/video0-r 640x480--jpeg 85-f 5 test.jpg

This is uses a compression factor (good tradeoff of Quality/size) and captures 5 frames (for less noise in image). Fswebcam man page MPlayer

MPlayer tv://-tv driver=v4l2:device=/dev/video0:width=640:height=480-frames 3-vo jpeg
MPlayer Documentation ArchLinux article on MPlayer VLC
Vlc-i dummy v4l2:///dev/video0--video-filter scene--no-audio--scene-path/home/stoppal/test--scene-prefix Image_ Prefix--scene-format PNG vlc://quit--run-time=1
Some notes about the Logitech QuickCam Pro 9000

If you are using the Logitech QuickCam Pro 9000 It has a advertised maximum resolution of 1600x1200. Let's try to run this with Fswebcam.

stephen@ubuntu:~$ fswebcam-d/dev/video1-r 1600x1200--jpeg 85-f (date 5/home/stephen/webcamphotos/$) . JPEG
---opening/dev/video1 ...
Trying source module V4l2
... /dev/video1 opened.
No input was specified, using the ' the '.
Adjusting resolution from 1600x1200 to 960x720.
---capturing 5 frames
... Captured 5 frames in 0.40 seconds. (fps)
---processing captured image ...
Setting output format to JPEG, quality
writing JPEG image to ~/home/stephen/webcamphotos/201304051633.jpeg.

Wait a second! Why did it adjust the resolution to 960x720?

It turns out we need to force it to use a YUYV palette instead of the default

stephen@ubuntu:~$ fswebcam-d/dev/video1-p yuyv-r 1600x1200--jpeg 85-f 5/home/stephen/webcamphotos/$ (Date +\%Y\%m\%d \%H\%M). jpeg
Configure crontab (Make a cronjob) to take a picture every minute or hour

Crontab is a popular *nix utility that executes a command on a user defined interval. Maybe you just want to take a picture every minute, or Maybe your want to shutdown your computer Monday through the at 1 0pm. Or Maybe you want to run some scripts that backup your data once every 3 months. If you are want to run multiple commands/can do, chaining them with the && keyword, but it ' s also sometimes w Orth Making a bash script (or maybe a simple python/perl/ruby script) that gets executed as part of the cronjob.

To view the current cron jobs for the current user, type Crontab-e. To view the current cron jobs for the Super user, type sudo crontab-e.

Here are some cronjobs I have set up:

# to take a picture every minute # */1 * * * streamer-f jpeg-s the 1024x768-o/home/stephen/timelap/$  
(Date +\%m\%d\%k \%m). JPEG

# to take a picture every hour on minute mark using a different tool # * * * *
fswebcam-r 102 4x768--jpeg 85-d 4-f 10/home/stephen/webcamphotos/$ (date +\%y\%m\%d\%k\%m). JPEG

# Take a picture and upload it to The webserver every hour
@hourly bash/home/stephen/scripts/take_photo_and_push.sh

The last cronjob calls a bash script so looks like this:

#!/bin/bash  
#Take A picture, then push it to a remote webserver

#Take a photo
fswebcam-d/dev/video1-p -R 1600x1200--jpeg 85-d 2-f 15/home/stephen/webcamphotos/$ (date +\%y\%m\%d\%h\%m). jpeg #Navigate to the

directory< c4/>cd/home/stephen/webcamphotos/

#Find The most recent JPEG
new_jpeg=$ (ls-t | grep ' \>.jpeg ' | head-1)

#Push it to the remote webserver
scp/home/stephen/webcamphotos/$NEW _jpeg stephen@netinstructions.com:/home/ Stephen/netinstructions.com/homeserver/latest.jpeg

For the more information on Cronjobs and crontab, take a look at this guide.

If you are want to view any logs for the "the" cron job you can view the logs by typing:

$ grep Cron/var/log/syslog
viewing/transferring the Pictures

Okay, so your found a command line utility this takes pictures, and perhaps a cronjob that runs that command every 5 minute s or minutes or every hour or once a day, but how do I look at the picture?

There are a couple of ways of doing this. If you are using the desktop version of Ubuntu (with a nice graphical user interface) your just double click on the photo. For the rest of the US who are SSH ' ing in to a remote machine or are using the server version of Ubuntu or some other Linx dis Tro, we have a few options:filezilla to grab the files and transfer them to my local machines If you have a Web server ( Apache, Ngnix, or something else on the server, move the "file to" web directory SCP the file to a remote Web server. For example, I have a few websites (such as this one) hosted by DreamHost, and they shell access

The command to securely transfer a file on one machine to another looks as this:

scp/home/stephen/webcamphotos/$NEW _jpeg stephen@netinstructions.com:/home/stephen/netinstructions.com/ Homeserver/latest.jpeg

Good luck!



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.