Wednesday, February 27, 2013

USB Webcam on the Raspberry Pi

I wanted to use a USB webcam to mount on the robot, and drive it using the RPi. Turns out it is pretty simple to not only drive a USB webcam, but to also stream a MJPEG video feed over a port. After plugging the webcam in, we can check to see if the device is detected:

I run Arch on my RPi, which means installing things is super easy. Someone wrote up some software to do this streaming called mjpg-streamer.

$ sudo pacman -S mjpg-streamer

Once this installs the software is relatively simple to run. The options are defined as follows:

-d - USB Webcam (or video device)
-r - Resolution
-f - Frame Rate
-p - Port Number
-w -Web directory

An example of running the software:

$ mjpg_streamer -i "/usr/lib/ -d /dev/video0  -r 640x480 -f 28" -o "/usr/lib/ -p 8090 -w /var/www/mjpg_streamer"

This will send the stream over port 8090. Which can be accessed via URL through the following link (where alarmpi is the IP of the raspberry pi).


This works with browsers which can read mjpg streams. If you happen have a web-controlled servo and some tape, you can embed the stream in the website and have a rotatable webcam.

No comments:

Post a Comment