Nginx+ffmpeg离线部署实现RTSP转HLS
简介
离线环境安装编译nginx和ffmpeg实现rtsp转hls
先从在线环境获取相关安装包后,复制到离线环境安装
1.安装make等命令
apt-get install --print-uris -y gcc automake autoconf libtool make | grep 'http' | cut -d' ' -f1 | tr -d "'" > download_list.txt
编辑脚本
#!/bin/bash
while IFS= read -r line; do
wget $line
done < download_list.txt
chmod +x download_packages.sh
./download_packages.sh
将下载后的包放入某个文件夹下,如deb_make
复制到离线服务器执行
dpkg -i *.deb
2.安装nginx相关依赖
apt-get install --print-uris -y libpcre3-dev openssl libssl-dev zlib1g-dev | grep 'http' | cut -d' ' -f1 | tr -d "'" > download_list.txt
获取deb包的方式同上
将下载后的包放入某个文件夹下,如deb_nginx_dev
复制到离线服务器执行
dpkg -i *.deb
3.将相关安装包复制到离线服务器
mkdir ~/module
cd ~/module
复制deb包如下:
ffmpeg-4.1.11.tar.xz
nginx-1.21.6.tar.gz
nginx-rtmp-module-master.tar.gz
yasm-1.3.0.tar.gz
4.安装nginx
tar -xzvf nginx-rtmp-module-master.tar.gz
tar -xzvf nginx-1.21.6.tar.gz
cd nginx-1.21.6.tar.gz
./configure --prefix=/opt/nginx-1.21.6 --with-http_stub_status_module --add-module=/root/module/nginx-rtmp-module-master --with-http_ssl_module
make
make install
5.修改nginx配置
5.1 rtsp转rtmp配置
vi /opt/nginx-1.21.6/conf/nginx.conf
rtmp {
# 转流服务,可以存在多个,每个服务端口要不同
server {
listen 1935;
application myapp{ #应用名,可以存在多个
live on;
record off;
allow play all;
}
}
}
5.2 rtsp转hls配置
server {
listen 8002;
server_name server_hls;
location / {
types {
application/vnd.apple.mpegusr m3u8;
video/mp2t ts;
}
root hls; #8002端口服务的根目录,nginx目录下的hls目录
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
add_header Access-Control-Methods "GET, POST, OPTIONS";
}
}
6.启动nginx
/opt/nginx-1.21.6/sbin/nginx
/opt/nginx-1.21.6/sbin/nginx -s stop
7.安装ffmpeg
7.1 安装yasm
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make && make install
7.2 编译ffmpeg
tar -xvf ffmpeg-4.1.11.tar.xz
cd ffmpeg-4.1.11
./configure --prefix=/usr/local/ffmpeg
make
make install
7.3 拷贝命令到/usr/bin
ls /usr/local/ffmpeg/
cp /usr/local/ffmpeg/bin/* /usr/bin/
ffmpeg -version
8.测试
cd /opt/nginx-1.21.6
mkdir hls
ffmpeg -f rtsp -rtsp_transport tcp -i rtsp://rtspstream:444183dc07a234d39a87b5574a718f73@zephyr.rtsp.stream/movie -codec copy -f hls -hls_list_size 10 -hls_wrap 20 -hls_time 15 /opt/nginx-1.21.6/hls/test.m3u8
http://192.168.0.1:8002/test.m3u8
Nginx+ffmpeg离线部署实现RTSP转HLS
http://example.com/2024/01/15/nginx-ffmpeg-offline-rtsp2hls/