Monitor a Webcam

From SingletonMillerWiki
Revision as of 17:00, 19 June 2012 by Martin (Talk | contribs) (References)

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.

Video Tools

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.

User Permissions

List the current users who can access video devices, using

cat /etc/group | grep video
video:x:44

Modify the group to add your user

gpasswd -a [user] video

replace [user] with your username eg. jack

video:x:44:jack

Group changes only change when you next login, so logout and log back in.

View a live feed

mplayer tv:///dev/video0 

when viewing this via a remote SSH connection you'll need your RPi display on to see the output!

Use Ctrl-C to terminate the feed.

I noticed that there were a large number of dropped frames reported by mplayer.

MPlayer interrupted by signal 2 in module: filter_video
v4l2: ioctl set mute failed: Invalid argument
v4l2: 416 frames successfully processed, 1225 frames dropped

This is probably related to the RPi limited CPU when processing my 640x480 images.

Save video to a file

ffmpeg -f video4linux2 -s vga -i /dev/video0 out.mpg

You may need to experiment with the format -f video4linux2 or the size -s vga to match your webcam.

Remember to press 'q' to stop the process

Convert the video format

mencoder out.mpg -ovc lavc -lavcopts vcodec=mpeg4 -o out2.avi

This converts the mpeg2 data to mpeg4.

Note, transcoding video formats on your RPi will be slow.

Now you can playback using the hardware accelerated player omxplayer, assuming you have it installed.

omxplayer out2.avi

Troubleshooting

  • USB Camera not detected.
  1. The RPi has limited capability to supply power to USB devices, try again using a powered USB hub.
  2. Search google to check if your webcam is support by linux.[1]

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. https://help.ubuntu.com/community/Webcam
  2. http://jeremyblythe.blogspot.co.uk/2012/06/battery-powered-wireless-motion.html
  3. http://jeremyblythe.blogspot.co.uk/2012/05/raspberry-pi-webcam.html
  4. http://benosteen.wordpress.com/2012/05/31/raspberrypi-birdfeeder-webcam/