개발자/Raspberry Pi

라즈베리 파이 카메라 사용법과 mjpg 동영상 스트리밍 서버를 구현하기

지구빵집 2019. 10. 11. 10:53
반응형

 

라즈베리파이3 B+ 까지 테스트 완료! 잘 돌아간다.

 

라즈베리 파이 카메라 모듈은 라즈베리 파이를위한 부가 설계된 확장형 모듈이다. 보드의 상단 표면에 두 개의 작은 소켓 중 F-PCB 컨텍터를 통하여 라즈베리 파이에 연결된다.

 

이 인터페이스는 특히 카메라의 인터페이스를 위해 설계 되었고, 전용 CSI 인터페이스를 사용하고, CSI 버스는 매우 높은 데이터 속도로 동영상을 실시간으로 보는데도 지장이 없다. 보드 자체는 약 25mm X 20mm X 9mm이며 , 무게는 3g 이다. 카메라가 CSI 버스, 프로세서 카메라에서 픽셀 데이터를 전송하는 높은 대역폭 링크를 통해 파이의 BCM2835 프로세서에 연결되어 있다.

센서 자체는 5 메가 픽셀의 해상도를 가지고 있으며, 고정 초점 렌즈가 내장되어있다. 스틸 이미지의 측면에서, 카메라는 2592 X 1944 픽셀의 정적인 이미지까지 촬영이 가능하다.

 

 

 

 

 

라즈베리파이용 카메라 모듈 사양

 

 센서  OmniVision OV5647(8.5 x 8.5 x 5mm)
 pcb 크기  25 x 20 x 9 mm
 무게  3g
 해상도  5 Megapixels
 지원 비디오 모드  1080p30, 720p60 and 640x480p60/90
 영상/스팅 지원  정지영상 캡처 2592×1944
 초당 30프레임의 1080p 지원
 초당 60프레임의 720p 지원
 초당 90프레임의 640 x 480p 지원

 

라즈베리 카메라의 소프트웨어적 특성

 

Picture formats  JPEG (accelerated) , JPEG + RAW , GIF , BMP , PNG , YUV420 , RGB888
 Video formats  raw h.264 (accelerated)
 Effects  negative , solarise , posterize , whiteboard , blackboard , sketch , denoise , emboss , oilpaint , hatch , gpen , pastel , watercolour, film , blur , saturation
 Exposure modes  auto , night , nightpreview , backlight , spotlight , sports , snow , beach , verylong , fixedfps , antishake , fireworks
 Metering modes average, spot, backlit, matrix
 Automatic White Balance modes  off, auto , sun , cloud, shade, tungsten, fluorescent , incandescent , flash, horizon
 Triggers  Keypress , UNIX signal , timeout
 Extra modes  demo , timelapse , circular buffer , video with motion vectors , segmented video , live preview on 3D models

 

 

카메라 연결과 사용법 참고 : http://programmerchoo.tistory.com/81

 

아래내용 참고 사이트 : http://ww.rasplay.org/?p=7174 라즈베리파이 파이카메라 활용강좌 : 웹 스트리밍(Mjpg-Stream)

 

 

카메라 모듈을 사용하기 위해 라즈비안부터 업그레이드를 해야 한다. 터미널에서 다음 명령을 입력하여 업그레이드를 수행한다.

 

$sudo apt-get update

 

$sudo apt-get upgrade

 

 

위 명령을 한 번에 실행하려면 아래와 같이 입력한다.

 

$sudo apt-get update && upgrade

 

이제 라즈비안의 환경 설정 유틸리티를 열고 카메라를 사용하겠다고 해주면 모든 준비는 끝난것이다.

카메라의 설정값은 disable이 디폴트이다. 이를 enable로 바꾸면 다음 부팅때부터는 카메라가 사용가능해진다. Finish를 선택하면 라즈베리파이가 자동으로 재부팅된다. 환경 설정 유틸리티를 실행하는 명령은 다음과 같다.

 

$sudo raspi-config 

 

명령어를 입력하여 아랴와 같은 화면에서 카메라를 enable 한다.

 

 

 

카메라 모듈을 이용하여 mjpg-stream 을 구현한다. 속도가 많이 느린 편이지만 현장 상황을 웹을 이용하여 모니터링 하기에는 무리가 없다. 웹스트리밍 또는 기타 외부 기기에서 라즈베리 파이 카메라 모듈을 이용한 웹스트리밍 서비스를 하기 위해선 mjpg-stream 이 가장 최적화 되어 있다.

 

Mjpg-stream 컴파일을 위해 아래 영상관련 라이브러리 및 cmake 패키지를 설치 해 주도록 한다. 

 

$sudo apt-get install git cmake libjpeg8-dev imagemagick -y

 

아래 실행화면을 나타내었다.

 

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
pi@raspberrypi:~ $ sudo apt-get install git cmake libjpeg8-dev imagemagick -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
git is already the newest version.
git set to manually installed.
The following extra packages will be installed:
  cmake-data ghostscript imagemagick-6.q16 imagemagick-common libdjvulibre-text libdjvulibre21 libgs9 libgs9-common
  libijs-0.35 libjbig2dec0 libjsoncpp0 liblqr-1-0 libmagickcore-6.q16-2 libmagickcore-6.q16-2-extra
  libmagickwand-6.q16-2 libnetpbm10 libpaper-utils libpaper1 libwmf0.2-7 netpbm
Suggested packages:
  codeblocks eclipse ninja-build ghostscript-x imagemagick-doc autotrace enscript ffmpeg gimp gnuplot grads graphviz
  hp2xx html2ps libwmf-bin mplayer povray radiance sane-utils texlive-base-bin transfig ufraw-batch inkscape
The following NEW packages will be installed:
  cmake cmake-data ghostscript imagemagick imagemagick-6.q16 imagemagick-common libdjvulibre-text libdjvulibre21 libgs9
  libgs9-common libijs-0.35 libjbig2dec0 libjpeg8-dev libjsoncpp0 liblqr-1-0 libmagickcore-6.q16-2
  libmagickcore-6.q16-2-extra libmagickwand-6.q16-2 libnetpbm10 libpaper-utils libpaper1 libwmf0.2-7 netpbm
0 upgraded, 23 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.1 MB of archives.
After this operation, 46.2 MB of additional disk space will be used.
Get:1 http://archive.raspberrypi.org/debian/ jessie/main cmake-data all 3.6.2-2~bpo8+1 [1,168 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjsoncpp0 armhf 0.6.0~rc2-3.1 [61.1 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main imagemagick-common all 8:6.8.9.9-5+deb8u8 [152 kB]
Get:4 http://archive.raspberrypi.org/debian/ jessie/main cmake armhf 3.6.2-2~bpo8+1 [2,379 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main libdjvulibre-text all 3.5.25.4-4 [59.8 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main libdjvulibre21 armhf 3.5.25.4-4+b1 [471 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main libijs-0.35 armhf 0.35-10 [18.5 kB]
Get:8 http://mirrordirector.raspbian.org/raspbian/ jessie/main liblqr-1-0 armhf 0.4.2-2 [20.9 kB]
Get:9 http://mirrordirector.raspbian.org/raspbian/ jessie/main libmagickcore-6.q16-2 armhf 8:6.8.9.9-5+deb8u8 [1,528 kB]
Get:10 http://mirrordirector.raspbian.org/raspbian/ jessie/main libmagickwand-6.q16-2 armhf 8:6.8.9.9-5+deb8u8 [384 kB]
Get:11 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpaper1 armhf 1.1.24+nmu4 [21.4 kB]
Get:12 http://mirrordirector.raspbian.org/raspbian/ jessie/main libwmf0.2-7 armhf 0.2.8.4-10.3+deb8u2 [140 kB]
Get:13 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjbig2dec0 armhf 0.13-4~deb8u1 [51.5 kB]
Get:14 http://mirrordirector.raspbian.org/raspbian/ jessie/main libgs9-common all 9.06~dfsg-2+deb8u4 [1,979 kB]
Get:15 http://mirrordirector.raspbian.org/raspbian/ jessie/main libgs9 armhf 9.06~dfsg-2+deb8u4 [1,600 kB]
Get:16 http://mirrordirector.raspbian.org/raspbian/ jessie/main ghostscript armhf 9.06~dfsg-2+deb8u4 [83.7 kB]
Get:17 http://mirrordirector.raspbian.org/raspbian/ jessie/main imagemagick-6.q16 armhf 8:6.8.9.9-5+deb8u8 [510 kB]
Get:18 http://mirrordirector.raspbian.org/raspbian/ jessie/main imagemagick armhf 8:6.8.9.9-5+deb8u8 [157 kB]
Get:19 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjpeg8-dev armhf 8d1-2 [205 kB]
Get:20 http://mirrordirector.raspbian.org/raspbian/ jessie/main libmagickcore-6.q16-2-extra armhf 8:6.8.9.9-5+deb8u8 [167 kB]
Get:21 http://mirrordirector.raspbian.org/raspbian/ jessie/main libnetpbm10 armhf 2:10.0-15.2 [74.2 kB]
Get:22 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpaper-utils armhf 1.1.24+nmu4 [17.2 kB]
Get:23 http://mirrordirector.raspbian.org/raspbian/ jessie/main netpbm armhf 2:10.0-15.2 [886 kB]
Fetched 12.1 MB in 9s (1,240 kB/s)
Preconfiguring packages ...
Selecting previously unselected package cmake-data.
(Reading database ... 117056 files and directories currently installed.)
Preparing to unpack .../cmake-data_3.6.2-2~bpo8+1_all.deb ...
Unpacking cmake-data (3.6.2-2~bpo8+1) ...
Selecting previously unselected package libjsoncpp0.
Preparing to unpack .../libjsoncpp0_0.6.0~rc2-3.1_armhf.deb ...
Unpacking libjsoncpp0 (0.6.0~rc2-3.1) ...
Selecting previously unselected package cmake.
Preparing to unpack .../cmake_3.6.2-2~bpo8+1_armhf.deb ...
Unpacking cmake (3.6.2-2~bpo8+1) ...
Selecting previously unselected package imagemagick-common.
Preparing to unpack .../imagemagick-common_8%3a6.8.9.9-5+deb8u8_all.deb ...
Unpacking imagemagick-common (8:6.8.9.9-5+deb8u8) ...
Selecting previously unselected package libdjvulibre-text.
Preparing to unpack .../libdjvulibre-text_3.5.25.4-4_all.deb ...
Unpacking libdjvulibre-text (3.5.25.4-4) ...
Selecting previously unselected package libdjvulibre21:armhf.
Preparing to unpack .../libdjvulibre21_3.5.25.4-4+b1_armhf.deb ...
Unpacking libdjvulibre21:armhf (3.5.25.4-4+b1) ...
Selecting previously unselected package libijs-0.35:armhf.
Preparing to unpack .../libijs-0.35_0.35-10_armhf.deb ...
Unpacking libijs-0.35:armhf (0.35-10) ...
Selecting previously unselected package liblqr-1-0:armhf.
Preparing to unpack .../liblqr-1-0_0.4.2-2_armhf.deb ...
Unpacking liblqr-1-0:armhf (0.4.2-2) ...
Selecting previously unselected package libmagickcore-6.q16-2:armhf.
Preparing to unpack .../libmagickcore-6.q16-2_8%3a6.8.9.9-5+deb8u8_armhf.deb ...
Unpacking libmagickcore-6.q16-2:armhf (8:6.8.9.9-5+deb8u8) ...
Selecting previously unselected package libmagickwand-6.q16-2:armhf.
Preparing to unpack .../libmagickwand-6.q16-2_8%3a6.8.9.9-5+deb8u8_armhf.deb ...
Unpacking libmagickwand-6.q16-2:armhf (8:6.8.9.9-5+deb8u8) ...
Selecting previously unselected package libpaper1:armhf.
Preparing to unpack .../libpaper1_1.1.24+nmu4_armhf.deb ...
Unpacking libpaper1:armhf (1.1.24+nmu4) ...
Selecting previously unselected package libwmf0.2-7:armhf.
Preparing to unpack .../libwmf0.2-7_0.2.8.4-10.3+deb8u2_armhf.deb ...
Unpacking libwmf0.2-7:armhf (0.2.8.4-10.3+deb8u2) ...
Selecting previously unselected package libjbig2dec0.
Preparing to unpack .../libjbig2dec0_0.13-4~deb8u1_armhf.deb ...
Unpacking libjbig2dec0 (0.13-4~deb8u1) ...
Selecting previously unselected package libgs9-common.
Preparing to unpack .../libgs9-common_9.06~dfsg-2+deb8u4_all.deb ...
Unpacking libgs9-common (9.06~dfsg-2+deb8u4) ...
Selecting previously unselected package libgs9.
Preparing to unpack .../libgs9_9.06~dfsg-2+deb8u4_armhf.deb ...
Unpacking libgs9 (9.06~dfsg-2+deb8u4) ...
Selecting previously unselected package ghostscript.
Preparing to unpack .../ghostscript_9.06~dfsg-2+deb8u4_armhf.deb ...
Unpacking ghostscript (9.06~dfsg-2+deb8u4) ...
Selecting previously unselected package imagemagick-6.q16.
Preparing to unpack .../imagemagick-6.q16_8%3a6.8.9.9-5+deb8u8_armhf.deb ...
Unpacking imagemagick-6.q16 (8:6.8.9.9-5+deb8u8) ...
Selecting previously unselected package imagemagick.
Preparing to unpack .../imagemagick_8%3a6.8.9.9-5+deb8u8_armhf.deb ...
Unpacking imagemagick (8:6.8.9.9-5+deb8u8) ...
Selecting previously unselected package libjpeg8-dev:armhf.
Preparing to unpack .../libjpeg8-dev_8d1-2_armhf.deb ...
Unpacking libjpeg8-dev:armhf (8d1-2) ...
Selecting previously unselected package libmagickcore-6.q16-2-extra:armhf.
Preparing to unpack .../libmagickcore-6.q16-2-extra_8%3a6.8.9.9-5+deb8u8_armhf.deb ...
Unpacking libmagickcore-6.q16-2-extra:armhf (8:6.8.9.9-5+deb8u8) ...
Selecting previously unselected package libnetpbm10.
Preparing to unpack .../libnetpbm10_2%3a10.0-15.2_armhf.deb ...
Unpacking libnetpbm10 (2:10.0-15.2) ...
Selecting previously unselected package libpaper-utils.
Preparing to unpack .../libpaper-utils_1.1.24+nmu4_armhf.deb ...
Unpacking libpaper-utils (1.1.24+nmu4) ...
Selecting previously unselected package netpbm.
Preparing to unpack .../netpbm_2%3a10.0-15.2_armhf.deb ...
Unpacking netpbm (2:10.0-15.2) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for libgdk-pixbuf2.0-0:armhf (2.31.1-2+deb8u5) ...
Processing triggers for hicolor-icon-theme (0.13-1) ...
Processing triggers for gnome-menus (3.13.3-6) ...
Processing triggers for desktop-file-utils (0.22-1) ...
Processing triggers for mime-support (3.58) ...
Setting up cmake-data (3.6.2-2~bpo8+1) ...
Setting up libjsoncpp0 (0.6.0~rc2-3.1) ...
Setting up cmake (3.6.2-2~bpo8+1) ...
Setting up imagemagick-common (8:6.8.9.9-5+deb8u8) ...
Setting up libdjvulibre-text (3.5.25.4-4) ...
Setting up libdjvulibre21:armhf (3.5.25.4-4+b1) ...
Setting up libijs-0.35:armhf (0.35-10) ...
Setting up liblqr-1-0:armhf (0.4.2-2) ...
Setting up libmagickcore-6.q16-2:armhf (8:6.8.9.9-5+deb8u8) ...
Setting up libmagickwand-6.q16-2:armhf (8:6.8.9.9-5+deb8u8) ...
Setting up libpaper1:armhf (1.1.24+nmu4) ...
 
Creating config file /etc/papersize with new version
Setting up libwmf0.2-7:armhf (0.2.8.4-10.3+deb8u2) ...
Setting up libjbig2dec0 (0.13-4~deb8u1) ...
Setting up libgs9-common (9.06~dfsg-2+deb8u4) ...
Setting up libgs9 (9.06~dfsg-2+deb8u4) ...
Setting up ghostscript (9.06~dfsg-2+deb8u4) ...
Setting up imagemagick-6.q16 (8:6.8.9.9-5+deb8u8) ...
Setting up imagemagick (8:6.8.9.9-5+deb8u8) ...
update-alternatives: using /usr/bin/compare-im6 to provide /usr/bin/compare (compare) in auto mode
update-alternatives: using /usr/bin/animate-im6 to provide /usr/bin/animate (animate) in auto mode
update-alternatives: using /usr/bin/convert-im6 to provide /usr/bin/convert (convert) in auto mode
update-alternatives: using /usr/bin/composite-im6 to provide /usr/bin/composite (composite) in auto mode
update-alternatives: using /usr/bin/conjure-im6 to provide /usr/bin/conjure (conjure) in auto mode
update-alternatives: using /usr/bin/import-im6 to provide /usr/bin/import (import) in auto mode
update-alternatives: using /usr/bin/identify-im6 to provide /usr/bin/identify (identify) in auto mode
update-alternatives: using /usr/bin/stream-im6 to provide /usr/bin/stream (stream) in auto mode
update-alternatives: using /usr/bin/display-im6 to provide /usr/bin/display (display) in auto mode
update-alternatives: using /usr/bin/montage-im6 to provide /usr/bin/montage (montage) in auto mode
update-alternatives: using /usr/bin/mogrify-im6 to provide /usr/bin/mogrify (mogrify) in auto mode
Setting up libjpeg8-dev:armhf (8d1-2) ...
Setting up libmagickcore-6.q16-2-extra:armhf (8:6.8.9.9-5+deb8u8) ...
Setting up libnetpbm10 (2:10.0-15.2) ...
Setting up libpaper-utils (1.1.24+nmu4) ...
Setting up netpbm (2:10.0-15.2) ...
Processing triggers for libc-bin (2.19-18+deb8u7) ...
 
 
출처: https://fishpoint.tistory.com/1905 [기린]

 

videodev2.h 헤더파일 링크하는데 mjpg-streamer 를 컴파일 진행 시에는 요구하는 videodev.h 헤더파일을 변경된 videodev2.h 파일로 링크 하자.

 

$sudo ln -s  /usr/include/linux/videodev2.h  /usr/include/linux/videodev.h

 

mjpg-streamer 다운로드  및 컴파일 하기

 

$git clone https://github.com/liamfraser/mjpg-streamer

 

$cd ~/mjpg-streamer/mjpg-streamer-experimental

 

아래 다운로드 화면과 폴더를 이동한 화면을 나타낸다.

 

1
2
3
4
5
6
7
8
9
10
11
pi@raspberrypi:~ $ git clone https://github.com/liamfraser/mjpg-streamer
Cloning into 'mjpg-streamer'...
remote: Counting objects: 1997done.
remote: Total 1997 (delta 0), reused 0 (delta 0), pack-reused 1997
Receiving objects: 100% (1997/1997), 3.24 MiB | 1.79 MiB/s, done.
Resolving deltas: 100% (1222/1222), done.
Checking connectivity... done.
pi@raspberrypi:~ $
pi@raspberrypi:~ $ cd ~/mjpg-streamer/mjpg-streamer-experimental
pi@raspberrypi:~/mjpg-streamer/mjpg-streamer-experimental $
pi@raspberrypi:~/mjpg-streamer/mjpg-streamer-experimental $

 

이동한 폴더에서 $make clean all 명령으로 컴파일 한다.

 

pi@raspberrypi ~/mjpg-streamer/mjpg-streamer-experimental $ make clean all

 

폴더를 이동한 후 컴파일 화면을 나타낸다.

 

 

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
pi@raspberrypi:~/mjpg-streamer/mjpg-streamer-experimental $ make clean all
make: svnversion: Command not found
make -C plugins/input_uvc clean
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_uvc'
rm -*.a *.o core **.so *.lo
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_uvc'
make -C plugins/input_testpicture clean
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_testpicture'
rm -*.a *.o core **.so *.lo
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_testpicture'
make -C plugins/output_file clean
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_file'
rm -*.a *.o core **.so *.lo
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_file'
make -C plugins/output_http clean
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_http'
rm -*.a *.o core **.so *.lo
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_http'
make -C plugins/output_udp clean
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_udp'
rm -*.a *.o core **.so *.lo
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_udp'
make -C plugins/output_autofocus clean
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_autofocus'
rm -*.a *.o core **.so *.lo
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_autofocus'
make -C plugins/output_viewer clean
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_viewer'
rm -*.a *.o core **.so *.lo
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_viewer'
make -C plugins/output_rtsp clean
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_rtsp'
rm -*.a *.o core **.so *.lo
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_rtsp'
make -C plugins/input_http clean
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_http'
rm -*.a *.o core **.so *.lo
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_http'
rm -*.a *.o mjpg_streamer core **.so *.lo
rm --r plugins/input_raspicam/build/*
echo "This folder is where the plugin gets built" > plugins/input_raspicam/build/Readme.md
gcc -D'SVN_REV=""' -DLINUX -D_GNU_SOURCE -Wall  -g -Wuninitialized   -c -o mjpg_streamer.o mjpg_streamer.c
mjpg_streamer.c: In function ‘signal_handler’:
mjpg_streamer.c:95:12: warning: unused variable ‘j’ [-Wunused-variable]
     int i, j;
            ^
gcc -D'SVN_REV=""' -DLINUX -D_GNU_SOURCE -Wall  -g -Wuninitialized   -c -o utils.o utils.c
gcc -D'SVN_REV=""' -DLINUX -D_GNU_SOURCE -Wall  -g -Wuninitialized mjpg_streamer.o utils.o -lpthread -ldl -o mjpg_streamer
chmod 755 mjpg_streamer
make -C plugins/input_uvc all
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_uvc'
gcc -c -O1  -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC -o v4l2uvc.lo v4l2uvc.c
gcc -c -O1  -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC -o jpeg_utils.lo jpeg_utils.c
gcc -c -O1  -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC -o dynctrl.lo dynctrl.c
gcc -O1  -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC -o input_uvc.so input_uvc.c v4l2uvc.lo jpeg_utils.lo dynctrl.lo -ljpeg
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_uvc'
cp plugins/input_uvc/input_uvc.so .
make -C plugins/output_file all
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_file'
gcc -O2 -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC -DDEBUG -g -o output_file.so output_file.c
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_file'
cp plugins/output_file/output_file.so .
make -C plugins/output_http all
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_http'
gcc -c -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC -Wuninitialized -o httpd.lo httpd.c
gcc -DLINUX -D_GNU_SOURCE -Wall -shared -fPIC -Wuninitialized -o output_http.so output_http.c httpd.lo
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/output_http'
cp plugins/output_http/output_http.so .
cd plugins/input_raspicam/build; cmake ..
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/build
make -C plugins/input_raspicam/build
make[1]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/build'
make[2]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/build'
make[3]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/build'
Scanning dependencies of target input_raspicam
make[3]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/build'
make[3]: Entering directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/build'
[ 50%] Building C object CMakeFiles/input_raspicam.dir/input_raspicam.c.o
/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/input_raspicam.c: In function ‘worker_thread’:
/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/input_raspicam.c:722:9: warning: assignment makes pointer from integer without a cast
    pool = mmal_port_pool_create(encoder_output, encoder_output->buffer_num, encoder_output->buffer_size);
         ^
[100%] Linking C shared library libinput_raspicam.so
make[3]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/build'
[100%] Built target input_raspicam
make[2]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/build'
make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/plugins/input_raspicam/build'
cp plugins/input_raspicam/build/libinput_raspicam.so ./input_raspicam.so
pi@raspberrypi:~/mjpg-streamer/mjpg-streamer-experimental $
 
cs

 

앞의 과정들을 통해 mjpg-streamer 를 실행 할 수 있는 환경이 갖추어 졌으니, 마지막으로 파이 캠에서 mjpg-streamer 를 이용 할 수 있도록 자동 스크립트를 작성하고 명령어를 입력 해  웹 스트리밍을 구현 해 보자.

 

pi@raspberrypi ~ $sudo nano mjpg.sh

 

편집기를 열어 아래 세줄을 입력한다. 아래 문장을 그대로 카피하면 " 나 - 글자로 실행이 안될 수도 있으니 주의하자

 

export STREAMER_PATH=$HOME/mjpg-streamer/mjpg-streamer-experimental

export LD_LIBRARY_PATH=$STREAMER_PATH

$STREAMER_PATH/mjpg_streamer -i "input_raspicam.so -d 200" -o "output_http.so -w $STREAMER_PATH/www"  

 

CTRL-X 를 누르고 Y 누르고 Enter 저장하고 나온다.

 

스트리밍 서버 실행

 

$ pi@raspberrypi ~ $sh mjpg.sh

 

 

크롬에서 확인 주소 : http://라즈베리파이 아이피 :8080

 

 

**** USB 포트에 연결한 웹 카메라로 mjpg 스트리밍 구현하는 방법 

 

질문이 몇번 받았는데 이 기회에 정리합니다. 예전 문서에서 카피하여 설명합니다.

 

우선 참고 사이트 두 곳을 안내합니다.

 

#  참고 사이트

https://forum.openwrt.org/viewtopic.php?id=55607

-  https://www.raspberrypi.org/forums/viewtopic.php?t=109352

 

# 명령어 - 영상 설정 확인용

 

$uvcdynctrl –f –d /dev/video0
//지원하는 Pixel format, Frame size, Frame rates 확인


$v4l2-ctl -d /dev/video0 --list-formats-ext
//지원하는 Pixel format, Frame size, Frame rates 확인

 

# 영상 스트리밍 3줄 코드

 

// 수정 전 - 위에 나오는 코드입니다.

export STREAMER_PATH=/home/pi/mjpg-streamer/mjpg-streamer-experimental
export LD_LIBRARY_PATH=$STREAMER_PATH
$STREAMER_PATH/mjpg_streamer -i "input_raspicam.so -d 200" -o "output_http.so -w $STREAMER_PATH/www"


//수정 후 - 웹 카메라 사용시 사용

export STREAMER_PATH=/home/pi/mjpg-streamer/mjpg-streamer-experimental
export LD_LIBRARY_PATH=$STREAMER_PATH
$STREAMER_PATH/mjpg_streamer -i "input_uvc.so -d /dev/video0 -y -n -f 30"  -o "output_http.so -w $STREAMER_PATH/www"

//위 코드를 mjpg.sh 파일로 만들어 실행 * 입력시특수문자 입력에 주의

// -y : YUV Format
// -f : frame rate
// -i : Input
// -o : Output

//카메라의 스트리밍 서버가 너무 빠르다보니 프로세서가 감당을 못하는 것 같다. 
//화소 가 높거나 프레임이 빠르면 온습도 센서가 값을 읽지 못한다.

 

여기까지. 마지막 수정 2020/05/13

 

 

 

 

 

 

반응형