centos7服务器搭建 RTMP 直播推流拉流的方法

centos7服务器上搭建直播推流、拉流服务器,主要基于nginx-rtmp-module开源服务搭建而成。

1.下载nginx直播服务器模块地址

https://github.com/arut/nginx-rtmp-module/releases/tag/v1.2.1

(1)解压 nginx-rtmp-module-1.2.1.tar.gz

tar -xvf  nginx-rtmp-module-1.2.1.tar.gz

(2)添加nginx module 模块

./configure --prefix=./bin  --add-module=../nginx-rtmp-module-1.2.1/

centos7服务器搭建 RTMP 直播推流拉流的方法-每日运维

编译后出现以下结果表示编译成功centos7服务器搭建 RTMP 直播推流拉流的方法

(3)make 安装

make && make install

centos7服务器搭建 RTMP 直播推流拉流的方法

(4)查看是否安装成功centos7服务器搭建 RTMP 直播推流拉流的方法

(5)配置nginx.config文件centos7服务器搭建 RTMP 直播推流拉流的方法

nginx.conf配置

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}
rtmp {
  server {
    listen 1935;
    #直播流地址,也能指定房间号
    application myapp {
    live on;
        #丢弃连接超过5s的连接
        drop_idle_publisher 5s;
    }

}
}
 1. Http 服务配置
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    1.                  '$status $body_bytes_sent "$http_referer" '
    1.                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    1. Http 服务配置
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
       1. location / {
       1.     root   /home/dist;
       1.     index  index.html index.htm;
       1. }
     location /stat {
     rtmp_stat all;
     rtmp_stat_stylesheet stat.xsl;     

    }
    location /stat.xsl {
    root /home/nginx-rtmp-module-1.2.1/;
    }

    location /control {
      rtmp_control all;
    }

    location rtmp-publisher {
      root /home/nginx-rtmp-module-1.2.1/test;

    }
    location / {
    root /home/nginx-rtmp-module-1.2.1/test/www;

}

        #error_page  404              /404.html;

        1. redirect server error pages to the static page /50x.html
        1.         error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        1. proxy the PHP scripts to Apache listening on 127.0.0.1:80
        1.         #location ~ .php$ {
        1.    proxy_pass   http://127.0.0.1;
        #}

        1. pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        1.         #location ~ .php$ {
        1.    root           html;
        1.    fastcgi_pass   127.0.0.1:9000;
        1.    fastcgi_index  index.php;
        1.    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        1.    include        fastcgi_params;
        #}

        1. deny access to .htaccess files, if Apache's document root
        1. concurs with nginx's one
        1.         #location ~ /.ht {
        1.    deny  all;
        #}
    }

    1. another virtual host using mix of IP-, name-, and port-based configuration
    1.     #server {
    1.    listen       8000;
    1.    listen       somename:8080;
    1.    server_name  somename  alias  another.alias;

    1.    location / {
    1.        root   html;
    1.        index  index.html index.htm;
    1.    }
    #}

    1. HTTPS server
    1.     #server {
    1.    listen       443 ssl;
    1.    server_name  localhost;
    1.    location / {
    1.        root   html;
    1.        index  index.html index.htm;
    1.    }
    #}

    1. HTTPS server
    1.     #server {
    1.    listen       443 ssl;
    1.    server_name  localhost;

    1.    ssl_certificate      cert.pem;
    1.    ssl_certificate_key  cert.key;

    1.    ssl_session_cache    shared:SSL:1m;
    1.    ssl_session_timeout  5m;

    1.    ssl_ciphers  HIGH:!aNULL:!MD5;
    1.    ssl_prefer_server_ciphers  on;

    1.    location / {
    1.        root   html;
    1.        index  index.html index.htm;
    1.    }
    #}

#}

    1. ssl_certificate      cert.pem;
    1.    ssl_certificate_key  cert.key;

    1.    ssl_session_cache    shared:SSL:1m;
    1.    ssl_session_timeout  5m;

    1.    ssl_ciphers  HIGH:!aNULL:!MD5;
    1.    ssl_prefer_server_ciphers  on;

    1.    location / {
    1.        root   html;
    1.        index  index.html index.htm;
    1.    }
    #}

}

【免费分享】音视频学习资料包、大厂面试题、技术视频和学习路线图,资料包括(C/C++,Linux,FFmpeg webRTC rtmp hls rtsp ffplay srs 等等)有需要的可以点击788280672加群免费领取~centos7服务器搭建 RTMP 直播推流拉流的方法

(6)运行直播服务器

./bin/sbin/nginx

centos7服务器搭建 RTMP 直播推流拉流的方法

(7)访问链接地址centos7服务器搭建 RTMP 直播推流拉流的方法

(8)推流

借助OBS Studio工具进行推流测试,配置推流地址。centos7服务器搭建 RTMP 直播推流拉流的方法-2

(9)拉流

借助LC media player工具进行拉流测试是否有直播画面。centos7服务器搭建 RTMP 直播推流拉流的方法centos7服务器搭建 RTMP 直播推流拉流的方法

(10)手机端通过FFmpeg工具拉流显示centos7服务器搭建 RTMP 直播推流拉流的方法

最后

下一步将实现通过手机端摄像头采集画面数据,将数据推流到服务器,其中涉及的知识点有rtmp、x264相关开源库.