Ubuntu+nginx+ftmp+obs搭建直播流服务器学习

  1. 第一步安装依赖

安装gcc g++的依赖库

sudo apt-get install build-essential
sudo apt-get install libtool

安装pcre依赖库

sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev

安装zlib依赖库

sudo apt-get install zlib1g-dev

安装SSL依赖库

1、wget https://www.openssl.org/source/openssl-3.0.1.tar.gz
2、tar -zxvf openssl-3.0.1.tar.gz
3、cd openssl-3.0.1
4、使用./config生成MakeFile,不加任何参数,默认的安装位置为:/usr/local/bin/openssl
5、sudo make && make install
>到上一步openssl就算安装好了,但是还无法使用,需要通过软链接的方式将新旧版本就行替换,依次运行下列命令。
sudo mv /usr/bin/openssl /usr/bin/openssl.old //将旧版本的openssl进行备份
sudo ln -s /usr/local/bin/openssl /usr/bin/openssl //将新版本的openssl进行软链接
cd /etc/ //进入etc目录
su //下一步一定要切换到root用户
echo “/usr/local/lib” >> ld.so.conf //将openssl的安装路径加入配置中
ldconfig //重新加载配置


  1. 安装nginx

切换成root用户步骤
1、sudo passwd root
2、修改root密码
在这里插入图片描述
在这里插入图片描述

>**#下载最新版本**
两种方式 (本文使用wget安装)
1:git clone https://github.com/nginx/nginx.git
2: wget http://nginx.org/download/nginx-1.20.2.tar.gz**#解压:**tar -zxvf nginx-1.20.2.tar.gz**#进入到解压目录**cd  nginx-1.20.2**#下载最新版本**./configure --prefix=/usr/local/nginx --with-openssl=/usr/local/openssl-3.0.1**#编译**make**#安装**sudo make install**#启动:**
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
**#至此nginx就安装成功了**

  1. 安装nginx-http-flv-module

网上很多都是装nginx-rtmp-module 但是nginx-http-flv-module 包含了 nginx-rtmp-module 所有的功能,所以不要将 nginx-http-flv-module 和 nginx-rtmp-module 一起编译。所以本文装的是nginx-http-flv-module ,因为后面要利用flv 拉流
在这里插入图片描述

配置参考地址
https://github.com/winshining/nginx-http-flv-module/blob/master/README.md

安装nginx-http-flv-module步骤

1.下载nginx-http-flv-module
git clone https://github.com/winshining/nginx-http-flv-module.git
2…/configure --add-module=…/nginx-http-flv-module --prefix=/usr/local/nginx --with-openssl=/usr/local/openssl-3.0.1
3.sudo make && make install

配置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       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}location /live {flv_live on; #打开 HTTP 播放 FLV 直播流功能chunked_transfer_encoding off; #支持 'Transfer-Encoding: chunked' 方式回复add_header 'Access-Control-Allow-Origin' '*'; #添加额外的 HTTP 头add_header 'Access-Control-Allow-Credentials' 'true'; #添加额外的 HTTP 头}location /hls {types {application/vnd.apple.mpegurl m3u8;video/mp2t ts;}root /tmp;add_header 'Cache-Control' 'no-cache';}location /dash {root /tmp;add_header 'Cache-Control' 'no-cache';}location /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {root /usr/local/nginx-http-flv-master/;}#如果需要 JSON 风格的 stat, 不用指定 stat.xsl#但是需要指定一个新的配置项 rtmp_stat_format#location /stat {#    rtmp_stat all;#    rtmp_stat_format json;#}location /control {rtmp_control all; #rtmp 控制模块的配置}#error_page  404              /404.html;# redirect server error pages to the static page /50x.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_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /tmp;
rtmp {out_queue           4096;out_cork            8;max_streams         128;timeout             15s;drop_idle_publisher 15s;log_interval 5s; #log 模块在 access.log 中记录日志的间隔时间,对调试非常有用log_size     1m; #log 模块用来记录日志的缓冲区大小server {listen 1935;chunk_size 4096;application vod {play /opt/video/vod;			}application live {live on;# 非常重要, 设定让ngnix断开阻塞中的连接, 才能触发exec_record_done# 以及客户端的LFLiveKit reconnectCount自动重新连接才会好用drop_idle_publisher 5s;meta off; # 为了兼容网页前端的 flv.js,设置为 off 可以避免报错gop_cache on; # 支持GOP缓存,以减少首屏时间allow play all; # 允许来自任何 ip 的人拉流wait_key on;}application flv {live on;gop_cache on; #打开GOP缓存,减少首屏等待时间}application dash {live on;dash on;dash_path /tmp/dash;}application hls {live on;hls on;hls_path /opt/video/rtmp/hls;}}
}

下载OBS

链接地址:https://obsproject.com/
https://obsproject.com/wiki/install-instructions#linux
这里有相关命令
在这里插入图片描述
>设置obs 推流
在这里插入图片描述>修改/usr/local/nginx/html/index.html下的页面
只需要将ip端口号改成对应的就行

<!DOCTYPE html><html><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"><title>Dynabook</title><style>.mainContainer {display: block;width: 1024px;margin-left: auto;margin-right: auto;}.urlInput {display: block;width: 100%;margin-left: auto;margin-right: auto;margin-top: 8px;margin-bottom: 8px;}.centeredVideo {display: block;width: 100%;height: 576px;margin-left: auto;margin-right: auto;margin-bottom: auto;}.controls {display: block;width: 100%;text-align: left;margin-left: auto;margin-right: auto;}</style>
</head><body><div class="mainContainer"><video id="videoElement" class="centeredVideo" controls autoplay width="1024" height="576">Your browser is tooold which doesn't support HTML5 video.</video></div><br><!-- <div class="controls"><button οnclick="flv_load()">加载</button><button οnclick="flv_start()">开始</button><button οnclick="flv_pause()">暂停</button><button οnclick="flv_destroy()">停止</button><input style="width:100px" type="text" name="seekpoint" /><button οnclick="flv_seekto()">跳转</button></div> --><script src="https://cdn.bootcdn.net/ajax/libs/flv.js/1.6.2/flv.min.js"></script><script>var player = document.getElementById('videoElement');if (flvjs.isSupported()) {var flvPlayer = flvjs.createPlayer({type: 'flv',isLive: true, // 如果是直播流需要设置这个值为 trueurl: 'http://192.168.140.172:80/live?port=1935&app=live&stream=test',hasAudio: true,hasVideo: true,enableStashBuffer: true,// ↑ 拉流示例地址,stream参数一定要和推流时所设置的流密钥一致});flvPlayer.attachMediaElement(videoElement);flvPlayer.load(); //加载flvPlayer.play();// flv_start();}function flv_start() {player.play();}function flv_pause() {player.pause();}function flv_destroy() {player.pause();player.unload();player.detachMediaElement();player.destroy();player = null;}function flv_seekto() {player.currentTime = parseFloat(document.getElementsByName('seekpoint')[0].value);}</script>
</body></html>

一个小坑
>记得关闭防火墙
或者用以下命令开启对应端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=1935/tcp --permanent

访问对应ip 192.168.140.172即可显示拉流画面

在这里插入图片描述

一些安装过程中的小tips
修改ubuntu的镜像源地址加速下载本文修改为清华大学镜像源

地址:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
1、备份Ubuntu默认的源地址
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
2、vim /etc/apt/sources.list
在这里插入图片描述
在这里插入图片描述

将镜像源替换完成后,更新镜像源执行
sudo apt-get update
至此镜像源更新完毕


Ubuntu安装ssh

安装ssh服务器
sudo apt install openssh-server

配置ssh服务器
vim /etc/ssh/sshd_config
在这里插入图片描述

重启ssh服务
sudo /etc/init.d/ssh restart


配置环境变量

1、vim /etc/profile
2、export PATH="$PATH:/usr/local/nginx/sbin"
3、source /etc/profile

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/1382692.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

LiveGBS流媒体平台GB/T28181常见问题-海康大华宇视监控设备安防摄像头等设备注册不上来如何检查问题?

LiveGBS中海康大华宇视监控设备安防摄像头等设备注册不上来如何检查问题 1、网页打开后, 看不到设备注册上来2、检查方式2.1、检查设备注册信息2.2、检查服务器防火墙 3、搭建GB28181视频直播平台 1、网页打开后, 看不到设备注册上来 设备已经配置注册了&#xff0c;但是 国标…

王者荣耀是用什么代码变成MOBA游戏的,该怎么学?有前途吗?

王者荣耀用什么开发的 &#xff1f; 手机上的的APP是用的Unity3D游戏引擎。具体的开发语言以C#为主。 下载王者荣耀App安装包并解压&#xff0c;从解压文件中组成的Dll就可发现&#xff0c;王者荣耀客户端使用的是Unity3D技术栈。 因此并不是提到IOS和Android&#xff0c;就一…

王者荣耀「挑战者杯」——千亿规模产业背后的网络架构是怎样的?

2021年王者荣耀挑战者杯总决赛于1月15日落下帷幕&#xff0c;最终武汉eStarPro战队以4&#xff1a;1的比分再次击败广州TTG获得胜利&#xff0c;捧起象征冠军的冰凤凰杯。「挑战者杯」是王者荣耀旗下的六大顶级电竞赛事之一&#xff0c;也是电竞圈新兴起来的热门赛事。 作为拥有…

《王者荣耀》是如何将心理学研究应用到极致的?

本文来自知乎网友神作关于知乎话题“在游戏设计者眼中&#xff0c;哪款游戏将心理学研究应用到了极致&#xff1f;”的回答&#xff0c;游资网授权发布。 开篇语&#xff1a;感谢木棉959圆桌派邀约。哪款游戏将心理学研究应用到了极致&#xff1f;我的答案是&#xff1a;继承…

当代网瘾少年分析,以“2020年,我打了多少局王者荣耀”为例

2020年年初&#xff0c;为了控制自己打游戏&#xff0c;做了一个表&#xff0c;记录打了多少局王者荣耀。 2021年来了&#xff0c;再看这个记录表和当初的flag&#xff0c;仿佛一个大型打脸现场。 打一年王者 写了2.5篇硕士论文&#xff1f; 导入数据后&#xff0c;经过简单计…

实战四十四:基于王者荣耀英雄数据的英雄出场概率、胜率预测分析

首先看一下数据: 结果分析: 完整代码: 所有的数据+代码 首先看一下数据:

【雕爷学编程】Arduino动手做(13)---TTP223B电容式触摸模块之通过串口监视器检测电容触摸键的状态与控制继电器

37款传感器与模块的提法&#xff0c;在网络上广泛流传&#xff0c;其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块&#xff0c;依照实践出真知&#xff08;一定要动手做&#xff09;的理念&#xff0c;以学习和交流为目的&#x…

【雕爷学编程】Arduino动手做(12)---霍尔磁场传感器模块5

37款传感器与模块的提法&#xff0c;在网络上广泛流传&#xff0c;其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块&#xff0c;依照实践出真知&#xff08;一定要动手做&#xff09;的理念&#xff0c;以学习和交流为目的&#x…

企业中商业智能BI,常见的工具和技术

商业智能&#xff08;Business Intelligence&#xff0c;简称BI&#xff09;数据可视化是通过使用图表、图形和其他可视化工具来呈现和解释商业数据的过程。它旨在帮助组织更好地理解和分析他们的数据&#xff0c;从而做出更明智的商业决策。 常见的商业智能数据可视化工具和技…

Zip压缩包有密码,如何删除?

Zip压缩包设置设置了密码&#xff0c;想要删除密码&#xff0c;除了将压缩包解压出来之后再将文件压缩为不带密码的压缩文件以外&#xff0c;还有一种删除密码的方法。设置方法如下&#xff1a; 右键点击zip文件&#xff0c;找到打开方式&#xff0c;以Windows资源管理器方式打…

Django笔记之数据库函数之日期函数

日期函数主要介绍两个大类&#xff0c;Extract() 和 Trunc() Extract() 函数作用是提取日期&#xff0c;比如我们可以提取一个日期字段的年份&#xff0c;月份&#xff0c;日等数据 Trunc() 的作用则是截取&#xff0c;比如 2022-06-18 12:12:12&#xff0c;我们可以根据需求…

SCAU操作系统知识点之(八)虚拟内存

1、虚拟地址概念&#xff0c;实地址概念 实存储器&#xff08;实存&#xff09;&#xff1a;内存 虚存储器&#xff08;虚存&#xff09;&#xff1a;磁盘 虚拟地址&#xff1a;在虚拟内存中分配给某一位置的地址&#xff0c;它使得该位置可被访问&#xff0c;就好像是主内的一…

【JavaWeb】使用聚合数据短信API发送短信

一、准备工作 聚合数据 首先在聚合数据官网中进行注册 然后申请短信API服务&#xff0c;初次使用赠送5次 申请成功之后&#xff0c;AppKey特别重要&#xff0c;不要让别人知道&#xff0c;然后再点击模板 点击模板&#xff0c;填写模板内容&#xff0c;要申请通过&#xff0c…

收藏!2023国内外高质量短信平台一览

众所周知&#xff0c; 短信群发是一种快速、高效、低成本的营销手段&#xff0c;包括但不限于以下作用&#xff1a; 1、传递重要信息&#xff1a;短信群发可以快速传递企业、品牌、产品的信息&#xff0c;通过短信内容向潜在客户、用户、合作伙伴等发送最新的产品信息、活动信…

【新晋开源项目】聚合短信工具 Sms-Aggregation 加入 Dromara 开源社区

原创 wind dromara开源组织 2023-04-10 08:38 发表于四川 sms-aggregation 聚合短信发送工具 作者介绍 名称&#xff1a;wind dromara 开源组织成员&#xff0c;dromara/sms_aggregation 作者 java高级开发工程师&#xff0c;拥有丰富实战经验 个人空间&#xff1a;https:…

聚合短信API,手机验证登录

今天在项目中遇到了一个需要手机验证登录的需求&#xff0c;在这里简单的记录一下。聚合短信API&#xff0c;手机验证登录 首先需要在聚合平台里面进行公司资质认真 飞机票&#xff1a;https://www.juhe.cn/docs/api/id/54 认证成功后 点击我的接口 继续 进行短信模板审核 通…

用ChatGPT和六顶帽思考法帮助自己更好地决策和解决问题

当我们在解决复杂问题时&#xff0c;我们常常陷入单一视角的状态。创造性思维领域的先驱爱德华德博诺&#xff0c;提出了六顶帽思考法[1]&#xff0c;这意味着我们可以从六个不同的视角来思考一个问题&#xff0c;以实现高水平决策和解决问题。 每一顶“帽子”代表不同的视角。…

发现一个相当好的食物热量计算器!

厄&#xff0c;这两天没怎么吃东西&#xff0c;感觉瘦了些。特意去网上找了一个食物热量计算器&#xff0c;把自己吃的那点儿放进去算了一下&#xff0c;哇&#xff0c;远远低于每天实际消耗的热量&#xff01; 我琢磨着&#xff0c;怎么把这东西给下载下来用呢&#xff1f;

计算每日摄入量

1.每周减重 自重*0.7% 2.蛋白质量 每磅*&#xff08;0.8 ~1&#xff09; 3.坚持计划&#xff0c;多负荷训练 参考&#xff1a;https://zhuanlan.zhihu.com/p/44725585 每日总消耗量&#xff08;TDEE&#xff09;&#xff1a;由三个因素构成 1.摄食生热效应&#xff1a; …

每天坚持慢跑30分钟,一个月身体会有什么变化?

如果我告诉你身材不会有什么大变化&#xff0c;你是不是会绝望&#xff1f;但这是事实&#xff01; 保持坚持跑步习惯的人有两种&#xff1a; 第1种是纯粹热爱跑步&#xff0c;追求身体的长久健康&#xff0c;活力保持。 第2种是为了减肥&#xff0c;回归匀称标准的身材。 …