匯算清繳在哪個(gè)網(wǎng)站做百度貼吧廣告投放
需求
在服務(wù)器搭建點(diǎn)播/視頻平臺(tái)的話需要在服務(wù)器搭建nginx和rtmp模塊
rtmp模塊
rtmp 模塊有 nginx-rtmp-module ,但是我們這里使用 nginx-http-flv-module 來(lái)替代。因?yàn)楹笳呤腔谇罢唛_(kāi)發(fā)的,前者擁有的功能后者都有,后者是國(guó)內(nèi)的開(kāi)發(fā)開(kāi)發(fā),有中文文檔
下載nginx-http-flv-module 源碼
#下載nginx-http-flv-module
wget https://github.com/winshining/nginx-http-flv-module/archive/master.zip
#解壓 nginx-http-flv-module
unzip master.zip#一般將這個(gè)放在usr/local,目錄下
接著下載 nginx.本身的源碼
#我這邊選擇1.24.0版本
wget http://nginx.org/download/nginx-1.24.0.tar.gz
#然后解壓
tar -zxvf nginx-1.24.0.tar.gz#進(jìn)入nginx安裝目錄
cd /usr/local/nginx-1.24.0#執(zhí)行 ../相對(duì)路徑
./configure --add-module=../nginx-http-flv-module-mastermake
make install#安裝好之后,nginx會(huì)默認(rèn)出現(xiàn)在/usr/local/nginx
先將nginx配置到全局命令中 /etc/profile
vim /etc/profile
#將這行命令添加到最后一行
export PATH=/usr/local/nginx/sbin/:$PATH#保存退出并重載資源
source /etc/profile#查看是否已經(jīng)添加了rtmp模塊
nginx -V#出現(xiàn)configure arguments: --add-module=../nginx-http-flv-module-master
#說(shuō)明已經(jīng)添加了rtmp模塊
開(kāi)始進(jìn)入rtmp配置
rtmp{server{listen 1935;chunk_size 4096;application hls{live on;allow publish all;allow play all; # 允許所有用戶播放流record off;hls on;hls_path /usr/local/video/hls;hls_fragment 10s; #切片時(shí)長(zhǎng)hls_playlist_length 60m; #播放列表hls_continuous on; hls_cleanup off; # 防止自動(dòng)清除切片}application vod{# 播放地址為 rtmp://ip:1935/vod/1.mp4 play /usr/local/video/vod;}}
}
如果希望播放m3u8格式的視頻,即實(shí)時(shí)視頻,可以在server中配置
location /hls/ {types {application/vnd.apple.mpegurl m3u8;video/mp2t ts;}root /usr/local/video/; # 設(shè)置HLS文件所在的根目錄add_header Cache-Control no-cache; # 禁止緩存add_header Access-Control-Allow-Origin *; #允許跨域請(qǐng)求。}
保存并退出之后使用nginx -t 查看是否配置有報(bào)錯(cuò)?
切記:配置的播放/存儲(chǔ)地址信息要先配好,不然執(zhí)行的時(shí)候會(huì)報(bào)錯(cuò)!
點(diǎn)播測(cè)試(記得開(kāi)發(fā)1935端口和nginx中server配置的端口80)
測(cè)試vod點(diǎn)播模塊,現(xiàn)在vod目錄下放入一個(gè)mp4文件
使用測(cè)試工具vlc?
依次選擇 媒體->打開(kāi)網(wǎng)絡(luò)串流
輸入rtmp://ip:1935/vod/2.mp4
如果有報(bào)錯(cuò)的話可以先打開(kāi)工具->消息,然后再次執(zhí)行
注意:記得先啟動(dòng)nginx ,進(jìn)入nginx目錄輸入nginx
查看nginx是否啟動(dòng)? ps -ef|grep nginx
使用ffmpeg推送視頻到服務(wù)器并進(jìn)行測(cè)試
在本地電腦下載ffmpeg,然后進(jìn)入ffmpeg目錄
ffmpeg -i D:\picture\video\4.mp4 -c:v libx264 -c:a aac -f flv rtmp://ip:1935/hls/test
這樣即上傳視頻成功
在vlc中再次測(cè)試http://ip:80/hls/test.m3u8
不過(guò)在vlc上測(cè)試可能會(huì)有問(wèn)題,比如它會(huì)只從中間播放,或者不能左移右移,又或者最后一段不能播放的問(wèn)題
可以用以下方式實(shí)戰(zhàn)測(cè)試。
在桌面新建一個(gè)文本文檔,然后把下面代碼輸進(jìn)去,并且將后綴.txt 修改為.html。
注意:在<source src > 這里將地址信息修改為你自己的地址
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>HLS Video</title><link href="https://vjs.zencdn.net/7.11.4/video-js.css" rel="stylesheet" /><style>#controls {margin-top: 10px;}#controls button {margin-right: 10px;}</style>
</head>
<body><video id="my-video" class="video-js" controls preload="auto" width="640" height="264" data-setup="{}"><source src="http://ip:80/hls/test.m3u8" type="application/x-mpegURL"></video><div id="controls"><button id="rewind">Rewind 10s</button><button id="forward">Forward 10s</button><span id="current-time">00:00</span> / <span id="duration">00:00</span></div><script src="https://vjs.zencdn.net/7.11.4/video.js"></script><script>var player = videojs('my-video');// Update current time and durationplayer.on('timeupdate', function() {document.getElementById('current-time').innerText = formatTime(player.currentTime());document.getElementById('duration').innerText = formatTime(player.duration());});// Rewind buttondocument.getElementById('rewind').addEventListener('click', function() {player.currentTime(player.currentTime() - 10);});// Forward buttondocument.getElementById('forward').addEventListener('click', function() {player.currentTime(player.currentTime() + 10);});// Format time functionfunction formatTime(seconds) {var minutes = Math.floor(seconds / 60);var seconds = Math.floor(seconds % 60);return (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds;}// Ensure video starts from the beginningplayer.ready(function() {player.currentTime(0);});</script>
</body>
</html>
雙擊測(cè)試