tidge27
Posts: 6
Joined: Sun Jun 17, 2012 8:38 pm

Mjpg-Streamer

Sun Jun 17, 2012 8:54 pm

Hi all,
This is my first post on the forums, so sorry if I miss a few things out!

Ok, my overall intent is to build a robot using the raspberry pi, so I will need a webcam stream and the GPIO to control the motors. I have managed to get the GPIO working, however I am struggling to find a way of streaming the webcam (ps2 eyetoy on /dev/video0) with minimal delay, which I want to get working before I setup anything else!

I have already tried to use motion, to stream the video, however I have had a delay of over 2 seconds, which would be unusable for my purpose, so I did some searching and found a thread on another forum which pointed me to mjpg-streamer. (http://sourceforge.net/projects/mjpg-streamer/). This is designed for low powered devices and other people have used it for this purpose, however I have had issues trying to install it. I would really appreciate it if someone could share a set of instructions of exactly how to install this on a pi, including dependencies, or an alternative method.

Thanks very much,
Tom

(just to let you know, but i a using debian)

funnel
Posts: 48
Joined: Sat May 05, 2012 8:00 am

Re: Mjpg-Streamer

Mon Jun 18, 2012 8:17 am

I wrote something about this here http://www.raspberrypi.org/phpBB3/viewt ... ing#p92461

Good luck.

tidge27
Posts: 6
Joined: Sun Jun 17, 2012 8:38 pm

Re: Mjpg-Streamer

Mon Jun 18, 2012 3:54 pm

Thanks very much for the quick response, however.....

I tried this as soon as I got home from school, but I had a couple of issues, firstly, about every other frame was either black or badly distorted making the feed very hard to interpret (I have heard of some issues with the eyetoy-ps2 webcam http://www.raspberrypi.org/phpBB3/viewt ... 08&p=98239), and I also still had a delay of about 1.5s

Any more ideas? :?:
Thanks
Tom

User avatar
AndrewS
Posts: 3634
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK

Re: Mjpg-Streamer

Mon Jun 18, 2012 6:12 pm

I believe VLC can be used to stream video. No idea how well it'd work on the RaspberryPi or with an EyeToy camera though... or what delay you'd get...

User avatar
ds18s20
Posts: 83
Joined: Fri Dec 23, 2011 5:44 am
Location: San Francisco

Re: Mjpg-Streamer

Tue Jul 31, 2012 11:56 pm

Getting MJPG-streamer working under Raspberry Pi would be a major breakthrough in usability. IP camera for $35 is significant. However I am sure the source will not compile so we need a guru help here to make it work under Raspberry Pi

All the other streamers are just inadequate comparison to MJPG-streamer. That thing just works.

User avatar
AndrewS
Posts: 3634
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK

Re: Mjpg-Streamer

Wed Aug 01, 2012 12:21 am

Other people have reported that they do have mjpg-streamer working http://www.raspberrypi.org/phpBB3/searc ... g+streamer
So maybe if you could report what compile errors you're getting... ;)

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia

Re: Mjpg-Streamer

Wed Aug 01, 2012 2:34 am

I had ffmpeg streaming with a pretty small delay on Raspbian.
less than a second IIRC.
Use the sources from deb-multimedia.org rather than the ones in the repos.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough

Re: Mjpg-Streamer

Thu Aug 02, 2012 5:59 pm

Yep, I am also desperately trying to do this.

Motion is incredibly intensive, using most of the webcam bandwidth...dismiss.

ffstream is very customisable but impossible to set up (at least to me!)

mjpeg-streamer is very easy but I can't get it to install on debian wheezy (videodev.h not found, think it's to do with it using v4l found on squeeze and not the v4l2 on wheezy?? confirm/deny?)

Anyone got any ideas?

My aim:
Expose webcam ('/dev/video0') to http://localhost:port

Thanks
Simon

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia

Re: Mjpg-Streamer

Fri Aug 03, 2012 2:39 am

howroyd wrote:Yep, I am also desperately trying to do this.

Motion is incredibly intensive, using most of the webcam bandwidth...dismiss.

ffstream is very customisable but impossible to set up (at least to me!)

mjpeg-streamer is very easy but I can't get it to install on debian wheezy (videodev.h not found, think it's to do with it using v4l found on squeeze and not the v4l2 on wheezy?? confirm/deny?)

Anyone got any ideas?

My aim:
Expose webcam ('/dev/video0') to http://localhost:port

Thanks
Simon
Grab deb-multimedia ffmpeg source
then follow this guide http://sirlagz.net/?p=357
The bitrate and videosize etc can be changed to suit your setup.

I'll probably write up a RasPi specific way of doing this later too.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough

Re: Mjpg-Streamer

Fri Aug 03, 2012 1:12 pm

No luck.

Compiled as per instructions here: http://www.raspberrypi.org/phpBB3/viewt ... =66&t=9045
All ok, no errors.

Made a file /etc/ffserver.conf which contains:

Code: Select all

Port 81
BindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 50000
NoDaemon

file webcam.ffm
FileMaxSize 10M

Feed webcam.ffm
Format mjpeg
VideoSize qvga
VideoFrameRate 10
VideoBitRate 100
Then ran:

Code: Select all

pi@raspberrypi:~$ sudo ffserver -f /etc/ffserver.conf & ffmpeg -v 2 -r 5 -s 320x240 -f video4linux2 -i /dev/video0 http://localhost:81/webcam.ffm
It pauses, then returns to "pi@raspberrypi:~$ ".
Inspection of processes using "top" show nothing of the above running, and pidof ffserver ad pidof ffmpeg both return nothing.

Help!

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia

Re: Mjpg-Streamer

Fri Aug 03, 2012 2:01 pm

change -v 2 to -v verbose
and then report back what happens.
-v 2 used to work but not anymore, I need to update that guide actually.

Also, I've updated a few other things in that post.
Wordpress stripped a few pretty important tags which I didn't notice :oops: :oops: :oops:
Shows how many people actually read my blog haha...
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough

Re: Mjpg-Streamer

Fri Aug 03, 2012 4:06 pm

Yes it's a brilliant guide, best I've found after hours on google!
Looks like and IO error, not a clue what this means with my limited knowledge!

Code: Select all

pi@raspberrypi:~$ sudo ffserver -f /etc/ffserver.conf & ffmpeg -v verbose -r 5 -s 320x240 -f video4linux2 -i /dev/video0 http://localhost:81/webcam.ffm
[1] 1673
ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
  built on Aug  3 2012 10:57:11 with gcc 4.6.3
  configuration:
  libavutil      51. 54.100 / 51. 54.100
  libavcodec     54. 23.100 / 54. 23.100
  libavformat    54.  6.100 / 54.  6.100
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 77.100 /  2. 77.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
[video4linux2,v4l2 @ 0x197e520] [3]Capabilities: 4000001
ffserver version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
  built on Aug  3 2012 10:57:11 with gcc 4.6.3
  configuration:
  libavutil      51. 54.100 / 51. 54.100
  libavcodec     54. 23.100 / 54. 23.100
  libavformat    54.  6.100 / 54.  6.100
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 77.100 /  2. 77.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
[video4linux2,v4l2 @ 0x197e520] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2,v4l2, from '/dev/video0':
  Duration: N/A, start: 117.112620, bitrate: 6144 kb/s
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 320x240, 6144 kb/s, 5 tbr, 1000k tbn, 5 tbc
[http @ 0x197ec10] HTTP error 404 Not Found
http://localhost:81/webcam.ffm: Input/output error
pi@raspberrypi:~$

User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough

Re: Mjpg-Streamer

Fri Aug 03, 2012 4:25 pm

Changed ffserver.conf to the below, now works fine through VLC.

Struggling receiving it in html though to embed it in my webpage, what's the best way? use img tags or iframe?
Port 81
BindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 50000
NoDaemon

<Feed webcam.ffm>
file /tmp/webcam.ffm
FileMaxSize 10M
</Feed>


<Stream webcam.mjpeg>
Feed webcam.ffm
Format mjpeg
VideoSize qvga
VideoFrameRate 10
VideoBitRate 100
</Stream>

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia

Re: Mjpg-Streamer

Fri Aug 03, 2012 4:53 pm

I would use an iframe, easiest way to do it.
Is this going to be an internet facing one or just for your local network ?

Just as an aside - I've written up a guide specific for the Raspberry Pi.
Hopefully this helps someone else too
http://sirlagz.net/?p=493
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

User avatar
howroyd
Posts: 39
Joined: Thu Aug 02, 2012 1:41 pm
Location: Loughborough

Re: Mjpg-Streamer

Fri Aug 03, 2012 5:26 pm

Network side initially but might open it up internet side; its part of an academic research project so would only be open at certain times

CrystalCowboy
Posts: 9
Joined: Mon Aug 27, 2012 8:44 pm

Re: Mjpg-Streamer

Sun Sep 02, 2012 8:02 pm

ds18s20 wrote:Getting MJPG-streamer working under Raspberry Pi would be a major breakthrough in usability. IP camera for $35 is significant. However I am sure the source will not compile so we need a guru help here to make it work under Raspberry Pi

All the other streamers are just inadequate comparison to MJPG-streamer. That thing just works.
mjpg-streamer is available as a package on Arch Linux ARM:

Code: Select all

pacman -S mjpg-streamer
On Raspbian (wheezy), here is how you can compile it. First, load some packages you will need.

Code: Select all

apt-get install subversion
apt-get install libv4l-dev
apt-get install libjpeg8-dev
apt-get install imagemagick
Subversion is software for downloading versioned software, it is used a lot by Open Source developers.
libv4l-dev and libjpeg8-dev are required dependencies.
ImageMagick will be needed for the installation, since it is used to process some image files during the compilation. (This is a bad move by the developers, IMHO).
Now to do the compilation (as root, or sudo):

Code: Select all

svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer
cd mjpg-streamer/mjpg-streamer
make USE_LIBV4L2=true clean all
make DESTDIR=/usr install
That should do it. To run mjpg-streamer, make sure no other processes are tying up the webcam, then it's something like this:

Code: Select all

mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0  -r 640x480 -f 1" -o "/usr/lib/output_http.so -p 8090 -w /var/www/mjpg_streamer"
Input modifiers:
-d specifies the device
-r is resolution
-f is frame rate
-y specifies YUYV format, rather than MJPEG format.

Output modifiers:
-p is port
-w is web serving directory.
See the documentation for more details.

Mjpg-streamer includes a lightweight web server, so you will not need to run apache or lighttpd. I think this is a wrong idea, but there it is.

A typical line in the html file for displaying an image stream looks like this:

Code: Select all

<img src="http://192.168.0.63:8090/?action=stream" width="752">
The port here should match the port specified in the mjpg-streamer command.

Some webcams will deliver MJPEG images. Mjpg-streamer is very efficient with these webcams, as it just reads the images and streams them to the web. I am seeing CPU usage of ~ 1% with a 640x360 resolution MJPEG image.

If you camera does not deliver MJPEG, you can probably still read it with the YUYV format, but there is more CPU overhead, because the software must read the YUYV and convert it to MJPEG in order to stream it.

If you don't know what formats your webcam delivers, try experimenting with fswebcam in "--verbose" mode. I found fswebcam to very useful for characterizing my cameras, and figuring out which resolutions they will serve. fswebcam reads an image from a webcam and writes it to a file. You can then see under what conditions it failed, and whether the files are garbled or not. (Files may be garbled if the resolution is somehow screwed up.) Fswebcam is available on both Arch and Wheezy as a package.

The best alternative to mjpg-streamer seems to be motion coupled with a web server like apache or lighttpd. Motion is very sophisticated software intended for surveillance video. Most of my effort in configuring it was spent turning off options I am not using.

On wheezy, I think motion's handling of MJPEG format from the webcam may be broken. That's a minor annoyance. MJPEG is at least 20 times more efficient in terms of size and bandwidth than YUYV, so if you want to go to higher resolution, MJPEG may work where YUYV fails. I was streaming 1280x960 resolution from a Logitech C310, at low frame rates.

Magsy
Posts: 1
Joined: Wed Sep 05, 2012 8:37 am

Re: Mjpg-Streamer

Wed Sep 05, 2012 8:48 am

CrystalCowboy

Thanks a _lot_. That post describes it all and it works perfectly! :D

I did use slightly different command line parameters.

Code: Select all

mjpg_streamer -i "./input_uvc.so -f 15 -r 1280x720" -o "./output_http.so -w ./www"
Using a HP 3110 I have 12.50fps solid at 1280x720 with 5% cpu usage (overclocked @ 1ghz)

selectnone
Posts: 55
Joined: Fri Jun 22, 2012 10:16 pm

Re: Mjpg-Streamer

Sun Oct 07, 2012 10:19 pm

Yeah, thanks a lot CrystalCowboy, that's exactly what I needed!

(I'm leaving the -w bit off, as I don't need an extra webpage served)

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Mjpg-Streamer

Fri Oct 12, 2012 7:17 am

Thanks a lot for this, CrystalCowboy.

The key point I originally missed was to add the -y parameter to input command. But it realy uses CPU when the camera can't provide jpeg directly.

I am using:
./mjpg_streamer -i "./input_uvc.so -y -d /dev/video0 -r 640x480 -f 10 -q 100 -n" -o "./output_http.so -n"

And that takes about 95% of CPU from my 1000 arm_freq turbo overclocked RPi.

lingon
Posts: 171
Joined: Fri Aug 26, 2011 7:31 am

Re: Mjpg-Streamer

Sun Nov 18, 2012 11:15 am

I tried out mjpg-streamer. A resolution of 960*720 with 15 frames / s results in a CPU load of 7-8 % when using MJPG-images from the webcam. This is very good, so the next problem is to get motion detection working. Has anyone tried using the mjpg-streamer output as input for motion on a different machine?

Even better would be to have motion running reliably on the Raspberry Pi also with larger frame sizes or to use the GPU for motion detection.

lingon
Posts: 171
Joined: Fri Aug 26, 2011 7:31 am

Re: Mjpg-Streamer

Sun Nov 18, 2012 4:52 pm

I tested another Logitech webcam which can go to 1600*1200 in MJPEG-mode, but for some reason streaming works very slow with this webcam with the 960*720 resolution which works fine with my older Logitech webcam. The CPU load was very low and I did not see any error messages, but in the browser the refresh rate of the images was one frame occasionally instead of 5 or 10 frames / s. I could test this on a PC, to see if the problem can be reproduced or not.

mybox
Posts: 4
Joined: Wed Oct 24, 2012 1:05 am

Re: Mjpg-Streamer

Wed Nov 21, 2012 4:28 am

Hi,

I'm also looking for solution for mjpg-streamer output as input for motion to record video on a different machine. Anyone has experience on this & what is the command to use for motion to record video whenever there is activities detected ?

Thanks

charleslinquist
Posts: 117
Joined: Wed Sep 05, 2012 12:43 pm

Re: Mjpg-Streamer

Sat Dec 01, 2012 9:59 pm

I got the source to compile, invoked Mjpg-streamer, and the light on my webcam shows that it is active.

Yet, whenever I go to my PC, and try to log in to the Pi's webserver (located at 192.168.1.214), I get nothing. I can get to the Pi at that address using Putty.

Should I be doing something else?

kelvinmead
Posts: 44
Joined: Tue Feb 05, 2013 9:19 pm
Location: Bristol, UK

Re: Mjpg-Streamer

Thu Feb 14, 2013 10:21 pm

apologies if this is a huge bump...

i have followed all the instructions to the letter with this, the libs, subversion and imagemagick are all the newest versions

but when i enter this line;

Code: Select all

svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer
i get

Code: Select all

svb: E000013: Can't make directory '/mjpg-streamer': Permission denied
using the pre-mentioned wheezy, and i've been using it for less than 24 hours, and i've installed LOADS of random packages, so it may be one of those bad boys?

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia

Re: Mjpg-Streamer

Fri Feb 15, 2013 1:39 am

Where are you running that command from ?
Try adding sudo to the front of that command.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

Return to “General discussion”