[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 use 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 a Raspberry Pi.
With the USB Camera attached to the Raspi, lsusb
returns something like this:
1 2 3 4 5 6 7 | 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)
1 2 3 4 5 | 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 |
Please note: Looks like the repo got recently moved, Try this to check-out the code if the previous step does not work:
1 | svn co https: //svn .code.sf.net /p/mjpg-streamer/code/mjpg-streamer/ mjpg-streamer |
Over on the Raspi, I tried to make the project, but quickly ran into 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
. This time, I 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
1 |
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
Raspberry Pi Webcam from Tech Casita Productions on Vimeo.
Let me know what Webcam software you found that works well on the Raspberry Pi.
@Peter Forget the second mjpg-streamer in cd mjpg-streamer/mjpg-streamer, just put
cd mjpg-streamer to enter the folder and run ./mjpg_streamer -i … command as given on this page. If you followed the steps on this page (except that double mjpg folder) you get it working.
Hi Wolf, this looks impressive. However, the only result I’m producing is my browser (Safari on Windows) saying “Could not open file” or “No file extension found”. Could you clarify the parameter “-w ./www”, and exactly what URL page I should call?
Nice. Thank You.
I am getting the following error:
pi@raspberrypi /dev/video0/mjpg-streamer $ sudo ./mjpg_streamer -i “./input_uvc.so” -o “./output_http.so -w ./www”
MJPG Streamer Version: svn rev: 3:160M
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 5
i: Format…………: MJPEG
ERROR opening V4L interface: Is a directory
Init v4L2 failed !! exit fatal
i: init_VideoIn failed
I am using a Logitech C270 webcam on a RPi B.2
sorry for my bad english i’m french
Mark :
my logitech (not same model as yours) don’t support less than 10 frames per second with mjpg_streamer.
this command work for me :
./mjpg_streamer -i “./input_uvc.so -d /dev/video0 -f 10 -r 640×480″ -o “./output_http.so -w ./www”
sorry i forget the y parameter in my command :
./mjpg_streamer -i “./input_uvc.so -d /dev/video0 -y -f 10 -r 640×480″ -o “./output_http.so -w ./www”
hello there,
can someone please help me with this error:
ERROR opening V4L interface: Is a directory
Init v4L2 failed !! exit fatal
I see it everywhere on the net but no solution is suggested. Urgent help needed!
+1 for the tutorial! It works like a charm
Can you tell me if I can start the webcam stream at boot?
Regards,
Alex
The instructions worked like a charm. I purchased an HP HD-2200 USB camera and it works fine. I am able to stream to VLC running on a Windows PC in 1280x720p mode and CPU utilization on the Raspberry never gets above 9%.
One note on getting the mjpg_streamer code. Rather than bother with svn, I used the command “wget http://lilnetwork.com/download/raspberrypi/mjpg-streamer.tar.gz” that I found on the raspberrypi.org site.
Got it installed on my board and it works great. I was wondering about the audio streaming piece. Would it be possible to use the audio input of the camera or raspberryp and stream that as well?
Thanks
Hap
I have installed.. But error occurs when i try
mjpg_streamer -i “/usr/local/lib/input_uvc.so” -o “/usr/local/lib/output_http.so -w /usr/local/www”
MJPG Streamer Version: svn rev: 3:172 i: Using V4L2 device.: /dev/video0 i: Desired Resolution: 640 x 480 i: Frames Per Second.: 5 i: Format…………: MJPEG Unable to set format: 1196444237 res: 640×480 Init v4L2 failed !! exit fatal i: init_VideoIn failed
kindly help me
Followed the instructions and it works fine
Thanks for the support its great
Ian
I’ve tried but i can’t see the streaming video from google chrome nor IE.
501: Not Implemented!
no www-folder configured
How to fix this error?
I tried to use VLC (http://192.168.7.2:8090/?action=stream), but nothing is showing on the VLC.
Any help?
thanks a lot.
Hi!
Thanks for the tutorial
I’m using raspberry pi B+ with Raspbian Wheezy and logitech C270. I tried running the mjpg-streamer with this command:
./mjpg_streamer -i “./input_uvc.so -n -f 15 -r 640×480″ -o “./output_http.so -n -w ./www”
it returned:
MJPG Streamer Version: svn rev: Unversioned directory
i: Using V4L2 device: /dev/video0
i: Desired resolution: 640×480
i: Frame per second: 15
i: Format: MJPEG
o: www-folder-path: ./www/
o: HTTP TCP Port: 8080
o: username:password: disabled
o: command: disabled
When i open mypyaddress:8080, the stream and static link only shows white.
Do you happen to know this problem and how to fix it?
It seems that with the latest raspbian image, and after doing a sudo apt-get update and sudo apt-get upgrade, the mjpeg streamer no longer works. You now have to use the -y when you launch in order to get it to work. It will work with the -y flag but the problem is that the fps will be a LOT slower. I’ve done a comparison with an old raspbian image using the normal mjpeg command as per wolf’s instructions, and with a totally new image based on 2015-02-16’s image and the fps is about 1 to 6 fps. The old image produces fps in the range of 8 – 31 fps, with dual-digit numbers typically more frequent.
Hello, I’m using mjpg_streamer for 3 USB webcams at same time, using other-pc-browser I can see video with almost no delay (I don’t really care about delay because I want to record video). So I use wget to record the stream but when playing the downloaded file it plays too fast so I loose timing on video… I guess it’s dropping frames or wget is not a “real-time-streaming-downloader”. It depends always on resolution (higher resolution faster-shorter video result). So, I have a few questions…
1) Can you think on a way to save streaming with real-timing?
2) Can I produce a stream with this tool and embed some info (like date/time banner as fswebcam)?
The command being executed is
#!/bin/sh
export LD_LIBRARY_PATH=”/usr/local/lib”
mjpg_streamer -i “input_uvc.so -d /dev/video0 -y -r 320×240 -q 75 -f 15 -l off” -o “output_http.so -p 8080 -w /usr/local/www” &
mjpg_streamer -i “input_uvc.so -d /dev/video1 -y -r 400×300 -q 75 -f 15 -l on” -o “output_http.so -p 8081 -w /usr/local/www” &
mjpg_streamer -i “input_uvc.so -d /dev/video2 -y -r 352×288 -q 75 -f 15 -l blink” -o “output_http.so -p 8082 -w /usr/local/www” &
sleep 5s
wget -O /tmp/mnt/cam0.mjpg http://127.0.0.1:8080/?action=stream &
wget -O /tmp/mnt/cam1.mjpg http://127.0.0.1:8081/?action=stream &
wget -O /tmp/mnt/cam2.mjpg http://127.0.0.1:8082/?action=stream
Note: everything is executed on the RPi (with wget output to an external smb mounted drive for testing and not overload the SD).
Thank you!
i:error grabbing frames pipe broken – comes after 10 or 15 min when it is turned on