티스토리 뷰

OS/Banana Pi /BPI-Bit

BPI-M2 Berry mjpg-streamer

파란크리스마스 2017. 9. 1. 00:07
728x90

BPI-M2 Berry mjpg-streamer

출처 : 【BPI-M2+】之mjpg-streamer测试和体验- Bananap讨论区- 烽火社区 ...
MJPG-Streamer › Wiki › ubuntuusers.de
라즈베리파이에서 웹캠 mjpg-streamer 따라하기|작성자 서리
mjpg-streamer 웹캠 영상 스트리밍 | Mungrrr

관련 라이브러리 설치

$ sudo apt-get install libjpeg8-dev libv4l-dev subversion
$ sudo apt-get install imagemagick

mjpg-streamer 소스 다운로드

출처 : http://www.lavrsen.dk/svn/motion/tags/3.2.9/picture.c

$ svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer mjpg-streamer
$ cd mjpg-streamer

input_ov5640.so 컴파일 관련 내용 추가

input_ov5640.so 소스는 누락되어 있습니다.(참고용)

$ vi Makefile

Makefile 내용 일부

# define the name of the program
APP_BINARY = mjpg_streamer

# define the names and targets of the plugins
PLUGINS = input_ov5640.so              # bluexmas : 추가
PLUGINS += input_uvc.so

... 생략 ...

# bluexmas : 추가
ifeq ($(USE_LIBV4L2),true)
input_ov5640.so: mjpg_streamer.h utils.h
	make -C plugins/input_ov5640 USE_LIBV4L2=true all
	cp plugins/input_ov5640/input_ov5640.so .
else
input_ov5640.so: mjpg_streamer.h utils.h
	make -C plugins/input_ov5640 all
	cp plugins/input_ov5640/input_ov5640.so .
endif

ifeq ($(USE_LIBV4L2),true)
input_uvc.so: mjpg_streamer.h utils.h

... 생략 ...

# cleanup
clean:
	make -C plugins/input_ov5640 $@           # bluexmas : 추가
	make -C plugins/input_uvc $@

mjpg-streamer 컴파일 및 설치

$ make USE_LIBV4L2=true clean all
$ sudo make install
install --mode=755 mjpg_streamer /usr/local/bin
install --mode=644 input_ov5640.so input_uvc.so output_file.so output_udp.so output_http.so input_testpicture.so input_file.so /usr/local/lib/
install --mode=755 -d /usr/local/www
install --mode=644 -D www/* /usr/local/www

input_ov5640.so

input_ov5640.so.tgz

mjpg-streamer의 input_uvc.so는 YUV만 지원하고, BPI-M2 Berry의 카메라인 OV5640는 YUV420코덱만 지원하기 때문에, mjpg-streamer에서 사용 할 수 없습니다.

제가 작업한 OV5640의 YUV420코덱을 지원하는 so 파일을 공개 합니다.
BPI-M2 Berry의 카메라인 OV5640를 사용해서 mjpg-streamer로 스트리밍 하시려면 첨부한 파일을 사용하세요.

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 -i "input_ov5640.so -y -n" -o "output_http.so -w /usr/local/www"
MJPG Streamer Version: svn rev: 3:172M
 i: Using V4L2 device.: /dev/video0
 i: Desired Resolution: 640 x 480
 i: Frames Per Second.: 5
 i: Format............: YUV420
 i: JPEG Quality......: 80
 o: www-folder-path...: /usr/local/www/
 o: HTTP TCP port.....: 8080
 o: username:password.: disabled
 o: commands..........: enabled

서비스등록

$ sudo vi /etc/init.d/mjpg-streamer

mjpg-streamer 파일 내용

#!/bin/bash
# /etc/init.d/mjpg-streamer
# 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 fps=10
export SHUTDOWN_WAIT=2
export QUALITY=95

if [ -n "$2" ]; then
  width=$2 
fi

if [ -n "$3" ]; then
  height=$3
fi

if [ -n "$4" ]; then
  fps=$4
fi

export LD_MJPG_STREAMER=/usr/local/lib

f_message(){
        echo "[+] $1"
}

mjpg_streamer_pid() {
  echo `ps aux | grep mjpg_service | 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_ov5640.so -r "$width"x"$height" -f $fps -q $QUALITY -y" -o "$LD_MJPG_STREAMER/output_http.so -p 8080 -w /usr/local/www" mjpg_service
		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 }'`
                currfps=`ps axu | grep mjpg_streamer | grep -v grep | awk '{ print $18 }'`
                if [ -n "$resolution" ];
                then
                        echo "${resolution}"x"$currfps"
                else
                        echo "0x0x0"
                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
● mjpg-streamer.service - LSB: mjpg_streamer for webcam
   Loaded: loaded (/etc/init.d/mjpg-streamer; bad; vendor preset: enabled)
   Active: active (running) since Thu 2017-08-31 20:14:42 CST; 2min 28s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 5108 ExecStart=/etc/init.d/mjpg-streamer start (code=exited, status=0/SUCCESS)
   Memory: 1.0M
      CPU: 1min 18.585s
   CGroup: /system.slice/mjpg-streamer.service
           └─5117 mjpg_streamer -b -i /usr/local/lib/input_ov5640.so -r 640x480 -f 10 -q 95 -y -o /usr/local/lib/output_http.so -p 8080 -w /
 
Aug 31 20:14:40 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: Format............: YUV420
Aug 31 20:14:40 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: JPEG Quality......: 95
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: www-folder-path...: /usr/local/www/
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: HTTP TCP port.....: 8080
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: username:password.: disabled
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: commands..........: enabled
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: starting input plugin /usr/local/lib/input_ov5640.so
Aug 31 20:14:41 bpi-iot-ros-ai mjpg_streamer[5117]: MJPG-streamer [5117]: starting output plugin: /usr/local/lib/output_http.so (ID: 00)
Aug 31 20:14:42 bpi-iot-ros-ai mjpg-streamer[5108]: [+] mjpg_streamer started
Aug 31 20:14:42 bpi-iot-ros-ai systemd[1]: Started LSB: mjpg_streamer for webcam.
lines 1-20/20 (END)

실행

-b 옵션 백드라운드로 실행

$ mjpg_streamer -b -i "input_ov5640.so -r "640"x"480" -f 10 -q 75 -y" -o "output_http.so -p 8080 -w /usr/local/www"
enabling daemon modeforked to background (10942)

motion

출처 : mjpegtoyuv420p patch for Logitech Quickcam Pro

$ svn co http://www.lavrsen.dk/svn/motion/trunk motion
$ cd motion
$ ./configure
$ make
댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
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
글 보관함