环信直播php怎么生成推流地址,使用Nginx实现简单的RTMP推流直播笔记

实现结果

推流的实现:使用OBS Studio进行推流

拉流播放的实现:使用VLC进行拉流地址播放

直播服务器实现:centos系统下的nginx+RTMP模块

实现步骤:

第1步:nginx相关依赖包的安装

nginx相关依赖包的安装:

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmakepcre-develnanowget gcc gcc-c++ ncurses-devel perl

其他需要用到的依赖包:

yum -y install git

yum -y install nano

yum -y install wget

第2步:nginx-rtmp-module

nginx-rtmp-module,官方github地址

// 通过git clone 的方式下载到服务器上

[root~]# git clone https://github.com/arut/nginx-rtmp-module.git

第3步:安装Nginx服务器

1.下载Nginx解压,并安装rtmp和openssl的模块

PS:add-module=/data/bak/nginx-rtmp-module 中的/data/bak是自己的下载的相关模块的存放路径

[root~]# wget http://nginx.org/download/nginx-1.10.3.tar.gz

[root~]# tar -zxvf nginx-1.10.3.tar.gz

[root~]# cd nginx-1.10.3

//添加rtmp和openssl支持

[root~]# ./configure --add-module=/data/bak/nginx-rtmp-module --with-http_ssl_module

[root~]# make && make install

第4步:查看安装模块信息:

[root@localhost nginx-1.10.3]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

[root@localhost nginx-1.10.3]# nginx -V

nginx version: nginx/1.10.3

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)

built with OpenSSL 1.0.2k-fips 26 Jan 2017

TLS SNI support enabled

configure arguments: --add-module=/data/bak/nginx-rtmp-module --with-http_ssl_module

第5步:启动nginx,查看启动的情况

[root@localhost nginx-1.10.3]# nginx -s stop

[root@localhost nginx-1.10.3]# nginx

[root@localhost nginx-1.10.3]# curl http://192.168.74.128/

Welcome to nginx!

body {

width: 35em;

margin: 0 auto;

font-family: Tahoma, Verdana, Arial, sans-serif;

}

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.

[root@localhost nginx-1.10.3]#

第6步:配置相关的模块信息修改nginx.conf

PS:注意是在http{}外进行添加:

rtmp {

server {

listen 1935;

application rtmplive {

live on;

record off;

}

application vod {

play /opt/video/vod;

}

}

}

完成的配置文件如下:

==

#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;

}

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;

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location /stat { #第1处添加的location字段。

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl { #第2处添加的location字段。

root /usr/local/nginx/nginx-rtmp-module/;

}

location / {

root html;

index index.html index.htm;

}

#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;

# 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;

# }

#}

}

rtmp {

server {

listen 1935;

application rtmplive {

live on;

record off;

}

application vod {

play /opt/video/vod;

}

}

}

第7步:关闭防火墙,为方便测试

ps:一般线上环境是不会直接关闭防火墙,而是开放对应的端口。写对应的规则!

systemctl stop firewalld

[root@localhost nginx-1.10.3]# nginx -s reload

[root@localhost nginx-1.10.3]# curl http://192.168.74.128/stat

1.10.3

1.1.4

gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)

Feb 26 2018 21:48:59

29574

608

0

0

0

0

0

rtmplive

0

vod

0

PS:说明启动成功

rtmplive

0

vod

第9步:使用OBS Studio进行推流

b4ee6956d1ea

image.png

点击来源:

直播来源:

b4ee6956d1ea

image.png

b4ee6956d1ea

image.png

点击确定:

b4ee6956d1ea

image.png

b4ee6956d1ea

image.png

点击开始推送:

b4ee6956d1ea

image.png

说明连接服务器成功:

b4ee6956d1ea

image.png

如果关闭了nginx,则会提示:

b4ee6956d1ea

image.png

第10步:使用VLC播放器进行播放拉流地址

b4ee6956d1ea

image.png

最终结果:

b4ee6956d1ea

image.png

ffmpeg -re -i "D:\download\film\aqgy\02.mp4" -vcodec libx264 -vprofile baseline -acodec aac

-ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://192.168.74.128:1935/

myapp/test1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值