首页 > 编程知识 正文

RTMP直播搭建(obs直播的好处)

时间:2023-05-06 14:03:28 阅读:71854 作者:740

目录和安装

构成

OBS推流

实行

引领潮流

完成

概述和安装

Nginx本身是一款非常好的HTTP服务器,openbroadcastersoftware (OBS )是一款免费、开源、全平台支持的视频录制和实时软件。 可以通过在单个nginx模块nginx-rtmp-module中组合这两个模块来构建功能流服务器。 此流媒体服务器可以支持RTMP和实时RTMP流(HLS )。

FFmpeg也是非常好的音视频解决方案。 但是,OBS的界面更友好,支持屏幕捕获,所以我选择OBS。 其实FFmpeg没有GUI接口,所以我不擅长研究它。

关于Nginx的安装,请参考这里。 在Linux端安装Nginx和RTMP模块请参考此处。 RTMP模块的Github地址在这里。 在这里可以看到更详细的使用方法。

作者在Windows环境下构建服务器,用最简单的方法实现了作者所需的功能。

构成

假设您安装了Nginx和RTMP插件。 现在是使用它的时候了。

首先,定义Nginx的配置文件nginx-win-rmtp.conf。

展开范例显示

#用户nobody;

#多工作器工作器!

工作器_ processes 2;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

事件{

worker_connections 8192;

# max value 32768,nginxrecyclingconnectionsregistryoptimization=

# this.value * 20=maxconcurrentconnectionscurrentlytestedwithoneworker

# c1000 kshouldbepossibledependingthereisenoughram/CPU power

# multi_accept on;

}

rtmp {

服务器{

listen 1935

chunk_size 4000;

live APP

直播开启;

}

}

}

http {

# include/nginx/conf/na xsi _ core.rules;

include mime.types;

efault _ type应用程序/octet-stream;

# log _ format main ' $ remote _ addr 3360 $ remote _ port-$ remote _ user [ $ time _ local ] ' $ request ' '

# ' $ status $ body _ bytes _ sent ' $ http _ referer ' '

# ' ' $ http _ user _ agent ' ' $ http _ x _ forwarded _ for ';

#access_log logs/access.log main;

# #加载平衡PHP

# upstream myLoadBalancer {

# server 127.0.0.133609001 weight=1fail _ time out=5;

# server 127.0.0.133609002 weight=1fail _ time out=5;

#服务器127.0.0.133609003 weight=1fail _ time out=5;

#服务器127.0.0.133609004 weight=1fail _ time out=5;

#服务器127.0.0.133609005 weight=1fail _ time out=5;

#服务器127.0.0.133609006 weight=1fail _ time out=5;

#服务器127.0.0.133609007 weight=1fail _ time out=5;

#服务器127.0.0.133609008 weight=1fail _ time out=5;

#服务器127.0.0.133609009 weight=1fail _ time out=5;

#服务器127.0.0.133609010 weight=1fail _ time out=5;

# least_conn;

# }

sendfile off;

#tcp_nopush on;

server_names_hash_bucket_size 128;

## Start: Timeouts ##

client_body_timeout 10;

client_header_timeout 10;

keepalive_timeout 30;

send_timeout 10;

keepalive_requests 10;

## End: Timeouts ##

#gzip on;

server {

listen 80;

server_name localhost;

location /stat {

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl {

root nginx-rtmp-module/;

}

location /control {

rtmp_control all;

}

#charset koi8-r;

#access_log logs/host.access.log main;

## Caching Static Files, put before first location

#location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {

# expires 14d;

# add_header Vary Accept-Encoding;

#}

# For Naxsi remove the single # line for learn mode, or the ## lines for full WAF mode

location / {

#include /nginx/conf/mysite.rules; # see also http block naxsi include line

##SecRulesEnabled;

##DeniedUrl "/RequestDenied";

##CheckRule "$SQL >= 8" BLOCK;

##CheckRule "$RFI >= 8" BLOCK;

##CheckRule "$TRAVERSAL >= 4" BLOCK;

##CheckRule "$XSS >= 8" BLOCK;

root html;

index index.html index.htm;

}

# For Naxsi remove the ## lines for full WAF mode, redirect location block used by naxsi

##location /RequestDenied {

## return 412;

##}

## Lua examples !

# location /robots.txt {

# rewrite_by_lua '

# if ngx.var.http_host ~= "localhost" then

# return ngx.exec("/robots_disallow.txt");

# end

# ';

# }

#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; # single backend process

# fastcgi_pass myLoadBalancer; # or multiple, see example above

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME $document_root$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 spdy;

# server_name localhost;

# ssl on;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_prefer_server_ciphers On;

# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

# ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!eNULL:!MD5:!DSS:!EXP:!ADH:!LOW:!MEDIUM;

# location / {

# root html;

# index index.html index.htm;

# }

#}

}

挑重点的说,我们需要注意的是

rtmp {

server {

listen 1935;

chunk_size 4000;

application live {

live on;

}

}

}

此处的listen指的是你的rtmp开在了本地的哪个端口,xndmy需要链接服务器的时候,别忘了把端口号加上,如果设备处于内网,那么记得打开端口映射,防火墙选择放行。因为我们关注的只有rtmp服务器,所以无需关注其他端口。

OBS推流

打开OBS。

1.进入推流设置,将服务设置为“自定义”。

2.服务器设置为rtmp://IP:Port/APP。

3.串流秘钥不填写,作者不会使用权限控制的功能。想要进行权限设置,可以参考这里。

因为在配置文件中我们创建的app名字就叫live,所以在这里APP填写为live。如rtmp://192.168.1.110:1935/live。

运行

我写了一个Powershell脚本来运行nginx。可以在一个PS窗口中非常方便的运行和结束nginx。

该脚本默认nginx-win-rtmp.conf配置文件在nginx.exe目录下的conf目录中。

而nginx.exe的路径在D:HiderToolsFFmpeg+nginx+LIVEnginx-1.7.11.3-Gryphon中,请根据实际情况自行修改。

cd "D:HiderToolsFFmpeg+nginx+LIVEnginx-1.7.11.3-Gryphon"

# 若nginx已经运行,则停止

Get-Process -Name "nginx" | Stop-Process

$job = Start-Job -ScriptBlock {

cd "D:HiderToolsFFmpeg+nginx+LIVEnginx-1.7.11.3-Gryphon";

.nginx.exe -c confnginx-win-rtmp.conf;

}

Write-Host "Starting...`n"

sleep 2

Get-Job

Write-Host "`n"

Get-Process -Name "nginx" | Format-Table

do {

Write-Host "`nNginx is running, finish it?`n";

$exit = Read-Host "Type Y to finish";

Write-Host "`n"

} while ($exit -ne "Y")

Write-Host "Before:"

Get-Process -Name "nginx" | Format-Table

.nginx.exe -s quit

# 先平稳关闭,若失败则强制结束进程

Get-Process -Name "nginx" | Stop-Process

sleep 1

Write-Host "`nAfter:"

Get-Process -Name "ngin*" | Format-Table

Write-Host "(It has been finished if there were no output.)"

Write-Host "`nNginx has been finished.`n"

pause

拉流

让OBS开始推流,如果一切都没有问题,此时应该是可以正常运行的。接下来,我们要让客户端拉取直播。

作者使用Potplayer,各个(靠谱的)播放器播放流的方法都大同小异:

1.菜单 - 打开 - 打开流(或 打开链接 等)

2.输入刚刚你推流的rtmp://网址,和OBS推流地址相同。

完成

到此为止,你应该已经成功的在本地搭建了一个简单的nginx直播服务器,并且能够正常观看。

十分感谢您的阅读,这是我第一次写博客,希望能够得到更多的指教,包括技术方面和写作方面的。

来源:https://www.cnblogs.com/zhiders/p/12987517.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。