mjpg-streamer 是一个开源的网络视频流服务器,本文使用UVC摄像头在UBUNTU18.04上建立一个测试环境。
1.安装环境依赖库
sudo apt-get install subversion libv4l-dev libjpeg62-dev imagemagick cmake subversion
?2.编译并安装mjpeg-streamer源码,注意要切换到root模式编译,否则安装失败。
git clone https://github.com/vcsy1994/mjpg-streamer.git
cd mjpg-streamer
make clean && make all && make install
root@czl-RedmiBook-14:/home/czl/Workspace/mjpg-streamer# make clean && make all && make install
[ ! -f _build/Makefile ] || make -C _build clean
rm -f mjpg_streamer *.so
[ -d _build ] || mkdir _build
[ -f _build/Makefile ] || (cd _build && cmake -DCMAKE_BUILD_TYPE=Release ..)
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- 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
CMAKE_BUILD_TYPE = Release
-- Looking for include file sys/inotify.h
-- Looking for include file sys/inotify.h - found
CMake Warning at plugins/input_opencv/CMakeLists.txt:4 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Could NOT find GPHOTO2 (missing: GPHOTO2_LIBRARY GPHOTO2_INCLUDE_DIR)
-- Looking for include file linux/videodev2.h
-- Looking for include file linux/videodev2.h - found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR)
-- The following features have been enabled:
* PLUGIN_INPUT_FILE, File input plugin
* PLUGIN_INPUT_HTTP, HTTP input proxy plugin
* PLUGIN_INPUT_UVC, Video 4 Linux input plugin
* PLUGIN_OUTPUT_FILE, File output plugin
* PLUGIN_OUTPUT_HTTP, HTTP server output plugin
* PLUGIN_OUTPUT_RTSP, RTSP output plugin
* PLUGIN_OUTPUT_UDP, UDP output stream plugin
-- The following OPTIONAL packages have been found:
* Threads
-- The following features have been disabled:
* WXP_COMPAT, Enable compatibility with WebcamXP
* PLUGIN_INPUT_OPENCV, OpenCV input plugin (unmet dependencies)
* PLUGIN_INPUT_RASPICAM, Raspberry Pi input camera plugin (unmet dependencies)
* PLUGIN_INPUT_PTP2, PTP2 input plugin (unmet dependencies)
* ENABLE_HTTP_MANAGEMENT, Enable experimental HTTP management option
* PLUGIN_OUTPUT_VIEWER, SDL output viewer plugin (unmet dependencies)
-- The following OPTIONAL packages have not been found:
* OpenCV
* Gphoto2
* SDL
-- Configuring done
-- Generating done
-- Build files have been written to: /home/czl/Workspace/mjpg-streamer/_build
make -C _build
make[1]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[2]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
Scanning dependencies of target mjpg_streamer
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 4%] Building C object CMakeFiles/mjpg_streamer.dir/mjpg_streamer.c.o
[ 8%] Building C object CMakeFiles/mjpg_streamer.dir/utils.c.o
[ 13%] Linking C executable mjpg_streamer
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 13%] Built target mjpg_streamer
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
Scanning dependencies of target input_file
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 17%] Building C object plugins/input_file/CMakeFiles/input_file.dir/input_file.c.o
[ 21%] Linking C shared library input_file.so
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 21%] Built target input_file
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
Scanning dependencies of target input_http
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 26%] Building C object plugins/input_http/CMakeFiles/input_http.dir/input_http.c.o
[ 30%] Building C object plugins/input_http/CMakeFiles/input_http.dir/misc.c.o
[ 34%] Building C object plugins/input_http/CMakeFiles/input_http.dir/mjpg-proxy.c.o
[ 39%] Linking C shared library input_http.so
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 39%] Built target input_http
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
Scanning dependencies of target input_uvc
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 43%] Building C object plugins/input_uvc/CMakeFiles/input_uvc.dir/dynctrl.c.o
[ 47%] Building C object plugins/input_uvc/CMakeFiles/input_uvc.dir/input_uvc.c.o
[ 52%] Building C object plugins/input_uvc/CMakeFiles/input_uvc.dir/jpeg_utils.c.o
[ 56%] Building C object plugins/input_uvc/CMakeFiles/input_uvc.dir/v4l2uvc.c.o
[ 60%] Linking C shared library input_uvc.so
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 60%] Built target input_uvc
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
Scanning dependencies of target output_file
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 65%] Building C object plugins/output_file/CMakeFiles/output_file.dir/output_file.c.o
/home/czl/Workspace/mjpg-streamer/plugins/output_file/output_file.c: In function ‘worker_thread’:
/home/czl/Workspace/mjpg-streamer/plugins/output_file/output_file.c:292:17: warning: ignoring return value of ‘link’, declared with attribute warn_unused_result [-Wunused-result]
(void) link(buffer2, buffer1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 69%] Linking C shared library output_file.so
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 69%] Built target output_file
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
Scanning dependencies of target output_http
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 73%] Building C object plugins/output_http/CMakeFiles/output_http.dir/httpd.c.o
/home/czl/Workspace/mjpg-streamer/plugins/output_http/httpd.c: In function ‘send_input_JSON’:
/home/czl/Workspace/mjpg-streamer/plugins/output_http/httpd.c:1731:38: warning: ‘%d’ directive writing between 1 and 10 bytes into a region of size 6 [-Wformat-overflow=]
sprintf(buffer_num, "%d", j);
^~
/home/czl/Workspace/mjpg-streamer/plugins/output_http/httpd.c:1731:37: note: directive argument in the range [0, 2147483647]
sprintf(buffer_num, "%d", j);
^~~~
In file included from /usr/include/stdio.h:862:0,
from /home/czl/Workspace/mjpg-streamer/plugins/output_http/httpd.c:28:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33:10: note: ‘__builtin___sprintf_chk’ output between 2 and 11 bytes into a destination of size 6
return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 78%] Building C object plugins/output_http/CMakeFiles/output_http.dir/output_http.c.o
[ 82%] Linking C shared library output_http.so
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 82%] Built target output_http
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
Scanning dependencies of target output_rtsp
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 86%] Building C object plugins/output_rtsp/CMakeFiles/output_rtsp.dir/output_rtsp.c.o
[ 91%] Linking C shared library output_rtsp.so
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 91%] Built target output_rtsp
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
Scanning dependencies of target output_udp
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 95%] Building C object plugins/output_udp/CMakeFiles/output_udp.dir/output_udp.c.o
[100%] Linking C shared library output_udp.so
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[100%] Built target output_udp
make[2]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
make[1]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
make -C _build install
make[1]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[2]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 13%] Built target mjpg_streamer
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 21%] Built target input_file
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 39%] Built target input_http
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 60%] Built target input_uvc
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 69%] Built target output_file
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 82%] Built target output_http
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[ 91%] Built target output_rtsp
make[3]: Entering directory '/home/czl/Workspace/mjpg-streamer/_build'
make[3]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
[100%] Built target output_udp
make[2]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/bin/mjpg_streamer
-- Set runtime path of "/usr/local/bin/mjpg_streamer" to "/usr/local/lib/mjpg-streamer"
-- Installing: /usr/local/share/mjpg-streamer/www
-- Installing: /usr/local/share/mjpg-streamer/www/favicon.ico
-- Installing: /usr/local/share/mjpg-streamer/www/java.html
-- Installing: /usr/local/share/mjpg-streamer/www/fix.css
-- Installing: /usr/local/share/mjpg-streamer/www/LICENSE.txt
-- Installing: /usr/local/share/mjpg-streamer/www/jquery.rotate.js
-- Installing: /usr/local/share/mjpg-streamer/www/JQuerySpinBtn.css
-- Installing: /usr/local/share/mjpg-streamer/www/JQuerySpinBtn.js
-- Installing: /usr/local/share/mjpg-streamer/www/control.htm
-- Installing: /usr/local/share/mjpg-streamer/www/functions.js
-- Installing: /usr/local/share/mjpg-streamer/www/static_simple.html
-- Installing: /usr/local/share/mjpg-streamer/www/jquery.ui.custom.css
-- Installing: /usr/local/share/mjpg-streamer/www/spinbtn_updn.gif
-- Installing: /usr/local/share/mjpg-streamer/www/stream_simple.html
-- Installing: /usr/local/share/mjpg-streamer/www/jquery.js
-- Installing: /usr/local/share/mjpg-streamer/www/jquery.ui.tabs.min.js
-- Installing: /usr/local/share/mjpg-streamer/www/jquery.ui.widget.min.js
-- Installing: /usr/local/share/mjpg-streamer/www/static.html
-- Installing: /usr/local/share/mjpg-streamer/www/bodybg.gif
-- Installing: /usr/local/share/mjpg-streamer/www/stream.html
-- Installing: /usr/local/share/mjpg-streamer/www/jquery.ui.core.min.js
-- Installing: /usr/local/share/mjpg-streamer/www/example.jpg
-- Installing: /usr/local/share/mjpg-streamer/www/style.css
-- Installing: /usr/local/share/mjpg-streamer/www/cambozola.jar
-- Installing: /usr/local/share/mjpg-streamer/www/javascript_motiondetection.html
-- Installing: /usr/local/share/mjpg-streamer/www/java_control.html
-- Installing: /usr/local/share/mjpg-streamer/www/javascript.html
-- Installing: /usr/local/share/mjpg-streamer/www/java_simple.html
-- Installing: /usr/local/share/mjpg-streamer/www/videolan.html
-- Installing: /usr/local/share/mjpg-streamer/www/favicon.png
-- Installing: /usr/local/share/mjpg-streamer/www/sidebarbg.gif
-- Installing: /usr/local/share/mjpg-streamer/www/javascript_simple.html
-- Installing: /usr/local/share/mjpg-streamer/www/index.html
-- Installing: /usr/local/share/mjpg-streamer/www/rotateicons.png
-- Installing: /usr/local/lib/mjpg-streamer/input_file.so
-- Installing: /usr/local/lib/mjpg-streamer/input_http.so
-- Installing: /usr/local/lib/mjpg-streamer/input_uvc.so
-- Installing: /usr/local/lib/mjpg-streamer/output_file.so
-- Installing: /usr/local/lib/mjpg-streamer/output_http.so
-- Installing: /usr/local/lib/mjpg-streamer/output_rtsp.so
-- Installing: /usr/local/lib/mjpg-streamer/output_udp.so
make[1]: Leaving directory '/home/czl/Workspace/mjpg-streamer/_build'
root@czl-RedmiBook-14:/home/czl/Workspace/mjpg-streamer#
3.启动mjpeg_streamer并且启动http服务器。
mjpeg_streamer启动后内部会继续启动一个http server,用来响应客户端连接.
./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -u -f 30" -o "./output_http.so -w ./www"
?4.在浏览器中测试,浏览器中输入以下网址,可以直接打开远程UVC摄像头.查看MJPEG 数据。
http://127.0.0.1:8080/
或者输入如下URL,直接看视频:
http://127.0.0.1:8080/?action=stream
结束!
|