服务端安装
nginx源码
$ git clone https://github.com/nginx/nginx.git
nginx的rtmp模块源码
$ git clone https://github.com/arut/nginx-rtmp-module.git
nginx的依赖pcre源码
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar−xzvf pcre−8.39.tar.gz
cd nginx$ git checkout release-1.9.9
安装依赖的库
sudo
apt-get
install
openssl libssl-dev
将configure的命令封装成脚本
$ vim cfg.sh
cfg.sh文件的内容
auto/configure –prefix=/usr/local/nginx \
–with-pcre=../pcre-8.39 \
–with-http_ssl_module \
–with-http_v2_module \
–with-http_flv_module \
–with-http_mp4_module \
–add-module=../nginx-rtmp-module/
chmoda+xcfg.sh
./cfg.sh
make
make install
配置nginx
安装完成后,打开Nginx的配置文件nginx.conf进行配置
首先在里面加入rtmp的配置
Java代码
- rtmp {
- server {
- listen 1935;
- application myapp {
- live on;
- }
- application hls {
- live on;
- hls on;
- hls_path /tmp/hls;
- }
- }
- }
- 在nginx.conf的最后加上
然后,针对hls,还需要在http里面增加一个location配置
Java代码
- location /hls {
- types {
- application/vnd.apple.mpegurl m3u8;
- video/mp2t ts;
- }
- root /tmp;
- add_header Cache-Control no-cache;
- }
启动nginx
/usr/local/nginx/sbin/nginx
发现监听了1935,配置文件配置的端口
二:推流
方式1:用ffmpeg来模拟推流
ffmpeg -re -i film.mp4(视频文件) -c copy -f flv rtmp://服务器ip:1935/myapp/test1
方式2:在pc端用obs推流
三:拉流观看
用vlc
打开网络串流,输入rtmp://服务器ip:1935/myapp/test1,既可观看。