phl
Posts: 4
Joined: Sun Dec 16, 2012 5:30 pm

webcam install script for mjpg-streamer

Mon Sep 04, 2017 1:39 pm

Hi all!
I was testing some different webcam settings for my camera pis (pi2+pi3).. because of that I wrote a small install bash script. I am sure that many of you could do it much better, shorter... but perhaps it is useful for someone. For me the mjpg-streamer with this settings is the best solution because the stream is very fluently and not very laggy even over wireless lan.


what it does:
- disable camera led
- install mjpg-streamer and dependencies with the following settings (change it in /opt/mjpg-streamer/mjpg-streamer-experimental/run.sh):
--- 1296x972 (for old camera module with full fov)
--- 15fps
--- jpg compr. quality 10
--- username: userxy
--- password: pass1234
- autostart mjpg-streamer script
- reboot

cpu workload is <4%



install script

Code: Select all

#!/bin/bash
#first do 'sudo raspi-config' and activate camera module and reboot
#then sudo this script

echo "disable_camera_led=1"
echo "disable_camera_led=1" >> /boot/config.txt
echo "max_usb_current=1"
echo "max_usb_current=1" >> /boot/config.txt

# UPDATES
echo "updates.."
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install subversion libjpeg8-dev imagemagick libav-tools libv4l-dev cmake git -y

# DOWNLOAD MJPG-STREAMER
echo "install mjpg-streamer.."
cd /opt
sudo git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental
export LD_LIBRARY_PATH=.
sudo make

# CREATE START SCRIPT
echo "create start script.."
sudo cat > /home/pi/run.sh << EOF
#!/bin/sh
#### CONFIG ##############
RESOLUTION_WIDTH="1296"
RESOLUTION_HEIGHT="972"
FPS="15"
QUALITY="10"
USERNAME=userxy
PASSWORD=pass1234
##########################
#ensure we are in the right path
cd /opt/mjpg-streamer/mjpg-streamer-experimental
export LD_LIBRARY_PATH=.
./mjpg_streamer -o "output_http.so -w ./www -c \$USERNAME:\$PASSWORD" -i "input_raspicam.so -fps \$FPS -x \$RESOLUTION_WIDTH -y \$RESOLUTION_HEIGHT -q \$QUALITY"
EOF

# MAKE IT EXECUTEABLE AND MOVE
echo "make start script executeable.."
sudo chmod +x /home/pi/run.sh
sudo mv /home/pi/run.sh /opt/mjpg-streamer/mjpg-streamer-experimental

# LINK SCRIPT IN STARTUP
echo "link start script in rc.local.."
sudo sed -i '$i/opt/mjpg-streamer/mjpg-streamer-experimental/run.sh' /etc/rc.local

sudo reboot







n00b install
1.) download and write rasbian strech (lite) to a micro sd card
2.) create a file "ssh" or "ssh.txt" to the boot partition of the new created sdcard
3.) for wireless access create and copy a file called "wpa_supplicant.conf" to the boot partition

Code: Select all

country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="your-SSID"
    psk="your-wireless-key"
}
4.) now connect over ssh or locally to the pi
5.)

Code: Select all

sudo raspi-config
(activate camera module, local settings like timezone, keyboard, expand filesystem etc..)
6.) reboot
7.)

Code: Select all

sudo nano install_webcam.sh
8.) paste install script content into the ssh window oder copy the script file.. however
9.) make the script executeable with

Code: Select all

sudo chmod +x install_webcam.sh
10.) execute the install_script with

Code: Select all

sudo ./install_webcam.sh
(make sure that your pi has internet access)

after this step the pi reboots and directly loads the mjpg-streamer start-script
you can now check the camera stream under:

Code: Select all

http://YOUR-PI-IP:8080




have fun!
regards, phil
Last edited by phl on Sun Sep 24, 2017 5:49 am, edited 4 times in total.

Granpino
Posts: 7
Joined: Thu Jun 04, 2015 8:26 am

Re: webcam install script for mjpg-streamer

Sat Sep 23, 2017 4:49 pm

I like the script and it works. I have been using mjpg-streamer with the raspberry camera for over a year. For some reason the stream stops and I have to refresh the browser to start it again. I have tried RPi_Cam_Web_Interface and PiKrellCam and they don't have that problem. I only need a simple and light streamer for my robot.

phl
Posts: 4
Joined: Sun Dec 16, 2012 5:30 pm

Re: webcam install script for mjpg-streamer

Sat Sep 23, 2017 4:56 pm

Hi Granpino,

I use a few pi cameras for my Synology NAS (Surveillance Station). Stream works there without problems. On my mobile devices I use IP CAM Viewer (available on android play store and apple app store). All works like a charm. But for the webbrowser view I cant help you a give any advise.. Also I have collected a bit more bash script knowledge and perhaps optimize the install script :)

Hopefully another guy can help you
regards, phil

User avatar
B.Goode
Posts: 8258
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: webcam install script for mjpg-streamer

Sat Sep 23, 2017 5:10 pm

what it does:

- rpi-update
Why?

phl
Posts: 4
Joined: Sun Dec 16, 2012 5:30 pm

Re: webcam install script for mjpg-streamer

Sat Sep 23, 2017 5:17 pm

B.Goode wrote:
Sat Sep 23, 2017 5:10 pm
what it does:

- rpi-update
Why?
I thought it is the cleanest and best way to do a upgrade or dist-upgrade and a rpi-update to get an update-to-date pi. Because of your question I just looked up again and found one source, saying that rpi-update is not always recommended. I think I have to look after that later this evening :-o

thanks for the hint!
not necessary - not recommended.

phl

Return to “Camera board”