目录
下载nginx-rtmp-module
原生的Nginx并不支持RTMP,需要安装第三方模块nginx-rtmp-module插件使其支持RTMP。
git clone https://github.com/arut/nginx-rtmp-module.git
安装Nginx
下载Nginx
wget http://nginx.org/download/nginx-1.20.0.tar.gz
解压
tar -xzf nginx-1.20.0.tar.gz
修改name文件
vim auto/cc/name
修改为下面内容。
修改sizeof文件
vim auto/types/sizeof
修改为下面内容。
配置
--prefix和--add-module的路径根据自己的实际情况进行修改。
./configure --prefix=/home/orangepi/Nginx/nginx-1.20.0/install \
--with-http_ssl_module \
--with-http_mp4_module \
--with-http_v2_module \
--without-http_upstream_zone_module \
--add-module=/home/orangepi/Nginx/nginx-rtmp-module
修改ngx_auto_config.h文件
vim objs/ngx_auto_config.h
添加下面内容。
#ifndef NGX_HAVE_SYSVSHM
#define NGX_HAVE_SYSVSHM 1
#endif
编译
make
安装
make install
新建nginx目录。
sudo mkdir nginx
将conf、logs、html目录拷贝到新建的/etc/nginx目录下。
sudo cp -r conf html logs /etc/nginx/
重启开发板。
测试nginx
查看版本信息
./nginx -V
查看帮助信息
./nginx -h
启动nginx
sudo ./nginx -p /etc/nginx
查看运行
ps -aux
配置nginx
修改nginx.conf文件
sudo vim /etc/nginx/conf/nginx.conf
添加下面内容。
rtmp {
server {
listen 1935; # 监听 1935 端口
chunk_size 4096;
application live{
allow publish 127.0.0.1;
allow play all;
live on; # 打开直播
record off; # 关闭 record
meta copy;
}
application hls {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 8s;
}
}
}
重启nginx
sudo ./nginx -p /etc/nginx -s reload
下载FFmpeg
需要使用FFmpeg进行推流。
sudo apt-get install ffmpeg
推视频文件流
ffmpeg -re -i ./test.mp4 -vcodec libx264 -acodec copy -f flv rtmp://127.0.0.1/live/mytest
推实时视频流
ffmpeg -r 10 -video_size 1280x720 -framerate 15 -i /dev/video0 -q 10 -max_delay 100 -g 5 -b 700000 -f flv rtmp://127.0.0.1/live/mytest
向云服务器推视频流
在云服务器需搭建好Nginx,过程跟上面一样。
ffmpeg -r 10 -video_size 1280x720 -framerate 15 -i /dev/video0 -q 10 -max_delay 100 -g 5 -b 700000 -f flv rtmp://云服务器IP地址/live/mytest
拉流
使用VLC进行拉流。