How to stream webcam from Raspberry Pi with Raspbian(wheezy) installed.
1. Update apt-get:
$ sudo apt-get update
2. Install required packages:
$ sudo apt-get install libv4l-dev libjpeg8-dev subversion imagemagick uvcdynctrl -y
3. Copy mjpg-streamer code from svn and compile it
$ svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer
$ cd mjpg-streamer/mjpg-streamer
$ make USE_LIBV4L2=true clean all
$ sudo make DESTDIR=/usr install
4a. To get the best performing capture and streaming, change cpu governor setting to performance
$ sudo nano /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
erase "ondemand" -row and write "performance" (without quotes)save and exit with ctrl+o (enter), ctrl+x
4b. Optionally you can set a script to change the cpu governor to performance on boot, because the governor will always change back to ondemand after shutdown
$ sudo nano /etc/local.rc
copy and paste "echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" (without quotes)
save and exit with ctrl+o (enter), ctrl+x
do a $ sudo reboot, if you skipped setp 4a.
5. Plug in your USB webcam, if you haven't done so yet and use uvcdynctrl to list it's supported formats.
$ uvcdynctrl -f
To get the best performance, you should only use the formats you see in this list. even fullHD @30fps is using about 5% cpu.
6. Start streaming
Use this, if you did see mjpg listed in the supported formats:
$ mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0 -r 1280x720 -f 30 -n" -o "/usr/lib/output_http.so -p 8090 -w /var/www/mjpg_streamer"
else, add -y flag to the input string:$ mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0 -r 1280x720 -f 30 -n -y" -o "/usr/lib/output_http.so -p 8090 -w /var/www/mjpg_streamer"
7. Test it
open http://<RPi IP ADDRESS>