個人怎樣建立網(wǎng)站市場調(diào)研報告1500字
技術要求:nginx+nginx-rtmp+ffmpeg+VLC
跟著大佬走的:
傳送門
準備工作:
首先需要一臺公網(wǎng)ip的服務器
這是使用天翼云的彈性云主機:免費試用1個月
天翼云官網(wǎng)
點擊關機,更多里面選擇重置密碼,
默認用戶名為root
使用xshell連接
彈性ip:xx.xx.xx.xx
root 密碼
創(chuàng)建目錄:mkdir rtmp
切換目錄
使用winSCP軟件上傳rtmp源碼文件,下載nginx:
wget http://nginx.org/download/nginx-1.8.0.tar.gz
解壓:tar -xvf nginx-1.8.0.tar.gz
cd nginx-1.8.0/
安裝依賴庫
yum -y install pcre-develyum -y install openssl openssl-devel
# 注釋:add-module=自己的nginx-rtmp目錄 --with-http_ssl_module
./configure --add-module=../nginx-rtmp-module-master --with-http_ssl_module
# 編譯makemake install
# 啟動nginx:cd /usr/local/nginx/sbin./nginx
nginx默認使用的是80端口,開放防火墻
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
天翼云后臺開放安全組:80 0.0.0.0/0
但其實這里的80端口是不能使用的,除非備案!!!
天翼云服務器的80、443、8080端口均需要備案才能訪問,其他端口是開放的
修改nginx的端口為8090
cd /usr/local/nginx/confvi nginx.conf
重啟nginxsudo pkill -9 nginx./nginx查看nginx端口是否是8090sudo netstat -anp | grep nginx
關閉防火墻
首先,您需要打開終端并以root用戶身份登錄。
然后,使用以下命令停止firewalld服務,并禁用防火墻服務
sudo systemctl stop firewalld
sudo systemctl disable firewalld
# 接下來,您可以使用以下命令來檢查是否已成功停止防火墻服務。
sudo systemctl status firewalld
天翼云后臺添加安全組:
出來了:
添加rtmp配置
cd /usr/local/nginx/confvi nginx.conf
rtmp {server {listen 1935;chunk_size 4000;application live {live on;}}
}
# 重啟nginx
sudo pkill -9 nginx
cd /usr/local/nginx/sbin
./nginx
推流測試
下載ffmpeg源碼包
window電腦配置環(huán)境變量(path)
使用ffmpeg推流
用gitbash打開,桌面有一個video.mp4 ,推流到ip為36.111.171.xx.xx(自己的):1935/live/流id(叫test也行,只是拉流也需要同名流id才能拉取成功)
ffmpeg -re -i video.mp4 -f flv rtmp://36.111.171.36:1935/live/s1
拉流測試
電腦端拉流測試
使用VLC軟件進行拉流,win11環(huán)境拉取服務器視頻
點擊媒體:選擇打開網(wǎng)絡串流,輸入rtmp://36.111.xx.xx:1935/live/s1
安卓手機拉流測試
下載安卓版VLC軟件:點擊更多->新建文件串流->輸入
rtmp://36.111.xx.xx:1935/live/s1
項目實戰(zhàn)demo:
創(chuàng)建一個uniapp項目,創(chuàng)建一個后綴為.nvue的文件
將代碼里面的data中的url,src中的ip換為自己的。
<template><view><!-- 音視頻播放 --><video id="myVideo" :src="src"@error="videoErrorCallback" :danmu-list="danmuList" enable-danmu danmu-btn controls></video><!-- 音視頻錄制 --><live-pusher id='livePusher' ref="livePusher" class="livePusher" :url="url"mode="SD" :muted="false" :enable-camera="true" :auto-focus="true" :beauty="1" whiteness="2"aspect="9:16" @statechange="statechange" @netstatus="netstatus" @error = "error"></live-pusher><!-- <button class="btn" @click="start">開始推流</button><button class="btn" @click="pause">暫停推流</button><button class="btn" @click="resume">resume</button><button class="btn" @click="stop">停止推流</button><button class="btn" @click="snapshot">快照</button><button class="btn" @click="startPreview">開啟攝像頭預覽</button><button class="btn" @click="stopPreview">關閉攝像頭預覽</button><button class="btn" @click="switchCamera">切換攝像頭</button> --></view>
</template><script>export default {data() {return {url:'rtmp://36.111.171.36:1935/live/s1',src:'rtmp://36.111.171.36:1935/live/s1'// url:'rtmp://192.168.74.128:1935/live/s1',// src:'rtmp://192.168.74.128:1935/live/s1'}},onReady() {// 注意:需要在onReady中 或 onLoad 延時this.context = uni.createLivePusherContext("livePusher", this);this.start();},methods: {statechange(e) {console.log("statechange:" + JSON.stringify(e));},netstatus(e) {console.log("netstatus:" + JSON.stringify(e));},error(e) {console.log("error:" + JSON.stringify(e));},start: function() {this.context.start({success: (a) => {console.log("livePusher.start:" + JSON.stringify(a));}});},close: function() {this.context.close({success: (a) => {console.log("livePusher.close:" + JSON.stringify(a));}});},snapshot: function() {this.context.snapshot({success: (e) => {console.log(JSON.stringify(e));}});},resume: function() {this.context.resume({success: (a) => {console.log("livePusher.resume:" + JSON.stringify(a));}});},pause: function() {this.context.pause({success: (a) => {console.log("livePusher.pause:" + JSON.stringify(a));}});},stop: function() {this.context.stop({success: (a) => {console.log(JSON.stringify(a));}});},switchCamera: function() {this.context.switchCamera({success: (a) => {console.log("livePusher.switchCamera:" + JSON.stringify(a));}});},startPreview: function() {this.context.startPreview({success: (a) => {console.log("livePusher.startPreview:" + JSON.stringify(a));}});},stopPreview: function() {this.context.stopPreview({success: (a) => {console.log("livePusher.stopPreview:" + JSON.stringify(a));}});}}}
</script><style></style>
運行到安卓手機
效果:下面在推流,上面在拉流,
由于網(wǎng)絡傳輸,拉流的視頻會有延時(直播)
完結撒花!!!碼字不易,點個贊再走啦