[Last updated on Feb. 2. 2013 for (2012-12-16-wheezy-raspbian) Kernel Version 3.2.27+]
Three years ago, we bought two small Webcams and since we wanted to used them on Linux and OS X, we went with the UVC and Mac compatible Creative LIVE! CAM Video IM Ultra. This Webcam (Model VF0415) has a high-resolution sensor that lets you take 5.0-megapixel pictures and record videos at up to 1.3-megapixel, supported resolutions include 640×480, 1290×720, and 1280×960. If you like, you can go back and read what I was thinking about the IM Ultra back in 2009. Today, it’s not much used anymore, but may just be the right accessory for an Raspberry Pi.
With the USB Camera attached to the Raspi, lsusb returns something like this:
lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS] Bus 001 Device 005: ID 041e:4071 Creative Technology, Ltd
Using the current Raspbian “wheezy” distribution (Kernel 3.2.27+), one can find the following related packages, ready for deployment:
- luvcview, a camera viewer for UVC based webcams, which includes an mjpeg decoder and is able to save the video stream as an AVI file.
- uvccapture, which can capture an image (JPEG) from a USB webcam at a specified interval
While these might be great tools, mpeg-streamer looks like a more complete, one-stop-shop kind-of solution.
Get the mpeg-streamer source code
Either install Subversion (svn) on the Raspberry Pi or use svn installed on your Mac or PC, to get the source-code before using Secure Copy (scp) to copy it over to your Raspi.
Here, I’m using svn, which is already installed on the Mac, before copying the files over to my Raspi, (username pi, hostname is phobos)
cd ~ mkdir tmp cd tmp svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer scp -r ./mjpg-streamer pi@phobos:mjpg-streamer
Over on the Raspi, I tried to make the project, but quickly ran into an error messages hinting at a missing library.
ssh pi@phobos
cd mjpg-streamer/mjpg-streamer
make
...
jpeg_utils.c:27:21: fatal error: jpeglib.h: No such file or directory, compilation terminated.
make[1]: *** [jpeg_utils.lo] Error 1
After finding out which libraries were available (apt-cache search libjpeg), I installed libjpeg8-dev like so: sudo apt-get install libjpeg8-dev. And this time got a lot further before hitting the next build error:
make
...
make[1]: *** [pictures/640x480_1.jpg] Error 127
make[1]: Leaving directory `/home/pi/mjpg-streamer/mjpg-streamer/plugins/input_testpicture'
After some google-ing, which resulted in installing ImageMagick like so: sudo apt-get install imagemagick, the next build attempt looked much more promissing:
make
..
and ls -lt shows the newly built files on top:
-rwxr-xr-x 1 pi pi 13909 Sep 8 07:51 input_file.so
-rwxr-xr-x 1 pi pi 168454 Sep 8 07:51 input_testpicture.so
-rwxr-xr-x 1 pi pi 31840 Sep 8 07:50 output_http.so
-rwxr-xr-x 1 pi pi 14196 Sep 8 07:50 output_udp.so
-rwxr-xr-x 1 pi pi 19747 Sep 8 07:50 output_file.so
-rwxr-xr-x 1 pi pi 29729 Sep 8 07:50 input_uvc.so
-rwxr-xr-x 1 pi pi 15287 Sep 8 07:50 mjpg_streamer
-rw-r--r-- 1 pi pi 1764 Sep 8 07:50 utils.o
-rw-r--r-- 1 pi pi 9904 Sep 8 07:50 mjpg_streamer.o
MJPG-streamer
MJPG-streamer is a command line tool to stream JPEG files over an IP-based network. MJPG-streamer relies on input- and output-plugins, e.g. an input-plugin to copy JPEG images to a globally accessible memory location, while an output-plugin, like output_http.so, processes the images, e.g. serve a single JPEG file (provided by the input plugin), or streams them according to existing mpeg standards.
Therefore, the important files that were built in the previous step are:
- mjpg_streamer – command line tool that copies JPGs from a single input plugin to one or more output plugins.
- input_uvc.so – captures such JPG frames from a connected webcam. (Stream up to 960×720 pixel large images from your webcam at a high frame rate (>= 15 fps) with little CPU load.
- output_http.so – HTTP 1.0 webserver, serves a single JPEG file of the input plugin, or streams them according to M-JPEG standard.
Starting the Webcam Server
A simple launch command would look like this:
./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"
MJPG Streamer Version: svn rev:
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 5
i: Format…………: MJPEG
o: HTTP TCP port…..: 8080
o: username:password.: disabled
o: commands……….: enabled
Open a Webbrowser on another computer on the LAN and open this url: http://{name or IP-address of the Raspi}:8080
However, experimenting with the resolution and frame rate parameters is well worth it and can improved the outcome.
UVC Webcam Grabber Parameters
The following parameters can be passed to this plugin:
| -d | video device to open (your camera) |
| -r | the resolution of the video device, can be one of the following strings: QSIF QCIF CGA QVGA CIF VGA SVGA XGA SXGA or a custom value like: 640×480 |
| -f | frames per second |
| -y | enable YUYV format and disable MJPEG mode |
| -q | JPEG compression quality in percent (activates YUYV format, disables MJPEG) |
| -m | drop frames smaller then this limit, useful if the webcam produces small-sized garbage frames may happen under low light conditions |
| -n | do not initalize dynctrls of Linux-UVC driver |
| -l | switch the LED “on”, “off”, let it “blink” or leave it up to the driver using the value “auto” |
HTTP Output Parameters
The following parameters can be passed to this plugin:
| -w | folder that contains webpages in flat hierarchy (no subfolders) |
| -p | TCP port for this HTTP server |
| -c | ask for “username:password” on connect |
| -n | disable execution of commands |
I have seen some good results with this
./mjpg_streamer -i "./input_uvc.so -n -f 15 -r 640x480" -o "./output_http.so -n -w ./www"
but even a much higher resolution didn’t impact the actually observed frame-rate all that much:
./mjpg_streamer -i "./input_uvc.so -n -f 15 -r 1280x960" -o "./output_http.so -n -w ./www"
MJPG Streamer Version: svn rev:
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 1280 x 960
i: Frames Per Second.: 15
i: Format…………: MJPEG
o: www-folder-path…: ./www/
o: HTTP TCP port…..: 8080
o: username:password.: disabled
o: commands……….: disabled
Webcam Stream Clients
The included Website (http://{name or IP-address of the Raspi}:8080) shows examples for how to connect a client to the Webcam stream. The easiest way is obviously a simple HTML page that works great with Google Chrome and Firefox but not so much with Safari. Anyways, it’s important to specify the width and height that was configured with the output_http.so, in the HTML as well
<img alt="" src="http://phobos:8080/?action=stream" width="1280" height="960" />
Raspberry Pi Webcam Streamer
Taking the Raspberry Pi Web Stream Server Outside
This is the Raspberry Pi powered by a 5VDC, 700mA battery, with an (Edimax EW-7811Un) USB-WiFi Adapter and the Creative LIVE! CAM Video IM Ultra connected.

Video Lan Client for Viewing and Recording
Using Video Lan Client, you can view and also record the video stream, served by the Raspi.

Recorded Webcam Streamer
Movie, streamed from a Raspberry Pi
Let me know what Webcam software you found that works well on the Raspberry Pi.


I’m currently researching all of the various attempts to hook a webcam up to the Raspberry Pi and yours looks like the best I’ve seen yet. Everybody else seems to be using the ffmpeg / motion packages and are getting very limiting CPU loads. Am I reading correctly that you can set up for 1280 X 960 X 15 fps with MJPEG Streamer on the Raspberry and it actually works fairly well? This is quite an acomplishment if so. Congrats! Any follow-up comments?
Have you had any problems with mjpg-streamer completely locking up the RasPi board? I can, with a bit of work, get it running but within 5 seconds the board completely locks and the only way to recover is with a power cycle. It won’t even respond to a ping, etc.
I did not see any problems. I.e., the Raspberry Pi did not become un-responsive. I have a RaspberryPi with a webcam setup for a longer term test, which you can take a look at over here:
http://wolfpaulus.com/systems/raspberrypi_livecam
Hi.
I like result of your work but have you thought about connecting more cameras to Raberry device? I know that USB port can be expanded by USB hub but does that mean that more cameras can be attached to Rasberry? I am not thinking about streaming video from all of them at the same time but rather about an option for a user to choose previewed camera.
Regards
Michal
I tried with http://www.facevsion.com/en/modules/tinyd1/index.php?id=57 but I get “could not initialize” … the webcam should be nice it is HD…
Hello,
Do you if is possible and, if so, know how to, capture as images frames from a computer VGA output, instead from the USB CAM?
Thanks for the article! I got my RPI & Logitech webcam C310 up & running in no time!
I have a problem with a view video on my cellphone. I have HTC Desire HD (Android). So how Can I view a video on my cell? Any ideas?
BestRegards,
Andrew
Thanks for your article! Like ricky said, most others tutorials explain the use of motion with ffmpeg. I’ll try your explanations as soon as I get a new compatible webcam, mine died a few weeks ago
Great work on explaining how to make this work. I was super disappointed that I couldn’t do the most basic stuff other than logging into a text console on that Pi but now it is actually usable for something… Thank you
Just found your pages. Interesting.
I’m going to want to hook up a webcam ( or the Pi camera) soon… this looks like very helpful information.
My own project uses a PI to rotate an object via a stepper motor, takes ‘frontal’ view from 360 degrees , using a digital camera & servo control at present,then uses ImageMagick to crop to a central strip & then append them. It’s kind of the inverse of an eggbot, which I also run off my Pi & Inkscape. Eggbots take 2D drawings & wrap them round cylinders. My project ‘unrolls’ a 3D clinder into a 2D picture.
See http://www.diga.me.uk/360degreeCamera.html
I want if possible to call IM from within Python scripts- something I’ve been doing for several years with Liberty BASIC on a PC.
I’m confused, how does one actually start the stream?
Perfect instructions, got it to work first time. Thanks!
I tried with Guillemot HD Exchange camera and it’s working fine.
All the solutions using ffserver or avconv to stream video were inconclusinve for me. the only one working was the solution with mjpg_streamer.
Thanks for your article.
I followed all your steps, and get this:
pi@raspberrypi ~/tmp_compile/mjpg-streamer/mjpg-streamer $ ./mjpg_streamer -i “./input_uvc.so -n -f 15 -r 1280×960″ -o “./output_http.so -n -w ./www”
MJPG Streamer Version: svn rev: 3:172
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 1280 x 960
i: Frames Per Second.: 15
i: Format…………: MJPEG
Unable to set format: 1196444237 res: 1280×960
Init v4L2 failed !! exit fatal
i: init_VideoIn failed
Happens with other resolutions and frame rates, same error.
I am usign this webcam: Bus 001 Device 007: ID 046d:081b Logitech, Inc. Webcam C310
Any ideas?
Awesome! It works just as you describe. I plan to rework my website around this
@radu
I had the same problem and searched on the web for an answer. I was able to fix it by adding an extra option to the command.
I run:
sudo ./mjpg_streamer -i “./input_uvc.so –yuv -f 30 -r 320×240″ -o “./output_http.so -w /www”
The key for me was to use –yuv mode.
Hope this helps!
Note: –yuv is two hyphens. ie. (-)(-) yuv. The font in the comments section makes it look like one hyphen
I remember fighting for days on my old Debian server to get the webcam (Microsoft Lifecam) to work and in the end, the Motion packages were the ones that did the trick. I’ll try this out since I’m migrating the old dog to my 2nd RPi.
Brilliant, got it up and running quickly and exactly as described, including the missing packages.
My only advice to newbies is always update/upgrade if you have any problems. It may be a lengthy process but usually solves whatever issues you have.
Great article and tutorial. Thank you for all your hard work. I was wondering if this includes motion detection? if not, would it be possible to implement it?
My setup completely failed with ffserver/ffmpeg, avconv/avserver and motion… But worked first time with mjpg-streamer – it’s a great system, thanks for sharing! I’m using Rpi 1st gen, Occidentalis 0.2 and Microsoft lifecam 5000.
Hi
Interesting.
Have you run the system 24×7 for a couple of weeks without any hangs etc?
Thanks
Hi,
Well done. I tried a number of video streaming methods and the results were not satisfactory. For example, SimpleCV was taking up too much CPU resources in the RPi. Motion’s frame rate was too low. Before I tried your procedure, I followed the one at http://www.slblabs.com/2012/09/26/rpi-webcam-stream/. I had problem compiling one of the plugins. The one you presented above works much better.
I use the command as follow because I am using a very cheap compact 300k pixel webcam:
./mjpg-streamer -i “./input_uvc.so -f 20 -y -r 320×240″ -o “./output_http.so -w ./www”
Just a quick update: I manage to plug in two 300k pixel webcams and stream over wifi using mjpg-streamer without any problem. Mjpg-streamer is the best solution that I found so far. Thanks again for the post.
Thank you so much, after trying Motion & ffMpeg we now have mjpg running on our 3G – controlled ‘lego rover’ with on-board webcam & Raspberry PI!
I’m having difficulty finding a good way to capture a single frame from mjpg_streamer. In my application I’m streaming a low resolution (176×144) video, but I want to then capture a single high resolution frame (1920×1020) from the same device. I’m working from python currently sending the shell commands through subprocess(). At the moment I’m killing the lores stream, starting a hi-res file export, killing the file output using killall -9 mjpg_streamer, then restarting the lores stream, but the server doesn’t stay killed, it pops back up again. I’ve also tried service a hires stream briefly then wget-ting an 127.0.0.1:8090/?action=snapshot, but similar problem. Any suggestions for a good way to switch resolutions and grab a single frame?
First off awesome guide, streaming worked great with http output. Was thinking about using a webcam stream in conjunction with screanly OSE, a digital signage program for the pi. Anyways, it has an option to include a website in the slideshow, but when using http output, screanly did not detect a website. This brought me to output_file and I read a bit at
http://sourceforge.net/apps/mediawiki/mjpg-streamer/index.php?title=Output_file
on getting the jpg moved, and got files captured from the webcam, but when embedding the jpeg into website got a broken image file.
http://wolfpaulus.com/systems/raspberrypi_livecam
looks like what i was getting as well. Were you perhaps using output_file?
I followed the soureforge tutorial exactly and tried moving location of moved.jpg around to see if it was a rights issue. No luck though. Any thoughts? I was looking at getting ffmpeg to transcode a .mpjeg into a .mp4 and serving it with an html5 video container. If that makes sense. I’m not much of a programmer…
mjpg_streamer installation according to this tutorial worked fine ina few minutes. Thank you!
I tested different webcams,
GS90 Panasonic DV-recorder
GS17 Panasonic DV-recorder
Logitech Webcam QuickCam USB PID_08DA
Only the older GS17 DV-Camcorder worked with 320×240 resolution, the images of the other two Cams was flickering in the video lan client and also via browser.
But this seems not to be a problem of mjpg_streamer, because I tried the Quickcam also with uvc.
Hey,
I managed to set up my Microsoft LifeCam HD with this tutorial. It worked very well! Just wanted to say thanks for the tutorial
I also liked the web interface that was available with MJPG-streamer. I haven’t done much else with the Pi since but need to start again!
Ross
I get se same problem as Ross, the image is flickering. I’ve tried two different Logitech webcams. Does anyone know how to fix this? Motion gave me correct images, but was very slow so I have no idea what could be wrong…
Hi, i just wanna ask, can i stream my webcam on global web page with mjpg-streamer way