侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

nginx 搭建rtmp流媒体服务器

2023-11-26 星期日 / 0 评论 / 0 点赞 / 61 阅读 / 4863 字

本文是搭建nginx流媒体服务器过程的笔记,方便自己或者有相关需求的人员参考。 1. 下载PCRE 并安装. 主页地址:ftp://ftp.csx.cam.ac.uk/pub/software/p

本文是搭建nginx流媒体服务器过程的笔记,方便自己或者有相关需求的人员参考。

1. 下载PCRE 并安装. 

     主页地址: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

     ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz

2.  解压 tar -xzvf pcre-8.37.tar.gz

     cd pcre-8.37

     make, make install (if not the root user, please use the sudo)

3.  安装OpenSSL 

     sudo apt-get install libssl-dev

4.  下载nginx 和 nginx rtmp 模块

     http://nginx.org/download/nginx-1.10.0.tar.gz

     解压 tar -zxvf nginx-1.10.0.tar.gz

     https://github.com/arut/nginx-rtmp-module

     执行nginx 编译配置

      ./configure --add-module=/path/to/nginx-rtmp-module
      make
      make install

5.   启动nginx

      nginx 默认安装目录 /usr/local/nginx

      sbin 目录下nginx 服务器主程序, 启动 sudo ./nginx

6.   查看

     /usr/local/nginx/sbin$ ps -ef | grep nginx
        root      1394  1474  0 18:11 ?        00:00:00 nginx: master process ./nginx
        nobody    1395  1394  0 18:11 ?        00:00:00 nginx: worker process
         1570  1027  0 18:22 pts/32   00:00:00 grep --color=auto nginx

 

 

./configure --add-module=/www/soft/nginx-rtmp-module-master --without-http_rewrite_module --prefix=/usr/local/nginx

7.  在浏览器中输入 http://localhost/  , 可以看到nginx 的首页

       Welcome to nginx!
       If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
       For online documentation and support please refer to nginx.org. 
       Commercial support is available at nginx.com.
       Thank you for using nginx.

8. 添加rtmp 支持

       sudo vi conf/nginx.conf

rtmp {
     server {
         listen 1935;
chunk_size 4096;

         application live {
             live on;
             record off;
         }

 application vod {
      play /data/livefile/vod;  #点播媒体文件存放目录
    }

application hls {

        live on;

        hls on;

        hls_path /tmp/hls;

}


     }
 }

 

http {

 server {

 listen 8080;

 location /stat {

 rtmp_stat all;

 rtmp_stat_stylesheet stat.xsl;

}

 location /stat.xsl {

 root /opt/nginx-rtmp-module-master/;

}

 location / {

 root /opt/nginx-rtmp-module-master/test/rtmp-publisher;

}

  }

}

 

9, 重启 nginx

     sudo ./sbin/nginx -t

     sudo ./sbin/nginx -s reload

10. 添加测试源, 推流到服务器

      ffmpeg -re -i /data/livefile/test1.mp4 -c copy -f flv rtmp://192.168.0.128:1935/live

      或者直接采集屏幕

 ffmpeg -f x11grab -follow_mouse centered -r 25 -s cif -i :0.0 -f flv rtmp://192.168.0.128:1935/live

6、访问http://192.168.11.75:8080/stat,可以看到统计情况

 

11. 使用vlc在局域网机器上打开rtmp测试流

      rtmp://192.168.0:128:1935/live

截图:

附录:对于window 可以采用 OBS推流:

https://obsproject.com/

设置方法:

 

广告 广告

评论区