I had been wanting to try this setup for quite a while. Thankfully, I found some time last weekend.
Requirements for this project:
- Raspberry Pi (version B or better)
- At least 2GB SD card
- Raspbian (Debian Wheezy)
- Webcam (in my case, that is Logitech QuickCam for Notebooks)
- The determination to continue this project, when something does not work on Linux as intended 😉
- mjpg-streamer package
So, what’s next?
First, you have to install Raspbian, which you can get from official Raspberry Pi website. Next, you will need to install the Raspbian image to a SD card using the method described in my previous post about installing XBMC.
You should get the Linux shell after connecting everything. Just in case, Raspbian default user is ‘pi’ and the password ‘raspberry’.
You can plug your webcam and check if it is properly detected by Raspbian using the command lsusb, which showed that my old Logitech webcam was connected:
ID 046d:08dd Logitech, Inc. QuickCam for Notebooks
It will be better if you will update Raspbian with the latest packages:
apt-get update apt-get upgrade
Next, you have to install some pre-requisites, which will help to have a smooth compilation from the mjp sources and not get the error messages like this:
jpeglib.h no such file or directory
sudo apt-get install libjpeg-dev subversion imagemagick
You are now ready to compile mjpg streamer:
mkdir sources cd sources svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/ mjpg-streamer cd mjpg-streamer make
If all required packages are present on the system, there should be no errors after compilation is completed. So, you should be able to start a streaming server by issuing the commands:
./mjpg_streamer -i "./input_uvc.so -r 320x232" -o "./output_http.so -w ./www"
mjpg_streamer can have the following parameters:
-i | input “<inputplugin.so> [parameters]”
-o | output “<outputplugin.so> [parameters]”
[-h | help ]
[-v | version ] will display version information
[-b | background] fork to the background, daemon mode
The command ‘kill’ is needed, in order to stop the server in daemon mode:
kill -9 pidof mjpg_streamer
input_uvc.so has some tweak-able parameters as well:
-d <device>, video device you will use (e.g. -d /dev/video0)
-r <resolution>, the resolution (e.g. -r 640×480 or 320×232)
-f <framerate>, the framerate (e.g. -f 30)
-q <quality>, the JPG compression quality in the range 1-100% (e.g. -q 80)
-y, usable if webcam doesn’t support MJPG.
The streamed video should be accessible from LAN entering ‘Streaming_Server_IP:8080’ on another PC browser:
VLC can be used to watch this streamed video by entering the network address ‘Streaming_Server_IP/?action=stream’:
However, you may noticed that my Logitech Webcam picture quality isn’t the highest grade… Better quality webcam is needed for normal setup. However, it was OK just for test 😉
QuickCam for Notebooks
My Logitech webcam did not show any life signs at the beginning after following all previously described steps. It was producing only noise on the screen. After some googling and reading, it appeared that for some less popular webcams to work a specific module is needed. That was gspca_zc3xx module in my case.
I had to enter the command to load that module:
sudo modprobe gspca_zc3xxsudo
Next, mjpg streamer complained about my webcam which didn’t support neither MJPG and chosen resolution. I plaid a little bit with that by reducing the resolution and some other settings and the streaming started to work!
If you have some difficulties with detecting a webcam under Raspbian OS, you could use the commands dmesg and lsusb to find out what’s wrong.
Last but not least, just a few more RPi commands
Keep in mind, that Rasbian does not like sudden power loss (e.g. unplugging). Opposite, you will have some troubles with the file system. In order to switch off properly a Raspbian, you need to enter such command:
shutdown -h now
or to reboot it write:
sudo shutdown -r 0
If your webcam needs a module, you can add to the file /etc/modules in order to automatically load every time when Raspberry Pi starts:
Enjoy your live streamed webcam!
ps Do you want do it the same but on RPi 2? Here is a link 😉