300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 环信直播php怎么生成推流地址 使用Nginx实现简单的RTMP推流直播笔记

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

时间:2023-05-07 15:43:44

相关推荐

环信直播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 /arut/nginx-rtmp-module.git

第3步:安装Nginx服务器

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

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

[root~]# wget /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 0623 (Red Hat 4.8.5-16) (GCC)

built with OpenSSL 1.0.2k-fips 26 Jan

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

.

Commercial support is available at

.

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 0623 (Red Hat 4.8.5-16) (GCC)

Feb 26 21:48:59

29574

608

0

0

0

0

0

rtmplive

0

vod

0

PS:说明启动成功

rtmplive

0

vod

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

image.png

点击来源:

直播来源:

image.png

image.png

点击确定:

image.png

image.png

点击开始推送:

image.png

说明连接服务器成功:

image.png

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

image.png

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

image.png

最终结果:

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。