Monitor a Webcam

From SingletonMillerWiki
Revision as of 15:51, 19 June 2012 by Martin (Talk | contribs)

Jump to: navigation, search


Plug in your webcam

Before you plug in your webcam, try the following command at a console:

ls /dev/video*

I don't have any video devices on my system so I get:

No such file or directory

Now Plug in your webcam

List the USB devices using

lsusb

You should see something like this.

Bus 001 Device 005: ID 1415:2000 Nam Tai E&E Products Ltd. or OmniVision Technologies, Inc. Sony Playstation Eye
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 05e3:0660 Genesys Logic, Inc. USB 2.0 Hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 001 Device 005: shows a USB Playstation Eye has been recognised.

Repeat the first command and make a note of the new devices names.

ls /dev/video*

Now we get

/dev/video0

This means the device has automatically been detected and recognised by the system. It doesn't mean you have a means of watching the video data, not yet.

Watch the Video

First we're going to need some video capture tools

MPlayer is capable of displaying a webcam video stream.

MEncoder can record from a webcam to video files. The companion to MPlayer,

FFmpeg is a cross-platform audio/video recording, conversion and streaming application.

sudo apt-get install mplayer mencoder ffmpeg

Wait patiently for the programmes and the dependencies to be installed.

Record some video to File

add [user] to the video group

gpasswd -a [user] video

replace [user] with your username eg. jack

 sudo ffmpeg -f video4linux2 -s 320x240 -i /dev/video0 out.mpg
FFmpeg version SVN-r0.5.6-4:0.5.6-3, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --extra-version=4:0.5.6-3 --prefix=/usr --enable-avfilter --enable-avfilter-lavf 
--enable-vdpau --enable-bzlib --enable-libdirac --enable-libgsm --enable-libopenjpeg --enable-libschroedinger
 --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping 
--disable-vhook --enable-runtime-cpudetect --extra-cflags=-marm -fPIC -DPIC --enable-gpl --enable-postproc 
--enable-swscale --enable-x11grab --enable-libfaad --enable-libdc1394 --disable-decoder=cavs 
--disable-parser=cavsvideo --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 1 / 52.20. 1
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Dec 31 2011 19:52:32, gcc: 4.4.5
[video4linux2 @ 0x17b8f50][3]Capabilities: 5000001
[video4linux2 @ 0x17b8f50]ioctl(VIDIOC_DQBUF): Input/output error
Input #0, video4linux2, from '/dev/video0':
  Duration: N/A, start: 1231.422308, bitrate: N/A
    Stream #0.0: Video: rawvideo, yuyv422, 320x240, 1000k tbr, 1000k tbn, 1000k tbc
Output #0, mpeg, to 'out.mpg':
    Stream #0.0: Video: mpeg1video, yuv420p, 320x240, q=2-31, 200 kb/s, 90k tbn, 60 tbc
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding
frame=  432 fps= 17 q=16.0 Lsize=     550kB time=7.18 bitrate= 627.2kbits/s    
video:546kB audio:0kB global headers:0kB muxing overhead 0.816629%

Remember to press 'q' to stop the process


Troubleshooting

  • USB Camera not detected.
The RPi has limited capability to supply power to USB devices, try again using a powered USB hub.

Tested

This page has been tested on the following RPi build standards

  1. Linux raspberrypi 3.1.9+ #95 PREEMPT Thu May 31 13:21:40 BST 2012 armv6l GNU/Linux


References

  1. http://jeremyblythe.blogspot.co.uk/2012/06/battery-powered-wireless-motion.html
  2. http://jeremyblythe.blogspot.co.uk/2012/05/raspberry-pi-webcam.html
  3. http://benosteen.wordpress.com/2012/05/31/raspberrypi-birdfeeder-webcam/