admin 发表于 2018-4-23 08:42:47

nginx+obs搭建流媒体,实现直播 流媒体

1.直播是现在最热门的,尤其是电竞的发展成功的带动的直播的发展,各种游戏直播月入XXX,经常听到的一句话:某主播XXX月入百万,不知道是真是假暂且不管,看看直播到底是怎么实现的,直播使用的是RTMP协议(实时消息传输协议),实现这个协议的方式有很多种,这里使用nginx(一个超级强大的服务器)的rtmp-moudle模块来实现。
我是在ubantu上面搭建的环境:
首先准备nginx安装包和nginx-rtmp-module模块的安装包
nginx安装包:http://nginx.org/,请自行下载
wget http://nginx.org/download/nginx-1.11.3.tar.gz
nginx-rtmp-module模块下载

wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
下载完毕解压
tar -zxvf nginx-1.11.3.tar.gz
unzip master.zip(没有安装该软件包:sudo apt-get install unzip)
解压完毕进入nginx-1.11.3文件夹
./configure--add-module=../arut-nginx-rtmp-module-c0bf381

sudo make
sudo make install
安装完毕!
运行nginx:
sudo /usr/local/nginx/sbin/nginx

运行:ifconfig查看ubantu的ip地址:


打开浏览器输入:你本机的ip看到nginx的欢迎页面,说明安装成功,如图:


然后:
cd /usr/local/nginx/conf
nginx的配置文件可能没有修改的权限
修改权限:

sudo chmod 777conf/
编辑nginx.conf文件,我贴出整个配置文件:

view plain copy



[*]#usernobody;
[*]worker_processes1;
[*]
[*]#error_loglogs/error.log;
[*]#error_loglogs/error.lognotice;
[*]#error_loglogs/error.loginfo;
[*]
[*]#pid      logs/nginx.pid;
[*]
[*]
[*]events {
[*]    worker_connections1024;
[*]}
[*]
[*]
[*]http {
[*]    include       mime.types;
[*]    default_typeapplication/octet-stream;
[*]
[*]    #log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
[*]    #                  '$status $body_bytes_sent "$http_referer" '
[*]    #                  '"$http_user_agent" "$http_x_forwarded_for"';
[*]
[*]    #access_loglogs/access.logmain;
[*]
[*]    sendfile      on;
[*]    #tcp_nopush   on;
[*]
[*]    #keepalive_timeout0;
[*]    keepalive_timeout65;
[*]
[*]    #gzipon;
[*]
[*]    server {
[*]      listen       80;
[*]      server_namelocalhost;
[*]
[*]      #charset koi8-r;
[*]
[*]      #access_loglogs/host.access.logmain;
[*]
[*]      location / {
[*]            root   html;
[*]            indexindex.html index.htm;
[*]      }
[*]
[*]      #error_page404            /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_indexindex.php;
[*]      #    fastcgi_paramSCRIPT_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 {
[*]      #    denyall;
[*]      #}
[*]    }
[*]
[*]
[*]    # another virtual host using mix of IP-, name-, and port-based configuration
[*]    #
[*]    #server {
[*]    #    listen       8000;
[*]    #    listen       somename:8080;
[*]    #    server_namesomenamealiasanother.alias;
[*]
[*]    #    location / {
[*]    #      root   html;
[*]    #      indexindex.html index.htm;
[*]    #    }
[*]    #}
[*]
[*]
[*]    # HTTPS server
[*]    #
[*]    #server {
[*]    #    listen       443 ssl;
[*]    #    server_namelocalhost;
[*]
[*]    #    ssl_certificate      cert.pem;
[*]    #    ssl_certificate_keycert.key;
[*]
[*]    #    ssl_session_cache    shared:SSL:1m;
[*]    #    ssl_session_timeout5m;
[*]
[*]    #    ssl_ciphersHIGH:!aNULL:!MD5;
[*]    #    ssl_prefer_server_cipherson;
[*]
[*]    #    location / {
[*]    #      root   html;
[*]    #      indexindex.html index.htm;
[*]    #    }
[*]    #}
[*]
[*]}
[*]rtmp {
[*]      server {
[*]                listen 1935;
[*]                chunk_size 4096;
[*]
[*]                application live {
[*]                        live on;
[*]                        record off;
[*]                }
[*]      }
[*]    }


加的配置就在最后,复制添加即可。
保存之后重启nginx:
sudo /usr/local/nginx/sbin/nginx -s stop

sudo /usr/local/nginx/sbin/nginx
没有出现错误,这时已经成功搭建好了rtmp流媒体,这时需要一个推流的客户端给服务器
这里选择OBS,比较出名的一个软件:下载地址:
https://obsproject.com/download#mp
自己下载安装
安装完毕配置obs





注意IP要该为自己的。
完毕之后还有做一个浏览器的展示:
建立play.php

view plain copy



[*]   
[*]
[*]
[*] jwplayer播放器测试
[*]
[*]
[*]
[*]
[*]
[*]
[*]
[*]
[*]

[*]
[*]
[*]
[*]

jwplayer包请在这里下载:http://download.csdn.net/detail/gaoxuaiguoyi/9300373
下载完毕直接放在目录下面就可以了:
访问:你的IP/play.php


到此实现的简单的直播。

页: [1]
查看完整版本: nginx+obs搭建流媒体,实现直播 流媒体