前一篇介紹 Mjpg-Streamer 的安裝方法,只要重新開機後就必須輸入指令啟動軟體,如果要讓 Mjpg-Streamer 開機後自動啟動,請依據下面方法操作。
首先切換到安裝的資料夾,新增一個 Shell 檔案,要用當作 service 服務使用,只需要輸入以下指令:
cd ~/mjpg-streamer/ vi mjpg-streamer.sh
將以下內容貼到 mjpg-streamer.sh 檔案內,並且儲存檔案。
###BEGIN INIT INFO #Provides: mjpg_streamer.sh #Default-Start: 2 3 4 5 #Default-Stop: 0 1 6 #Short-Description: mjpg_streamer for webcam #Description: Streams /dev/video0 and /dev/video1 to http://IP/?action=stream ###END INIT INFO # Using the lsb functions to perform the operations. ./lib/lsb/init-functions # Process name ( For display ) NAME=mjpg_streamer.sh # Daemon name, where is the actual executable DAEMON=/home/pi/mjpg-streamer/mjpg-streamer-experimental/ # pid file for the daemon PIDFILE=/var/run/mjpg_streamer.pid # If the daemon is not there, then exit. test -x $DAEMON || exit 5 case $1 in start) echo "Starting mjpg_streamer" cd $DAEMON sudo ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www" & sleep 2 echo "mjpg_streamer started" ;; stop) echo "Stopping mjpg_streamer..." killall mjpg_streamer echo "mjpg_streamer stopped" ;; restart) $0 stop && sleep 2 && $0 start ;; status) pid=`ps -A | grep mjpg_streamer | grep -v "grep" | grep -v mjpg_streamer. | awk '{print $1}' | head -n 1` if [ -n "$pid" ]; then echo "mjpg_streamer is running with pid ${pid}" echo "mjpg_streamer was started with the following command line" cat /proc/${pid}/cmdline ; echo "" else echo "Could not find mjpg_streamer running" fi ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 2 ;; esac
檔案新增完成後,要測試檔案是否能正常運作,輸入以下指令:
sudo sh ./mjpg-streamer.sh start
打開瀏覽器,測試 Mjpg-Streamer 是否能正常運作,如果能正常運作就代表 Shell 檔案設定完成。
複製相關檔案到系統目錄,並且變更權限 和 設定成開機自動啟動,只需要輸入以下指令:
sudo cp mjpg-streamer.sh /etc/init.d/mjpg-streamer.sh sudo chmod +x /etc/init.d/mjpg-streamer.sh sudo update-rc.d mjpg-streamer.sh defaults
已經完成設定!
可以重新開機試試看,是否開機後會自動運作。
本文章網址:
https://www.ez2o.com/Blog/Post/OctoPrint-Raspberry-Pi-mjpg-streamer-AutoRun
https://www.ez2o.com/Blog/Post/508
https://www.ez2o.com/Blog/Post/OctoPrint-Raspberry-Pi-mjpg-streamer-AutoRun
https://www.ez2o.com/Blog/Post/508
留言
佩佩 ( 2019-11-27 )請問如果我的octporint上裝有兩個攝影機,要讓他們開啟octoprint時攝影機自動開啟,也是使用您說的設定嗎,因為現在的狀況是,如果重新開機兩個鏡頭的port會搶,使另一個需要使用樹莓派才能手動開啟。