php开源流媒体服务器,Centos6.5+Nginx+RTMP流媒体服务(直播、点播)

安装前的准备

sudo yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel -y

sudo yum install gcc gcc-c++ make libtool -y

下载Nginx

wget http://nginx.org/download/nginx-1.12.0.tar.gz

tar -xvf nginx-1.12.0.tar.gz

下载nginx-rtmp-module

wget https://github.com/arut/nginx-rtmp-module/archive/v1.1.11.tar.gz

tar -xvf v1.1.11.tar.gz

cd nginx-1.12.0

sudo ./configure --add-module=../nginx-rtmp-module-1.1.11/

sudo make

sudo make install

添加防火墙白名单,局域网其它机器可以通过ip访问Nginx

sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT

sudo iptables -I INPUT -p tcp --dport 8000 -j ACCEPT

sudo iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

sudo service iptables save

sudo service iptables restart

查看防火墙配置

sudo cat /etc/sysconfig/iptables

或者

sudo iptables -L -n

Nginx配置

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

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

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;

#}

}

server {

listen 8080;

server_name localhost;

# sample handlers

#location /on_play {

# if ($arg_pageUrl ~* localhost) {

# return 201;

# }

# return 202;

#}

#location /on_publish {

# return 201;

#}

#提供vod点播服务

location /vod {

alias /var/flvs;

}

# rtmp stat

location /stat {

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl {

# you can move stat.xsl to a different location

root html;

}

# rtmp control

location /control {

rtmp_control all;

}

location /hls {

# Serve HLS fragments

types {

application/vnd.apple.mpegurl m3u8;

video/mp2t ts;

}

root /tmp;

add_header Cache-Control no-cache;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

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

ping 30s;

notify_method get;

application myapp {

live on;

# sample play/publish handlers

#on_play http://localhost:8080/on_play;

#on_publish http://localhost:8080/on_publish;

# sample recorder

#recorder rec1 {

# record all;

# record_interval 30s;

# record_path /tmp;

# record_unique on;

#}

# sample HLS

#hls on;

#hls_path /tmp/hls;

#hls_sync 100ms;

}

# Video on demand

application vod {

#play /home/cmcc/test;

play /var/flvs;

}

# Video on demand over HTTP

application vod_http {

play http://localhost:8080/vod/;

}

application hls{

live on;

hls on;

hls_path /tmp/hls;

hls_fragment 5s;

}

}

}

将nginx-rtmp-module-1.1.11目录下的stat.xls放到nginx配置的stat文件所在目录,通过访问http://localhost:8080/stat 来查看Nginx RTMP状态

sudo cp stat.xsl /usr/local/nginx/html/

RTMP测试方法二,使用JWPlayer JS库,这里需要注意,需要在jwplayer官网注册之后,获得一个key之后,在加载jwplayer.js的页面将key一起配置,才可以使用。然后新建一个play.html,代码如下:

点播:rtmp://10.2.44.216/vod/mp4:large.mp4

jwplayer('my-video').setup({

file:'rtmp://10.2.44.216/vod/mp4:large.mp4'

});

直播:rtmp://10.2.44.216/myapp/live

jwplayer('my-video1').setup({

file:'rtmp://10.2.44.216/myapp/live'

});

点播功能效果:

在/var/flvs/目录下放入一个h264编码的视频文件large.mp4,然后在play.html中设置rtmp地址为rtmp://10.2.44.216/vod/mp4:large.mp4

40c81c1926e0?from=timeline&isappinstalled=0

点播

此时stat页面:

40c81c1926e0?from=timeline&isappinstalled=0

http://10.2.44.216:8080/stat

直播功能效果:

需要Android手机一部,使用yasea作为推流的客户端APP,修改开源项目中的代码,设置rtmp地址为"rtmp://10.2.44.216/myapp/live",效果如下

40c81c1926e0?from=timeline&isappinstalled=0

直播

40c81c1926e0?from=timeline&isappinstalled=0

直播stat

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值