openEuler-22.03-SP4离线编译安装ZLMediaKit
openEuler-22.03-SP4离线编译安装ZLMediaKit
使用OpenEuler22操作系统替换CentOS7,需要在离线状态编译安装ZLMediaKit,部署流媒体服务,特记录安装过程。
操作系统:openEuler-22.03-LTS-SP4-x86_64 openEuler-22.03-LTS-SP4-x86_64
1 准备安装环境
1.1 下载离线安装包
准备与目标机相同操作系统环境环境的备机(真机、虚拟机均可)
切记:备机上必须与目标机环境相同,切勿执行yum update 或者yum upgrade等操作,否则在目标机上安装时会导致大量的包需要升级。
在备机上安装必备软件
yum install -y tar
yum install -y git
yum install -y wget
在备机上下载离线包
mkdir -p /home/rpm/tools/net-tools
cd /home/rpm/tools/net-tools
dnf download --resolve net-tools
mkdir -p /home/rpm/tools/vim
cd /home/rpm/tools/vim
dnf download --resolve vim
mkdir -p /home/rpm/tools/tar
cd /home/rpm/tools/tar
dnf download --resolve tar
mkdir -p /home/rpm/tools/wget
cd /home/rpm/tools/wget
dnf download --resolve wget
mkdir -p /home/rpm/tools/git
cd /home/rpm/tools/git
dnf download --resolve git
mkdir -p /home/rpm/compile/gcc-c++
cd /home/rpm/compile/gcc-c++
dnf download --resolve gcc-c++
mkdir -p /home/rpm/compile/make
cd /home/rpm/compile/make
dnf download --resolve make
mkdir -p /home/rpm/compile/cmake
cd /home/rpm/compile/cmake
dnf download --resolve cmake
mkdir -p /home/rpm/compile/automake
cd /home/rpm/compile/automake
dnf download --resolve automake
mkdir -p /home/rpm/compile/pkgconfig
cd /home/rpm/compile/pkgconfig
dnf download --resolve pkgconfig
mkdir -p /home/rpm/compile/openssl-devel
cd /home/rpm/compile/openssl-devel
dnf download --resolve openssl-devel
mkdir -p /home/rpm/compile/libtool
cd /home/rpm/compile/libtool
dnf download --resolve libtool
mkdir -p /home/rpm/ZLMediaKit/freetype
cd /home/rpm/ZLMediaKit/freetype
dnf download --resolve freetype
dnf download --resolve freetype-devel
# -----NASM-----
mkdir -p /home/rpm/ZLMediaKit/nasm
cd /home/rpm/ZLMediaKit/nasm
wget https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.bz2
# -----Yasm-----
mkdir -p /home/rpm/ZLMediaKit/yasm
cd /home/rpm/ZLMediaKit/yasm
wget https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
# -----libx264---
cd /home/rpm/ZLMediaKit
git clone --branch stable --depth 1 https://code.videolan.org/videolan/x264.git
# -----libx265----
cd /home/rpm/ZLMediaKit
git clone --branch stable --depth 2 https://bitbucket.org/multicoreware/x265_git
# -----libfdk_aac-----
cd /home/rpm/ZLMediaKit
git clone --depth 1 https://github.com/mstorsjo/fdk-aac
# ------libmp3lame----
cd /home/rpm/ZLMediaKit
wget https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
# -----libopus--------
cd /home/rpm/ZLMediaKit
wget https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
# -----libvpx--------
cd /home/rpm/ZLMediaKit
git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
# -----ffmpeg--------
mkdir -p /home/rpm/ZLMediaKit/ffmpeg
cd /home/rpm/ZLMediaKit/ffmpeg
wget https://ffmpeg.org/releases/ffmpeg-7.1.tar.bz2
# -----ZLMediaKit--------
cd /home/rpm/ZLMediaKit
# 国内用户推荐从同步镜像网站gitee下载
git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
cd /home/rpm/ZLMediaKit/ZLMediaKit
# 千万不要忘记执行这句命令
git submodule update --init
cp /home/rpm/tools/tar/tar-1.34-5.oe2203sp4.x86_64.rpm /home/.
tar -zcvf rpm.tar.gz rpm/*
2 在目标机上安装
2.1 安装前的准备工作
- 关闭selinux
vi /etc/selinux/config
# 修改 SELINUX=enforcing 为 SELINUX=disabled
- 复制文件
cd /home
# 请更改IP地址为备机IP地址
scp root@192.168.43.163://home/*.rpm .
scp root@192.168.43.163://home/*.gz .
rpm -ivh --nosignature tar-1.34-5.oe2203sp4.x86_64.rpm
tar -zxvf rpm.tar.gz
- 安装通用软件及编译环境
# 安装net-tools
cd /home/rpm/tools/net-tools
rpm -ivh --nosignature *.rpm
# 安装vim
cd /home/rpm/tools/vim
rpm -ivh --nosignature *.rpm
# 安装git
cd /home/rpm/tools/git
rpm -ivh --nosignature *.rpm
#### 安装编译环境 ####
# 安装make
cd /home/rpm/compile/make
rpm -ivh --nosignature *.rpm
# 安装cmake
cd /home/rpm/compile/cmake
rpm -ivh --nosignature *.rpm
# 安装automake
cd /home/rpm/compile/automake
rpm -ivh --nosignature *.rpm
# 安装gcc-c++
cd /home/rpm/compile/gcc-c++
rpm -Uvh --nosignature *.rpm
# 安装glibc
cd /home/rpm/compile/glibc
rpm -Uvh --nosignature *.rpm
# 安装pkgconfig
cd /home/rpm/compile/pkgconfig
rpm -ivh --nosignature *.rpm
# 安装openssl-devel
cd /home/rpm/compile/openssl-devel
rpm -Uvh --nosignature *.rpm
# 安装libtool
cd /home/rpm/compile/libtool
rpm -ivh --nosignature libtool-2.4.7-2.oe2203sp4.x86_64.rpm
# 安装freetype
cd /home/rpm/ZLMediaKit/freetype
rpm -ivh --nosignature *.rpm
rpm -ivh --nosignature bzip2-devel-1.0.8-6.oe2203sp4.x86_64.rpm
rpm -ivh --nosignature libpng-devel-1.6.38-2.oe2203sp4.x86_64.rpm
rpm -ivh --nosignature freetype-devel-2.12.1-3.oe2203sp4.x86_64.rpm
2.2 安装编译ffmpeg所需依赖包
# -----NASM-----
cd /home/rpm/ZLMediaKit/nasm
tar xjvf nasm-2.15.05.tar.bz2
cd nasm-2.15.05
./autogen.sh
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install
# -----Yasm-----
cd /home/rpm/ZLMediaKit/yasm
tar xzvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install
# -----libx264---
cd /home/rpm/ZLMediaKit/x264
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make
make install
# -----libx265----
cd /home/rpm/ZLMediaKit/x265_git/build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make
make install
# -----libfdk_aac-----
cd /home/rpm/ZLMediaKit/fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
# ------libmp3lame----
cd /home/rpm/ZLMediaKit/
tar xzvf lame-3.100.tar.gz
cd lame-3.100
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm
make
make install
# -----libopus--------
cd /home/rpm/ZLMediaKit/
tar xzvf opus-1.3.1.tar.gz
cd opus-1.3.1
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
# -----libvpx--------
cd /home/rpm/ZLMediaKit/libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
make
make install
2.3 编译安装ffmpeg
#### FFmpeg ####
cd /home/rpm/ZLMediaKit/ffmpeg
tar xjvf ffmpeg-7.1.tar.bz2
cd /home/rpm/ZLMediaKit/ffmpeg/ffmpeg-7.1
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--extra-libs=-lpthread \
--extra-libs=-lm \
--bindir="$HOME/bin" \
--enable-gpl \
--enable-libfdk_aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-nonfree
make
make install
2.4 编译安装ZLMediaKit
- 编译安装
cd /home/rpm/ZLMediaKit/
tar -zxvf ZLMediaKit.tar.gz
cd /home/rpm/ZLMediaKit/ZLMediaKit
mkdir build
cd build
cmake ..
make -j4
mv /home/rpm/ZLMediaKit/ZLMediaKit/release/linux/Debug /home/ZLMediaKit
- 修改配置文件
vi /home/ZLMediaKit/config.ini
# 记录下secret,后续测试要用
secret=mFRurKYneR02MVRlVgtTyGZwTU9PDAst
# 修改[http]下
port=8090
sslport=8443
2.5 开放端口
firewall-cmd --zone=public --add-port=1935/tcp --permanent
firewall-cmd --zone=public --add-port=1935/udp --permanent
firewall-cmd --zone=public --add-port=554/tcp --permanent
firewall-cmd --zone=public --add-port=554/udp --permanent
firewall-cmd --zone=public --add-port=8443/tcp --permanent
firewall-cmd --zone=public --add-port=8090/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports
3 测试
3.1 手动启动命令
/home/ZLMediaKit/MediaServer -d &
3.2 设置ZLMediaKit开机自启动
vi /etc/systemd/system/zlmediakit.service
# 复制以下内容
[Unit]
Description=ZLMediaKit Background Service
After=network.target
[Service]
Type=simple
ExecStart=/home/ZLMediaKit/MediaServer
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
设置开机自启动
sudo systemctl daemon-reload
sudo systemctl enable zlmediakit
sudo systemctl start zlmediakit
3.3 ffmpeg推流
# 复制测试mp4文件
cp /home/rpm/ZLMediaKit/mov_bbb.mp4 /home/mov_bbb.mp4
# ffmpeg -re -stream_loop -1 -i "/home/mov_bbb.mp4" -vcodec h264 -f rtsp rtsp://127.0.0.1/live/test
ffmpeg -re -stream_loop -1 -i "/home/mov_bbb.mp4" -vcodec h264 -f flv rtmp://127.0.0.1/live/test
3.4 在VLC中测试
在VLC中“媒体”–“打开网络串流”中输入
rtsp://192.168.43.11/live/test
3.5 在网页中测试
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>H5播放m3u8格式视频</title>
<!-- 这个是videojs的CDN网站,测试时使用本地的video.js(请自行下载),所以注释掉以下几行 -->
<!-- https://www.bootcdn.cn/video.js/ -->
<!--<link href="https://cdn.bootcdn.net/ajax/libs/video.js/7.19.0/alt/video-js-cdn.css" rel="stylesheet">-->
<!--<script src="https://cdn.bootcdn.net/ajax/libs/video.js/7.19.0/alt/video.core.min.js"></script>-->
<!-- https://www.bootcdn.cn/videojs-contrib-hls/ -->
<!--<script src="https://cdn.bootcss.com/videojs-contrib-hls/5.15.0/videojs-contrib-hls.min.js"></script>-->
<link href="./js/video-js-cdn.css" rel="stylesheet">
<script src="./js/video.core.min.js" charset="utf-8"></script>
<script src="./js/videojs-contrib-hls.min.js"></script>
</head>
<body>
<video id="myVideo" class="video-js vjs-default-skin vjs-big-play-centered" controls preload="auto" width="1080" height="708" data-setup='{}'>
<source id="source" src="rtsp://192.168.43.60/live/test/hls.m3u8" type="application/x-mpegURL">
</video>
</body>
<script>
// videojs 简单使用示例
var myVideo = videojs('myVideo',{
bigPlayButton : true,
textTrackDisplay : false,
posterImage: false,
errorDisplay : false,
})
myVideo.play() // 视频播放
myVideo.pause() // 视频暂停
</script>
</html>
以上就是编译安装的完整步骤,如果所用操作系统与本文不同,请按照上述步骤执行即可。
本文所需资源已上传。资源文件