User Tools

Site Tools


rpi_livestream

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rpi_livestream [2015/04/04 23:47]
wbeckett
rpi_livestream [2021/06/04 02:16] (current)
Line 7: Line 7:
  
 First, update the Raspberry Pi and then install some of the dependencies of MJPG-Streamer. First, update the Raspberry Pi and then install some of the dependencies of MJPG-Streamer.
-sudo apt-get update sudo apt-get upgrade sudo apt-get install libjpeg8-dev imagemagick libv4l-dev 
-1 
-2 
-3 
   
 sudo apt-get update sudo apt-get update
Line 17: Line 13:
  
 An adjustment needs to be made:  the videodev.h ​ file has been replaced with videodev2.h ​ but this change needs to be made manually. ​ To do this, just create a symbolic link. An adjustment needs to be made:  the videodev.h ​ file has been replaced with videodev2.h ​ but this change needs to be made manually. ​ To do this, just create a symbolic link.
-sudo ln -s /​usr/​include/​linux/​videodev2.h /​usr/​include/​linux/​videodev.h 
-1 
   
 sudo ln -s /​usr/​include/​linux/​videodev2.h /​usr/​include/​linux/​videodev.h sudo ln -s /​usr/​include/​linux/​videodev2.h /​usr/​include/​linux/​videodev.h
Line 30: Line 24:
  
 Install subversion (if necessaary). Install subversion (if necessaary).
-sudo apt-get install subversion 
-1 
   
 sudo apt-get install subversion sudo apt-get install subversion
  
 Then, download a copy of the MJPG-Streamer source code to your home folder and move into the directory when the download is complete: Then, download a copy of the MJPG-Streamer source code to your home folder and move into the directory when the download is complete:
-cd ~ svn co https://​svn.code.sf.net/​p/​mjpg-streamer/​code/​mjpg-streamer/​ mjpg-streamer cd mjpg-streamer 
-1 
-2 
-3 
   
 cd ~ cd ~
Line 50: Line 38:
     input_file.so (for camera module): similar to the above, but copies them from a directory.     input_file.so (for camera module): similar to the above, but copies them from a directory.
     output_http.so:​ streams the files to a Webserver     output_http.so:​ streams the files to a Webserver
- 
-make mjpg_streamer input_file.so input_uvc.so output_http.so 
-1 
   
 make mjpg_streamer input_file.so input_uvc.so output_http.so make mjpg_streamer input_file.so input_uvc.so output_http.so
Line 62: Line 47:
  
 Run the following commands to copy it to a more globally-accessible area: Run the following commands to copy it to a more globally-accessible area:
-sudo cp mjpg_streamer /​usr/​local/​bin sudo cp output_http.so input_file.so input_uvc.so /​usr/​local/​lib/​ sudo cp -R www /​usr/​local/​www 
-1 
-2 
-3 
   
 sudo cp mjpg_streamer /​usr/​local/​bin sudo cp mjpg_streamer /​usr/​local/​bin
Line 75: Line 56:
  
 If you did try to run mjpg_streamer ​ now, it probably returned an error about search paths. ​ This is because right now, the system doesn’t know where to find the files. ​ This is an easy fix.  Just append the following line to ~/.bashrc (assuming you ran the commands above to copy the files to /usr/local/ .  This will make it a permanent change so that you don’t need to do this every time you log in: If you did try to run mjpg_streamer ​ now, it probably returned an error about search paths. ​ This is because right now, the system doesn’t know where to find the files. ​ This is an easy fix.  Just append the following line to ~/.bashrc (assuming you ran the commands above to copy the files to /usr/local/ .  This will make it a permanent change so that you don’t need to do this every time you log in:
-export LD_LIBRARY_PATH=/​usr/​local/​lib/​ 
-1 
   
 export LD_LIBRARY_PATH=/​usr/​local/​lib/​ export LD_LIBRARY_PATH=/​usr/​local/​lib/​
Line 82: Line 61:
 Now you can either log out and back in again, but it is easier to run the source ​ command to apply the change (this has the same effect as logging in): Now you can either log out and back in again, but it is easier to run the source ​ command to apply the change (this has the same effect as logging in):
  
-source ~/.bashrc 
-1 
   
 source ~/.bashrc source ~/.bashrc
Line 91: Line 68:
  
 Start running mjpg_streamer ​ with the command: Start running mjpg_streamer ​ with the command:
 +
 /​usr/​local/​bin/​mjpg_streamer -i "/​usr/​local/​lib/​input_uvc.so"​ -o "/​usr/​local/​lib/​output_http.so -w /​usr/​local/​www"​ /​usr/​local/​bin/​mjpg_streamer -i "/​usr/​local/​lib/​input_uvc.so"​ -o "/​usr/​local/​lib/​output_http.so -w /​usr/​local/​www"​
-1 
-  
-/​usr/​local/​bin/​mjpg_streamer -i "/​usr/​local/​lib/​input_uvc.so"​ -o "/​usr/​local/​lib/​output_http.so -w /​usr/​local/​www"​ 
- 
  
 === this worked or Logitech C615 == === this worked or Logitech C615 ==
Line 118: Line 92:
  
 If you used the -b  option, you will get your prompt back.  So how do you stop it from running? ​ After running the command, you will see a line like: If you used the -b  option, you will get your prompt back.  So how do you stop it from running? ​ After running the command, you will see a line like:
-forked to background (4979) +
-1+
   
 forked to background (4979) forked to background (4979)
Line 125: Line 98:
 If you want to stop the stream, just run: If you want to stop the stream, just run:
  
-kill 4979 
-1 
   
 kill 4979 kill 4979
Line 156: Line 127:
  
 The command would look like this: The command would look like this:
-/​usr/​local/​bin/​mjpg_streamer -i "/​usr/​local/​lib/​input_uvc.so"​ -o "/​usr/​local/​lib/​output_http.so -w /​usr/​local/​www -c username:​password"​ 
-1 
   
 /​usr/​local/​bin/​mjpg_streamer -i "/​usr/​local/​lib/​input_uvc.so"​ -o "/​usr/​local/​lib/​output_http.so -w /​usr/​local/​www -c username:​password"​ /​usr/​local/​bin/​mjpg_streamer -i "/​usr/​local/​lib/​input_uvc.so"​ -o "/​usr/​local/​lib/​output_http.so -w /​usr/​local/​www -c username:​password"​
Line 165: Line 134:
  
 For simplicity, just make the page in the same directory that is serving up the HTML files ( /​usr/​local/​www/ ​ in this walkthrough). ​ This makes it easier to make sure the page works. ​ After you know its working, you can move it somewhere else, but you will just need to adjust the paths. ​ Enter the following HTML code (adjusting to your setup) and it is ready to go. For simplicity, just make the page in the same directory that is serving up the HTML files ( /​usr/​local/​www/ ​ in this walkthrough). ​ This makes it easier to make sure the page works. ​ After you know its working, you can move it somewhere else, but you will just need to adjust the paths. ​ Enter the following HTML code (adjusting to your setup) and it is ready to go.
-<​html>​ <​head><​title>​Kitty-cam Live-stream</​title></​head>​ <​body>​ <​center><​h1>​Meow</​h1></​center>​ <​center>​ <img src="/?​action=stream"​ /> </​center>​ <​body>​ </​html>​ 
-1 
-2 
-3 
-4 
-5 
-6 
-7 
-8 
-9 
   
 <​html>​ <​html>​
Line 197: Line 156:
  
 There are two scripts below: a very basic one that just runs the command, and an advanced script that will allow you to use the service ​ command to control it: There are two scripts below: a very basic one that just runs the command, and an advanced script that will allow you to use the service ​ command to control it:
-sudo service livestream.sh start sudo service livestream.sh stop sudo service livestream.sh restart 
-1 
-2 
-3 
   
 sudo service livestream.sh start sudo service livestream.sh start
Line 209: Line 164:
  
 A very simple script to do this is below: A very simple script to do this is below:
-sudo vi /​etc/​init.d/​livestream.sh +
-1+
   
 sudo vi /​etc/​init.d/​livestream.sh sudo vi /​etc/​init.d/​livestream.sh
  
-#!/bin/bash /​usr/​local/​bin/​mjpg_streamer -i "/​usr/​local/​lib/​input_uvc.so"​ -o "/​usr/​local/​lib/​output_http.so -w /​usr/​local/​www -c username:​password"​ 
-1 
-2 
   
 #!/bin/bash #!/bin/bash
Line 222: Line 173:
  
 Save the script. ​ Make it executable: Save the script. ​ Make it executable:
-sudo chmod 755 /​usr/​sbin/​livestream.sh 
-1 
   
 sudo chmod 755 /​usr/​sbin/​livestream.sh sudo chmod 755 /​usr/​sbin/​livestream.sh
  
 This next command makes sure it is executed during boot: This next command makes sure it is executed during boot:
-sudo update-rc.d livestream.sh defaults 
-1 
   
 sudo update-rc.d livestream.sh defaults sudo update-rc.d livestream.sh defaults
  
 Advanced Script Advanced Script
- 
-Below is a script that should load MJPG-Streamer at boot and allow use of the service ​ command: 
-#!/bin/sh # /​etc/​init.d/​livestream.sh ### BEGIN INIT INFO # Provides: livestream.sh # 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 ### END INIT INFO f_message(){ echo "[+] $1" } # Carry out specific functions when asked to by the system case "​$1"​ in start) f_message "​Starting mjpg_streamer"​ /​usr/​local/​bin/​mjpg_streamer -b -i "/​usr/​local/​lib/​input_uvc.so"​ -o "/​usr/​local/​lib/​output_http.so -w /​usr/​local/​www -c username:​password"​ sleep 2 f_message "​mjpg_streamer started"​ ;; stop) f_message "​Stopping mjpg_streamer…"​ killall mjpg_streamer f_message "​mjpg_streamer stopped"​ ;; restart) f_message "​Restarting daemon: mjpg_streamer"​ killall mjpg_streamer /​usr/​local/​bin/​mjpg_streamer -b -i "/​usr/​local/​lib/​input_uvc.so"​ -o "/​usr/​local/​lib/​output_http.so -w /​usr/​local/​www -c username:​password"​ sleep 2 f_message "​Restarted daemon: mjpg_streamer"​ ;; status) pid=`ps -A | grep mjpg_streamer | grep -v "​grep"​ | grep -v mjpg_streamer. | awk ‘{print $1}’ | head -n 1` if [ -n "​$pid"​ ]; then 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 ""​ else f_message "Could not find mjpg_streamer running"​ fi ;; *) f_message "​Usage:​ $0 {start|stop|status|restart}"​ exit 1 ;; esac exit 0 
-1 
-2 
-3 
-4 
-5 
-6 
-7 
-8 
-9 
-10 
-11 
-12 
-13 
-14 
-15 
-16 
-17 
-18 
-19 
-20 
-21 
-22 
-23 
-24 
-25 
-26 
-27 
-28 
-29 
-30 
-31 
-32 
-33 
-34 
-35 
-36 
-37 
-38 
-39 
-40 
-41 
-42 
-43 
-44 
-45 
-46 
-47 
-48 
-49 
-50 
-51 
-52 
   
 #!/bin/sh #!/bin/sh
rpi_livestream.1428191241.txt.gz · Last modified: 2021/06/04 02:16 (external edit)