Posts: 33
Joined: Sun Dec 30, 2012 11:08 pm
Location: Midlands UK

mjpg-streamer on bootup

Sat Jan 26, 2013 5:50 pm

Hi all,

I was wondering if someone can help me out?

I have mjpg-streamer installed that i normally start manually using
./ start
I am wanting to make mjpg-streamer start on boot up.

I followed this link initially but with no joy. ... ream-cctv/

The program is running after boot but only for a few seconds then i get no response from the page http://x.x.x.x:8081/?action=stream
When i say running i can see the process in netstat -lp -tu and for a few seconds the webcam stream works.
If i start it manually i get the response that its already runnning.
If I kill it first then start it manually the above url link working and video is streamed ok.

These are the actions i have taken to get this far.

I have created a file called in /etc/init.d/ directory. The contents are

Code: Select all

# /etc/init.d/
# v0.2
# Provides:
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mjpg_streamer for webcam
# Description:       Streams /dev/video0 to http://IP/?action=stream

        echo "[+] $1"
        echo "space here"

# Carry out specific functions when asked to by the system
case "$1" in
                f_message "Starting mjpg_streamer"
                /home/pi/mjpg-streamer/ start
                #mjpg_streamer -b -i "/usr/lib/ -d /dev/video0" -o "/usr/lib/ -p 8081 -w /var/www/mjpg_streamer -n"
                sleep 2
                f_message "mjpg_streamer started"
                f_message "Stopping mjpg_streamer."
                /home/pi/mjpg-streamer/ stop
                f_message "mjpg_streamer stopped"
                f_message "Restarting mjpg_streamer"
                /home/pi/mjpg-streamer/ stop
                #killall mjpg-streamer
                /home/pi/mjpg-streamer/ start
                 #mjpg-streamer -b -i "/usr/lib/ -d /dev/video0" -o "/usr/lib/ -p 8081 -w /var/www/mjpg_streamer -n"
                sleep 2
                f_message "Restarted mjpg_streamer"
                pid=`ps -A | grep mjpg-streamer | grep -v "grep" | grep -v mjpg-streamer. | awk .{print $1}. | head -n 1`
                if [ -n "$pid" ];
                        f_message "mjpg_streamer is running with pid ${pid}"
                        f_message "mjpg_streamer was started with the following command line"
                        cat /proc/${pid}/cmdline ; echo ""
                        f_message "Could not find mjpg_streamer running"
                f_message "Usage: $0 {start|stop|status|restart}"
                exit 1
exit 0

you can see that i commented out the line

Code: Select all

mjpg-streamer -b -i "/usr/lib/ -d /dev/video0" -o "/usr/lib/ -p 8081 -w /var/www/mjpg_streamer -n"
as this was the only way to get it working manually, by putting the direct path to the program and adding the start/stop parameter on the end instead.

After creating the above I made the file and path to it executable using chmod +X <xxx> and chmod 777 <name>.

I then did as per the instructions and made it runnable from boot with

Code: Select all

sudo update-rc.d defaults
Watching the streaming url on bootup, it starts the webpage streaming but then it stops(light goes out on webcam/url stops responding) even though the process (netstat -lp -tu) still shows it as running.

My thoughts were that there was a problem with the symbolic links and one of these was killing the program but there again it still showing in netstat- -lp -tu.
To try it anyway I manually added these
ln -s /etc/init.d/ /etc/rc0.d/
ln -s /etc/init.d/ /etc/rc1.d/
ln -s /etc/init.d/ /etc/rc2.d/
ln -s /etc/init.d/ /etc/rc3.d/
ln -s /etc/init.d/ /etc/rc4.d/
ln -s /etc/init.d/ /etc/rc5.d/
ln -s /etc/init.d/ /etc/rc6.d/
So in all i think the process is running from boot but there is a problem with the actual streaming working, but as mentioned only when asking it to do it from boot, works ok when manually executing the program with
/etc/init.d/ start
I maybe off the track completely so maybe useful to try and diagnose why it starts and works ok and then a few seconds after, further into the bootup, it stops again.

If anyone has any ideas or tips they would be much appreciated.

Thanks in advance

Posts: 42
Joined: Sat Sep 22, 2012 1:54 am

Re: mjpg-streamer on bootup

Tue Feb 05, 2013 2:32 pm

Not to hijack a thread, but I have a similar problem with mjpg-streamer... I have also set it to start on boot and run as a service....this works fine, but only for a short while. In fact, it doesn't matter how i start mjpg-streamer. It olny streamer for a short time. When the stream stops, the service is still running, I just lose the video. To get it running again I simply restart the service. In my case, the light on the webcam stays on even though the stream has stopped. I made a workaround for this by using a php script in my webpage to allow me to reset the service from within the browser...not pretty, but it works...

I have a feeling this problem is rooted in the very problematic USB driver/hardware we are stuck with....if anyone out there has a suggestion, please help!


Posts: 33
Joined: Sun Dec 30, 2012 11:08 pm
Location: Midlands UK

Re: mjpg-streamer on bootup

Tue Feb 05, 2013 6:10 pm


That is interesting as to why it is stopping whatever way you choose to start it.

Before i mentioned that mine would start for a few seconds during boot and then stop.

I found during my investigations that I may have been confusing the system by having mjpg-streamer installed in my own directory with its own file and also having a copy of the for-mentioned script created in my etc/init.d/ directory. This along with my start and stop symbolic links i think it was getting killed somewhere.

I got around this by removing all the symbolic links from the rcX.d directories, removing the script from the /etc/init.d/ directory.

I now simply call the file once from its original install directory by placing the code i would use to call it manually into my etc/rc.local file.

here is a snippet of how my rc.local files looks.

Code: Select all

case "$1" in
        /home/pi/mjpg-streamer/ start
Hope this helps others in the future.

when you say yours in running, do you see the process in ps aux? I was using netstat -lp -tu to check if mjpg-streamer was running initially until i realized that by doing ps aux | grep mjpg I could see the script had been started from within my install directory and from where my symbolic links were pointing.


Posts: 1
Joined: Thu Oct 17, 2013 6:54 pm

Re: mjpg-streamer on bootup

Thu Oct 17, 2013 7:19 pm

Hi initially faced problems like you. The streamer would start at boot but then drop dead.
However I just had a hunch that this could be related to power supply as I had read on multiple threads about problems attributed to bad supply. I was using a 5.5 V 500 mA power supply. I replaced that by my Galaxy S4 charger 5V 2A. And my problem was resolved without doing anything of the sort mentioned by you. I haven't had a single crash of mjpg streamer since then. It starts with every boot and works for hours at a stretch.


Return to “Raspbian”

Who is online

Users browsing this forum: No registered users and 23 guests