#WebCam: Using mjpeg streamer to stream video over HTTP

<div class="text-success lead">
This article illustrates how stream video on web using commercials USB webcams
</div>

In the following image is visible an Aria G25 SoM wired directly to the circuitry os a Microsoft HD-3000 webcam:

<a href="/ariag25_wirings">
<img src="./ariag25_hd3000_wiring.jpg" width="460px"/>
</a>

This is the result obtained on a web browser. <a href="./screenshot_full.jpg">Click to see the 1:1 dimension</a>.

<a href="./screenshot_full.jpg">
<img src="./screenshot_small.jpg" width="460px"/>
</a>

We've tested some webcams that belong to different classes of cost and feature:

* Microsoft Lifecam HD-3000
* Microsoft Lifecam HD-5000
* Microsoft Lifecam Cinema 720p HD webcam
* Microsoft LifeCam Studio 1080p HD
* Logitech Webcam C250 1.3 megapixel webcam
* Logitech QuickCam&reg; Sphere AF. Motorised 2-megapixel HD sensor webcam with Carl Zeiss&reg; optics.

All these cams are compatible with the USB Video device Class (UVC) that is a standard USB device 
class defined by the USB Implementers Forum.

The UVC driver for Linux are available here <a href="http://linux-uvc.berlios.de">http://linux-uvc.berlios.de</a> 
but since the Linux 2.6.26 is included in kernel source distribution. 

What we need more is **mjpeg_streamer** program that gets the mjpeg data from V4L2 and send it through a HTTP session.

Mjpeg_streamer automatically generates a set of html pages that illustrates different 
methods to stream the video over your browser. The best result comes using Google 
Chrome on any OS but it works well also on Firefox, Opera and IE. 

The stream works well but slower also on the **iPhone**.

Using the Logitech QuickCam Sphere AF it is possible to control also the camera tilt an pan with the default control panel.

<img src="./mjpg_streamer_home.jpg">

##MJPG Streamer installation

It is possible to install MJPG streamer from the sources and compile it directly on the Acme Linux Board.

Download the sources from this link:

* [mjpg-streamer.tar.gz](http://terzo.acmesystems.it/download/webcam/mjpg-streamer.tar.gz)

Save the file on the Acme board microSD then uncompress it by typing:

<pre class="minicom">
~# <b>tar -xvzf mjpg-streamer.tar.gz</b>
~# <b>cd mjpg-streamer</b>
~/mjpg-streamer#
</pre>

Install <b>make</b>, <b>libjpeg-dev</b> and <b>libv4l-dev</b> libraries:

<pre class="minicom">
~/mjpg-streamer# <b>apt-get update</b>
~/mjpg-streamer# <b>apt-get install make</b>
~/mjpg-streamer# <b>apt-get install libjpeg-dev</b>
~/mjpg-streamer# <b>apt-get install libv4l-dev</b>
</pre>

Now run the source compilation:

<pre class="minicom">
~/mjpg-streamer# <b>make</b>
</pre>

After a while the mjpg-streamer executable will be ready.

## Kernel > 3.11 troubleshooting

If you get this error:

<pre>
.. fatal error: linux/videodev.h: No such file or directory
</pre>

Create a soft link to /usr/include/linux/videodev2.h 

<pre class="minicom">
~/mjpg-streamer# <b>ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h</b>
</pre>

Comment also the following line in the <b>Makefile</b>:

<pre class="minicom">
# PLUGINS += input_gspcav1.so
</pre>

If at run time it still doesn't work verify, using <b>make menuconfig</b> that
that the <b>USB Video Class</b> is enabled in the Kernel :

<pre class="minicom">
Device Drivers  --->
	<*> Multimedia support  ---> 
		[*]   Media USB Adapters  --->
			<*>   USB Video Class (UVC)
</pre>
	


##How to use MJPG Streamer

Plug your webcam and type:

<pre class="minicom">
~/mjpg-streamer# <b>dmesg</b>
usb 1-2: new full speed USB device using at91_ohci and address 4
Linux video capture interface: v2.00
uvcvideo: Found UVC 1.00 device <unnamed> (046d:0804)
input: UVC Camera (046d:0804) as /devices/platform/at91_ohci/usb1/1-2/1-2:1.0/input1
usbcore: registered new interface driver uvcvideo
USB Video Class driver (v1.0.0)
usbcore: registered new interface driver snd-usb-audio
</pre>

Now run the streaming server typing:

<pre class="minicom">
~/mjpg-streamer# <b>./mjpg_streamer -i "./input_uvc.so -f 15 -r 640x480" -o "./output_http.so -w ./www"</b>
MJPG Streamer Version.: 2.0
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: 15
 i: Format............: MJPEG
 o: www-folder-path...: ./www/
 o: HTTP TCP port.....: 8080
 o: username:password.: disabled
 o: commands..........: enabled
</pre>

If you are using an [Aria G25](/aria) or [Terra board](/terra) on full 
speed USB ports (Port A and B) try to get the streaming in 720p resolution by typing:

<pre class="minicom">
~/mjpg-streamer# <b>./mjpg_streamer -i "./input_uvc.so -f 15 -r 1280x720" -o "./output_http.so -w ./www"</b>
</pre>

A complete list of examples are available on the start.sh file in mjpg_streamer directory.

The video below shows a web video streaming using the tilt and pan controls:

<iframe width="560" height="315" src="https://www.youtube.com/embed/LDGgvk0pRAE" frameborder="0" allowfullscreen></iframe>

##Notes for Debian Lenny 5.0 users

If you are using Debian Lenny 5.0 add to the /etc/apt/sources.list file this line:

<pre class="minicom">
deb http://backports.debian.org/debian-backports lenny-backports main
</pre>

##Related links

* [Aria G25 image sensor wiring](/aria_wirings_2)
* [MJPG-streamer project page](http://sourceforge.net/projects/mjpg-streamer/develop)
* [USB Video Class Linux device driver home page](http://linux-uvc.berlios.de)

@include='adv_roadrunner'

