MJPG简介:
MJPG是MJPEG的缩写,但是MJPEG还可以表示文件格式扩展名。
MJPEG全名为 “Motion Joint Photographic Experts Group”,是一种视频编码格式,Motion JPEG技术常用与闭合电路的电视摄像机的模拟视频信号“翻译”成视频流,并存储在硬盘上。典型的应用如数字视频记录器等。MJPEG不像MPEG,不使用帧间编码,因此用一个非线性编辑器就很容易编辑。MJPEG的压缩算法与MPEG一脉相承,功能很强大,能发送高质图片,生成完全动画视频等。但相应地,MJPEG对带宽的要求也很高,相当于T-1,MJPEG信息是存储在数字媒体中的庞然大物,需要大量的存储空间以满足如今多数用户的需求。因此从另一个角度说,在某些条件下,MJPEG也许是效率最低的编码/解码器之一。MJPEG 是 24-bit 的 “true-color” 影像标准,MJPEG 的工作是将 RGB 格式的影像转换成 YCrCB 格式,目的是为了减少档案大小,一般约可减少 1/3 ~ 1/2 左右。
MJPEG与MJPG的区别:
1、mjpeg是视频,就是由系列jpg图片组成的视频。
2、MJPG是MJPEG的缩写,但是MJPEG还可以表示文件格式扩展名。
一、软硬件环境
(一)硬件
1、HD-G2UL-EVM开发板(with ubuntu 20.04);
2、HIKVISION 720P USB摄像机;
(二)软件
HD-G2UL-EVM开发板系统已经更新至Ubuntu 20.04。
root@vanxoak:~~~# uname -a
Linux vanxoak 5.10.83-cip1-yocto-standard #1 SMP PREEMPT Tue Apr 5 23:00:00 UTC 2011 aarch64 aarch64 aarch64 GNU/Linux
root@vanxoak:~#~~
二、应用配置
(一)USB摄像头
USB摄像头插在HD-G2UL-EVM开发板上即可,需要检测摄像头挂载在哪个设备下,是video0(记住这个,后面有用)。
(二)网络环境
WLAN0连接WIFI即可。
(三)依赖软件安装
有了Ubuntu和SoC较为强大的处理能力,可以直接在HD-G2UL-EVM开发板上编译mjpg-streamer所需要的一些软件和库,主要包括cmake、subversion、imagemagick、libv4l、git等,直接apt install即可。
1、apt-get install subversion
root@vanxoak:~# apt-get install subversion
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libapr1 libaprutil1 libserf-1-1 libsvn1 libutf8proc2
Suggested packages:
db5.3-util libapache2-mod-svn subversion-tools
The following NEW packages will be installed:
libapr1 libaprutil1 libserf-1-1 libsvn1 libutf8proc2 subversion
0 upgraded, 6 newly installed, 0 to remove and 62 not upgraded.
Need to get 2211 kB of archives.
After this operation, 9854 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Fetched 2211 kB in 8s (261 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libapr1:arm64.
(Reading database ... 85595 files and directories currently installed.)
Setting up libutf8proc2:arm64 (2.5.0-1) ...
Setting up libapr1:arm64 (1.6.5-1ubuntu1) ...
Setting up libaprutil1:arm64 (1.6.1-4ubuntu2) ...
Setting up libserf-1-1:arm64 (1.3.9-8build1) ...
Setting up libsvn1:arm64 (1.13.0-3ubuntu0.2) ...
Setting up subversion (1.13.0-3ubuntu0.2) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
2、apt-get install libjpeg8-dev
root@vanxoak:# apt-get install imagemagick
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
gsfonts hicolor-icon-theme imagemagick-6-common imagemagick-6.q16
libdjvulibre-text libdjvulibre21 libfftw3-double3 libilmbase24 liblqr-1-0
libmagickcore-6.q16-6 libmagickcore-6.q16-6-extra libmagickwand-6.q16-6
libnetpbm10 libopenexr24 libwmf0.2-7 netpbm
Suggested packages:
imagemagick-doc autotrace cups-bsd | lpr | lprng curl enscript ffmpeg gimp
gnuplot grads groff-base hp2xx html2ps libwmf-bin mplayer povray radiance
sane-utils transfig ufraw-batch libfftw3-bin libfftw3-dev inkscape
libjxr-tools libwmf0.2-7-gtk
The following NEW packages will be installed:
gsfonts hicolor-icon-theme imagemagick imagemagick-6-common
imagemagick-6.q16 libdjvulibre-text libdjvulibre21 libfftw3-double3
libilmbase24 liblqr-1-0 libmagickcore-6.q16-6 libmagickcore-6.q16-6-extra
libmagickwand-6.q16-6 libnetpbm10 libopenexr24 libwmf0.2-7 netpbm
0 upgraded, 17 newly installed, 0 to remove and 62 not upgraded.
Need to get 8056 kB of archives.
After this operation, 25.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Fetched 8056 kB in 22s (370 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libfftw3-double3:arm64.
(Reading database ... 85735 files and directories currently installed.)
Setting up hicolor-icon-theme (0.17-2) ...
Setting up libwmf0.2-7:arm64 (0.2.8.4-17ubuntu1) ...
Setting up libnetpbm10 (2:10.0-15.3build1) ...
Setting up libilmbase24:arm64 (2.3.0-6build1) ...
Setting up libopenexr24:arm64 (2.3.0-6ubuntu0.5) ...
Setting up gsfonts (1:8.11+urwcyr1.0.7pre44-4.4) ...
Setting up netpbm (2:10.0-15.3build1) ...
Setting up libfftw3-double3:arm64 (3.3.8-2ubuntu1) ...
Setting up liblqr-1-0:arm64 (0.4.2-2.1) ...
Setting up libdjvulibre-text (3.5.27.1-14ubuntu0.1) ...
Setting up libdjvulibre21:arm64 (3.5.27.1-14ubuntu0.1) ...
Setting up libmagickcore-6.q16-6:arm64 (8:6.9.10.23+dfsg-2.1ubuntu11.4) ...
Setting up libmagickwand-6.q16-6:arm64 (8:6.9.10.23+dfsg-2.1ubuntu11.4) ...
Setting up libmagickcore-6.q16-6-extra:arm64 (8:6.9.10.23+dfsg-2.1ubuntu11.4) ...
Setting up imagemagick-6.q16 (8:6.9.10.23+dfsg-2.1ubuntu11.4) ...
Setting up imagemagick (8:6.9.10.23+dfsg-2.1ubuntu11.4) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
Processing triggers for fontconfig (2.13.1-2ubuntu3) ...
3、apt-get install imagemagick
root@vanxoak:~# apt-get install imagemagick
Reading package lists... Done
Building dependency tree
Reading state information... Done
imagemagick is already the newest version (8:6.9.10.23+dfsg-2.1ubuntu11.4).
0 upgraded, 0 newly installed, 0 to remove and 62 not upgraded.
4、apt-get install libv4l-dev
root@vanxoak:~# apt-get install libv4l-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
libv4l-dev
0 upgraded, 1 newly installed, 0 to remove and 62 not upgraded.
Need to get 104 kB of archives.
After this operation, 427 kB of additional disk space will be used.
Get:1 http:
Fetched 104 kB in 3s (40.3 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libv4l-dev:arm64.
(Reading database ... 87151 files and directories currently installed.)
Preparing to unpack .../libv4l-dev_1.18.0-2build1_arm64.deb ...
Unpacking libv4l-dev:arm64 (1.18.0-2build1) ...
Setting up libv4l-dev:arm64 (1.18.0-2build1) ...
5、apt-get install cmake
root@vanxoak:~# apt-get install cmake
Reading package lists... Done
Building dependency tree
Reading state information... Done
cmake is already the newest version (3.16.3-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 62 not upgraded.
6、apt-get install git
root@vanxoak:~~~# apt-get install git
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
gettext-base git-daemon-run | git-daemon-sysvinit git-doc git-el git-email
git-gui gitk gitweb git-cvs git-mediawiki git-svn
The following packages will be upgraded:
git
1 upgraded, 0 newly installed, 0 to remove and 61 not upgraded.
Need to get 4338 kB of archives.
After this operation, 4096 B of additional disk space will be used.
Get:1 http:
Fetched 4338 kB in 12s (360 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
(Reading database ... 87170 files and directories currently installed.)
Preparing to unpack .../git_1%3a2.25.1-1ubuntu3.6_arm64.deb ...
Unpacking git (1:2.25.1-1ubuntu3.6) over (1:2.25.1-1ubuntu3.5) ...
Setting up git (1:2.25.1-1ubuntu3.6) ...
root@vanxoak:~#~~
三、源码下载&编译&安装
考虑到直接在HD-G2UL-EVM开发板SoC较强的处理能力,座椅直接在板子上编译安装mjpg-streamer。
(一)源码下载
从全球最大交友网站下载好mjpg-streamer源码 ,如果很久没有响应,需要检测网络。
git clone https://github.com/jacksonliam/mjpg-streamer.git
(二)源码编译&安装
进入/mjpg-streamer/mjpg-streamer-experimental 文件夹,执行 make all。
之后继续make install 安装。
查看下,几个编译后的结果文件都在:
四、服务启动
直接输入 mjpg_streamer 即可启动服务,默认的是video0,HD-G2UL-EVM开发板的USB刚好是video0,无需要单独指定。在启动服务命令中通过“-d /dev/video0” 选项来指定。
y是表示YUV格式。如果没有-y,默认启动是mjpeg格式,这个就报错。改成YUV格式
-d指定设备
-f 制订帧数,默认30帧
-r指定视频大小,如320×240
-q指定画质,默认80对于输出参数:
-p 指定端口,一般是8080
-w 指定网页目录,设置的是/www目录
-c设置通过密码访问
最终启动服务命令如下:
./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -f 30 -q 90 -n" -o "./output_http.so -w ./www"
正常启动后的日志如下:
五、业务测试
(一)在线视频查看
打开浏览器,访问URL为:[HD-G2UL-EVM开发板 IP]:8080
,得到的内容如下:
(二)取一张图
取一张图的URL为 IP:8080?action=snapshot
这个功能对于后续图像的AI分析非常有用。
得益于ARM V8高性能架构,SoC在流畅处理图像业务时依旧保持极低的发热,用手摸也仅仅是一丁点的温,令人惊叹。
##感谢阅读##