Because the Raspberry Pi webcam server presented in my last article is to slow for most applications regarding robotics, I want to go one step further in this article using mjpg-streaming.
For this article I use a Raspberry Pi model B connected to a Logitech c170 webcam (with an usb hub as external power supply). There is no additional webserver like apache necessary.
1. First of all make sure, that your webcam is listed correctly.
2. To start you’ve got to install the following packages:
apt-get install libv4l-dev apt-get install libjpeg8-dev apt-get install subversion apt-get install imagemagick
libv4l-dev and libjpeg8-dev are required dependencies. Subversion and ImageMagick will be needed to get and to compile the code.
3. Now you are ready to download and to compile the code you will need for mjpg streaming.
svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer cd mjpg-streamer/mjpg-streamer make USE_LIBV4L2=true clean all make DESTDIR=/usr install
4. You are now ready to start the mjpg streamer. Using the following line you start a mjpg stream at port 8090 with a resoultion of 320×240 px and 10 frames per second.
mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0 -r 320x240 -f 10" -o "/usr/lib/output_http.so -p 8090 -w /var/www/mjpg_streamer"
Input modifiers of mjpg_streamer are:
-f: frame rate
-y specifies YUYV format, rather than MJPEG format if MJPEG ist not supported by your webcam.
Output modifiers are:
-w: web serving directory.
See the documentation for more details.
5. To display the image stream just add this line to a html-file. You can replace “raspberrypi” with the ip adress of your Raspberry PI.
img src="http://raspberrypi:8090/?action=stream" width="752"