티스토리 뷰
728x90
출처 : How to build and run MJPG-Streamer on the Raspberry Pi
라즈베리파이 파이카메라 활용강좌 : 웹 스트리밍(Mjpg-Stream)
fishkingsin/mjpg_streamer.sh
MJPG streamer 컴파일 관련 라이브러리 설치
$ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install cmake libjpeg8-dev imagemagick libv4l-dev
videodev2.h 헤더파일 링크
$ sudo ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h
MJPG streamer 소스 다운로드, 컴파일, 설치
$ echo "이전 git clone https://github.com/liamfraser/mjpg-streamer" $ git clone https://github.com/jacksonliam/mjpg-streamer.git $ cd mjpg-streamer/mjpg-streamer-experimental/ $ make $ sudo make install
LD_LIBRARY_PATH 경로 추가
$ echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib/mjpg-streamer" | sudo tee -a /etc/profile
MJPG Streamer 실행
출처 : MJPG Streamer configuration
$ mjpg_streamer -i "input_raspicam.so -x 640 -y 480 -fps 10 -rot 180 -ex night" --output "output_http.so -w /usr/local/share/mjpg-streamer/www --port 8080"
또는
$ mjpg_streamer -i "input_raspicam.so -x 320 -y 240 -quality 30 -fps 15 -rot 180 -ex night"
MJPG Streamer 실행 - 최적옵션
$ mjpg_streamer -i "input_uvc.so -r 320x240 -f 10 -y" --output "output_http.so -w /usr/local/share/mjpg-streamer/www --port 8080"
html 코드
출처 : mjpegcanvasjs / Tutorials / CreatingASingleStreamCanvas
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script type="text/javascript" src="eventemitter2.min.js"></script> <script type="text/javascript" src="mjpegcanvas.min.js"></script> <script type="text/javascript" type="text/javascript"> /** * Setup all visualization elements when the page is loaded. */ function init() { // Create the main viewer. var viewer = new MJPEGCANVAS.Viewer({ divID : 'mjpeg', host : '192.168.0.14', port : '8080', width : 640, height : 480, topic : '/?action=stream' }); } </script> </head> <body onload="init()"> <h1>Simple MJPEG Canvas Example</h1> <div id="mjpeg"></div> </body> </html>
V4L2(Video4Linux2) 부팅시 활성화 시키기
$ sudo vi /etc/modules
아래 내용 추가
bcm2835-v4l2
서비스등록
$ sudo vi /etc/init.d/mjpg_streamer
mjpg_streamer 파일 내용
#!/bin/bash # /etc/init.d/mjpg_streamer.sh # v0.2 phillips321.co.uk ### BEGIN INIT INFO # Provides: mjpg_streamer.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 # export width=640 export height=480 export bitrate=10 export SHUTDOWN_WAIT=2 if [ -n "$2" ]; then width=$2 fi if [ -n "$3" ]; then height=$3 fi if [ -n "$4" ]; then bitrate=$4 fi export LD_MJPG_STREAMER=/usr/local/lib/mjpg-streamer f_message(){ echo "[+] $1" } mjpg_streamer_pid() { echo `ps aux | grep mjpg-streamer | grep -v grep | awk '{ print $2 }'` } start() { pid=$(mjpg_streamer_pid) if [ -n "$pid" ] then echo "mjpg_streamer is already running (pid: $pid)" else # Start mjpg_streamer f_message "Starting mjpg_streamer" mjpg_streamer -b -i "$LD_MJPG_STREAMER/input_uvc.so -r "$width"x"$height" -f $bitrate -y" -o "$LD_MJPG_STREAMER/output_http.so -p 8080 -w /usr/local/share/mjpg-streamer/www" sleep 2 f_message "mjpg_streamer started" fi return 0 } stop() { pid=$(mjpg_streamer_pid) if [ -n "$pid" ] then f_message "Stopping mjpg_streamer..." kill -9 $pid let kwait=$SHUTDOWN_WAIT let count=0; until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ] do echo -n -e "\nwaiting for processes to exit"; sleep 1 let count=$count+1; done if [ $count -gt $kwait ]; then echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\n" kill -9 $pid fi else echo "mjpg_streamer is not running" fi return 0 } # Carry out specific functions when asked to by the system case "$1" in start) start ;; stop) stop ;; restart) stop sleep 2 start ;; resolution) resolution=`ps axu | grep mjpg-streamer | grep -v grep | awk '{ print $16 }'` if [ -n "$resolution" ]; then echo "${resolution}" else echo "0x0" fi ;; 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
등록
$ sudo chmod u+x /etc/init.d/mjpg_streamer $ sudo update-rc.d mjpg_streamer defaults
서비스 실행 및 실행 확인
$ sudo service mjpg_streamer start $ sudo service mjpg_streamer status [0m mjpg_streamer.service - LSB: mjpg_streamer for webcam Loaded: loaded (/etc/init.d/mjpg_streamer) Active: active (running) since Sat 2016-05-21 15:18:17 UTC; 8s ago Process: 1373 ExecStop=/etc/init.d/mjpg_streamer stop (code=killed, signal=TERM) Process: 1403 ExecStart=/etc/init.d/mjpg_streamer start (code=exited, status=0/SUCCESS) CGroup: /system.slice/mjpg_streamer.service 붴1407 mjpg_streamer -b -i /usr/local/lib/mjpg-streamer/input_uvc.so -r 320x240 -f 10 -y -o /usr/local/lib/mjpg-s... May 21 15:18:15 raspberrypi mjpg_streamer[1407]: MJPG-streamer [1407]: TV-Norm...........: DEFAULT May 21 15:18:15 raspberrypi mjpg_streamer[1403]: enabling daemon modeforked to background (1407) May 21 15:18:15 raspberrypi mjpg_streamer[1407]: MJPG-streamer [1407]: www-folder-path...: /usr/local/share/mjpg-streamer/www/ May 21 15:18:15 raspberrypi mjpg_streamer[1407]: MJPG-streamer [1407]: HTTP TCP port.....: 8080 May 21 15:18:15 raspberrypi mjpg_streamer[1407]: MJPG-streamer [1407]: username:password.: disabled May 21 15:18:15 raspberrypi mjpg_streamer[1407]: MJPG-streamer [1407]: commands..........: enabled May 21 15:18:15 raspberrypi mjpg_streamer[1407]: MJPG-streamer [1407]: starting input plugin /usr/local/lib/mjpg-stream...vc.so May 21 15:18:15 raspberrypi mjpg_streamer[1407]: MJPG-streamer [1407]: starting output plugin: /usr/local/lib/mjpg-stre...: 00) May 21 15:18:17 raspberrypi mjpg_streamer[1403]: [+] mjpg_streamer started May 21 15:18:17 raspberrypi systemd[1]: Started LSB: mjpg_streamer for webcam. Hint: Some lines were ellipsized, use -l to show in full.
댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- NDK
- oracle
- 동경
- JavaScript
- 튜닝쇼 2008
- Linux
- KOBA
- Delphi
- Mac
- 레이싱모델 익스트림 포토 페스티벌
- Delphi Tip
- sas2009
- android
- Spring
- ble
- Spring MVC
- BPI-M4
- 송주경
- 지스타2007
- ubuntu
- koba2010
- MySQL
- SAS
- 전예희
- Xcode
- Java
- 서울오토살롱
- flex
- ffmpeg
- 일본여행
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함