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

2024-02-2711:02:16服务器及运维Comments289 views字数 3017阅读模式

centos7服务器上搭建直播推流、拉流服务器,主要基于nginx-rtmp-module开源服务搭建而成。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

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

(1)解压 nginx-rtmp-module-1.2.1.tar.gz文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

(2)添加nginx module 模块文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

./configure --prefix=./bin  --add-module=../nginx-rtmp-module-1.2.1/
centos7服务器搭建 RTMP 直播推流拉流的方法

编译后出现以下结果表示编译成功文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

(3)make 安装文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

(4)查看是否安装成功文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

(5)配置nginx.config文件文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

nginx.conf配置文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

#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;
	}
	
}
}
 # Http 服务配置
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$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;
    # Http 服务配置
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
       # location / {
       #     root   /home/dist;
       #     index  index.html index.htm;
       # }
	 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;

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

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

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

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


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

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


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


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

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

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

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

#}

    # ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

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

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

【免费分享】音视频学习资料包、大厂面试题、技术视频和学习路线图,资料包括(C/C++,Linux,FFmpeg webRTC rtmp hls rtsp ffplay srs 等等)有需要的可以点击788280672加群免费领取~文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

(6)运行直播服务器文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

./bin/sbin/nginx
centos7服务器搭建 RTMP 直播推流拉流的方法

(7)访问链接地址文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

(8)推流

借助OBS Studio工具进行推流测试,配置推流地址。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

(9)拉流

借助LC media player工具进行拉流测试是否有直播画面。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

(10)手机端通过FFmpeg工具拉流显示文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

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

最后

下一步将实现通过手机端摄像头采集画面数据,将数据推流到服务器,其中涉及的知识点有rtmp、x264相关开源库.文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/61479.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/yunwei/61479.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定