找回密码
 立即注册
虾米引擎源代码Delphi3KM2引擎源码20121218CQFIR飞尔引擎20120918源码文字广告位置4
APPLEM2引擎源代码传奇引擎delphi源代码DELPHI视频教程
GSQL_6.5.2.1源代码Delphi即时通讯Delphi源码文字广告位置11
文字广告位置12
文字广告位置13
文字广告位置14
文字广告位置15
文字广告位置16
UC845刺客引擎飞龙3delphi源码文字广告位置18
文字广告位置19
文字广告位置20
文字广告位置21文字广告位置22
文字广告位置23
文字广告位置24
文字广告位置25
文字广告位置26文字广告位置27文字广告位置28
查看: 787|回复: 0

[其他教程] nginx+obs搭建流媒体,实现直播 流媒体

[复制链接]

800

主题

42

回帖

4857

积分

管理员

积分
4857

最佳新人活跃会员热心会员推广达人宣传达人突出贡献优秀版主荣誉管理论坛元老

QQ
发表于 2018-4-23 08:42:47 | 显示全部楼层 |阅读模式
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文件,我贴出整个配置文件:

[plain] view plain copy


  • #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 / {
  •             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;
  •                 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

[php] view plain copy


  •    
  • jwplayer播放器测试



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


到此实现的简单的直播。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|Delphi源代码

GMT+8, 2025-4-27 09:16 , Processed in 0.151394 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表