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/
编译后出现以下结果表示编译成功
(3)make 安装
make && make install
(4)查看是否安装成功
(5)配置nginx.config文件
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;
}
}
}
# 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加群免费领取~
(6)运行直播服务器
./bin/sbin/nginx
(7)访问链接地址
(8)推流
借助OBS Studio
工具进行推流测试,配置推流地址。
(9)拉流
借助LC media player
工具进行拉流测试是否有直播画面。
(10)手机端通过FFmpeg工具拉流显示
最后
下一步将实现通过手机端摄像头采集画面数据,将数据推流到服务器,其中涉及的知识点有rtmp、x264相关开源库.
THE END