RTMP 是 Real Time Messaging Protocol 的縮寫
該協定是Adobe Systems公司為Flash播放機和伺服器之間音訊、視頻和資料傳輸 開發的開放協定
本次測試環境主要分為三大部分
1. rtmp server: 安裝nginx-rtmp
2. push to rtmp: Adobe Flash Media Live Encoder 或是 ffmpeg
3. rtmp player: jwplayer
[安裝server]
nginx 是戰鬥民族出品的強大web server,我們必須要再加裝nginx-rtmp 模組才可以支援rtmp 串流
以CentOS 為例
wget https://copr.fedorainfracloud.org/coprs/lkiesow/nginx-rtmp/repo/epel-6/lkiesow-nginx-rtmp-epel-6.repo
yum install nginx-rtmp
以FreeBSD 為例
cd /usr/ports/www/nginx (勾選rtmp)
make install
設定檔範例
vi nginx.conf
#user nobody;
worker_processes 1;
error_log /var/log/rtmp_error.log debug;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
chunk_size 8192;
application rtmp {
#### 設定 access control
allow publish 192.168.2.13;
allow publish 10.0.0.0/24;
allow play all;
deny all;
live on;
#### 如果要複製一份影像到其他 rtmp server
meta copy;
push rtmp://rtmp02-server/rtmp/live;
push rtmp://rtmp03-server/rtmp/live;
}
}
}
[push to rtmp]
Adobe Flash Media Live Encoder 好處是跨平台、免費、GUI、方便外接攝影機訊號
ffmpeg 好處是方便在文字介面下透過指令推送
範例
ffmpeg -i video-file.mp4 -vcodec h264 -acodec aac -strict -2 -r 60.0 -s 1280x720 -b:a 100k -f flv rtmp://rtmp01-server/rtmp/live
[rmpt player]
至官網下載jwplayer
https://www.jwplayer.com/products/jwplayer/
範例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>stream playing~~</title>
<script src="jwplayer.js"></script>
<script>jwplayer.key = "Your Key ~~";</script>
</head>
<body>
<div id="player"></div>
<script>
jwplayer("player").setup({
sources: [{
file: "rtmp://rtmp01-server/rtmp/live"
}],
height: 360,
width: 640
});
</script>
</body>
</html>
一手掌握短小精悍的Nginx
作者: 高群凱
出版社:佳魁資訊
出版日期:2016/11/25
語言:繁體中文
定價:490元
留言列表