2016年8月18日12:42:35 參照官方文檔https://github.com/arut/nginx-rtmp-module/wiki/Directiveshtml
請注意這個是粗翻譯版,僅供參考,不是精校版 精校版後面纔會更新
目錄python
上下文能夠理解爲,默認配置文件或者參數,若是沒有就會報錯,由於每一個函數都需一些定義好的參數和傳入函數的參數,這個有些能夠少,可是有些是必須的linux
語法: rtmp { ... }
上下文: rootnginx
聲明RTMP服務器實例git
語法: listen (addr[:port]|port|unix:path) [bind] [ipv6only=on|off] [so_keepalive=on|off|keepidle:keepintvl:keepcnt|proxy_protocol]
上下文: server
添加監聽套接字NGINX接受RTMP鏈接
rtmp { server { } }
server {
listen 1935;
}github
語法: application name { ... }
上下文: serverweb
建立RTMP應用。不一樣於HTTP位置應用程序的名稱不能是一個模式。shell
server { listen 1935; application myapp { } }
語法:超時值
上下文:RTMP,服務器跨域
套接字超時。該值主要用於寫入。大多數時間RTMP模塊預計不會對除發行插座全部套接字的任何活動。若是你想斷插座獲得迅速斷開鏈接採用主動式工具,如保活或RTMP平。默認爲1分鐘。瀏覽器
timeout 60s;
語法: ping value
上下文: rtmp, server
RTMP ping間隔。零變爲平掉。 RTMP平是主動鏈接檢查的協議功能。一個特殊的數據包被髮送到遠程對等體和答覆有望與ping_timeout指令指定的超時時間內。
若是ping回覆未在此時間內收到而後關閉鏈接。平安默認值爲1分鐘。默認Ping超時是30秒。
ping 3m;
ping_timeout 30s;
ping_timeout
語法: ping_timeout value
上下文: rtmp, server
見上面ping的描述
語法: max_streams value
上下文: rtmp, server
設置RTMP流的最大數目。數據流被複用成一個單一的數據流。不一樣信道用於發送命令,音頻,視頻等的默認值是32,它一般是肯定爲許多狀況。
max_streams 32;
語法: ack_window value
上下文: rtmp, server
設置RTMP確認窗口的大小。它接收到的字節以後對等體應發送確認包到遠程側的次數。默認值是5000000。
ack_window 5000000;
語法: chunk_size value
上下文: rtmp, server
最大的塊的大小爲最大流複數。默認值是4096越大該值越低CPU開銷。這個值不能小於128。
chunk_size 4096;
語法: max_queue value
上下文: rtmp, server
照上面的語法習慣是這樣,官方平沒有給出文檔,應該是設置最大鏈接數的參數,具體想知道這個是作什麼的請參看源代碼
語法: max_queue value
上下文: rtmp, server
輸入數據消息的最大大小。全部輸入數據來源(成塊,並進一步)分紅的消息。的部分信息保存在內存中,而等待它完成。在理論上傳入消息能夠是很是大的,能夠是對於服務器的穩定性的問題。默認值是1M足夠許多狀況下。
max_message 1M;
語法: buflen time
上下文: rtmp, server
設置默認的緩衝區長度。一般客戶端發送播放前RTMP set_buflen命令並重置該設置。默認值是1000毫秒。
buflen 5S;
目前沒有文檔
目前沒有文檔
語法: allow [play|publish] address|subnet|all
上下文: rtmp, server, application
容許發佈/從指定的地址或全部地址播放。容許/拒絕指令出現的順序檢查。
allow publish 127.0.0.1; deny publish all; allow play 192.168.0.0/24; deny play all;
deny
語法: deny [play|publish] address|subnet|all
上下文: rtmp, server, application
參見allow
說明
語法: exec_push command arg*
上下文: rtmp, server, application
指定將公佈每個流執行帶參數的外部命令。當發佈中止處理結束。二進制完整路徑應指定爲第一個參數。沒有這個過程應該作的假設。然而,這功能與ffmpeg的對流轉換很是有用。
FFmpeg的應該鏈接到nginx的,RTMP做爲客戶端和輸出轉換流回到nginx的,RTMP做爲發行人。形式是$var / ${VAR}的可替換命令行中使用
$name - stream name
$app - application name
$addr - client address
$flashver - client flash version
$swfurl - client swf url
$tcurl - client tc url
$pageurl - client page url
shell風格重定向能夠exec_push指令指定寫入輸出和接收輸入。支持的是
truncating output >file
appending output >>file
descriptor redirects like 1>&2
input <file
確保有重定向字符和流名稱/編號之間沒有空格。
您能夠指定要執行的命令或短命令名的完整路徑。在後一種狀況下,二進制文件由PATH環境變量指定的目錄中查找。默認狀況下nginx的清除環境一般會使RTMP模塊只運行位於標準目錄如/ bin和/ USR / bin中的二進制文件。
爲了使這個老是工做,請保持原來的PATH變量值具備如下nginx的指令。
下面的ffmpeg的通話呼入轉碼流HLS就緒流(H264 / AAC)。 FFmpeg的應libx264&libfaac支持被編譯在這個例子中工做。
application src { live on; exec_push ffmpeg -i rtmp://localhost/src/$name -vcodec libx264 -vprofile baseline -g 10 -s 300x200 -acodec libfaac -ar 44100 -ac 1 -f flv rtmp://localhost/hls/$name 2>>/var/log/ffmpeg-$name.log; } application hls { live on; hls on; hls_path /tmp/hls; hls_fragment 15s; }
語法: exec_pull command arg*
上下文: rtmp, server, application
指定與要在打事件中執行參數外部命令。當第一個客戶端鏈接到該流,當最後一個斷開被殺害時,執行命令。該指令使得能夠在本地客戶端的任何格式拉遠程流。
該功能僅在單進程模式下可靠地工做。這樣作的緣由是,咱們不能確保外部進程始終鏈接到合適的工人。它顯然鏈接到一個隨機的。雖然這仍然會在大多數狀況下這不是一個建議的體系結構,這將是不穩定和可能出現bug。
指令參數是相同exec_push
application myapp { live on; exec_pull ffmpeg -i http://example.com/video_$name.ts -c copy -f flv rtmp://localhost/$app/$name; }
在上述配置exec_pull指令提供全部數據流。這致使遠程流名稱格式必定的侷限性。它應該可以利用現有的變量,好比$應用程序構建遠程URL,$app等。
當這是不可能的,你能夠添加指令exec_options容許設置在exec-family指令附加流選項。如今支持的惟一的選擇是名稱選項。
application myapp { live on; exec_options on; exec_pull ffmpeg -i http://example.com/tv1.ts -c copy -f flv rtmp://localhost/$app/$name name=mystream; exec_pull ffmpeg -i http://another.example.com/video_plus.ts -c copy -f flv rtmp://localhost/$app/$name name=anotherstream; }
語法: exec command arg*
上下文: rtmp, server, application
EXEC是exec_push的別名
語法: exec_options on|off
上下文: rtmp, server, application
該指令切換Exec選模式。當被激活時,你能夠添加一個exec家族指令選項。惟一支持的EXEC選項名稱。經過該選項,能夠應用EXEC只有指定的流。默認爲關閉狀態。
exec_options on;
# 調用on_publish只爲「mystream」
exec_publish http://localhost/on_publish name=mystream;
#調用on_play只爲「另外一個」
exec_play http://localhost/on_play name=another;
#執行不一樣的ffmpeg對不一樣的流
exec_pull http://example.com/abc.ts -c copy -f flv rtmp://localhost/$name/$app name=mystream;
exec_pull http://my.example.com/tele.ts -c copy -f flv rtmp://localhost/$name/$app name=tv;
exec_pull http://enother.example.com/hello/f.ts -c copy -f flv rtmp://localhost/$name/$app name=fun;
語法: exec_static command arg*
上下文: rtmp, server, application
相似給exec,但在運行nginx的啓動指定的命令。不支持替換,由於沒有session 環境。
exec_static ffmpeg -i http://example.com/video.ts -c copy -f flv rtmp://localhost/myapp/mystream;
exec_kill_signal
語法: exec_kill_signal signal
上下文: rtmp, server, application
exec_kill_signal term; exec_kill_signal usr1; exec_kill_signal 3;
語法: respawn on|off
上下文: rtmp, server, application
若是重生子進程打開的時候同時發佈仍然在它的終止。默認爲上;
respawn off;
語法: respawn_timeout timeout
上下文: rtmp, server, application
套重生超時開始新的子實例以前等待。默認值是5秒。
respawn_timeout 10s;
語法: exec_publish command arg*
上下文: rtmp, server, application
指定與參數外部命令要在發佈事件執行。返回代碼不進行分析。 EXEC的替換是同時支持在這裏。此外ARGS變量同意舉行查詢字符串參數。
語法: exec_play command arg*
上下文: rtmp, server, application
指定與要在打事件中執行參數外部命令。返回代碼不進行分析。替代列表和exec_publish相同
語法: exec_play_done command arg*
上下文: rtmp, server, application
指定與參數外部命令要在play_done事件執行。返回代碼不進行分析. 替代列表和exec_publish相同
語法: exec_publish_done command arg*
上下文: rtmp, server, application
指定與參數外部命令要在publish_done事件執行。返回代碼不進行分析. 替代列表和exec_publish相同
語法: exec_record_done command arg*
上下文: rtmp, server, application, recorder
指定錄音結束時要執行帶有參數的外部命令。 exec_publish的取代在這裏支持以及附加變量
recorder
- recorder namepath
- recorded file path (/tmp/rec/mystream-1389499351.flv
)filename
- path with directory omitted (mystream-1389499351.flv
)basename
- file name with extension omitted (mystream-1389499351
)dirname
- directory path (/tmp/rec
)例子
# 跟蹤客戶信息 exec_play bash -c "echo $addr $pageurl >> /tmp/clients"; exec_publish bash -c "echo $addr $flashver >> /tmp/publishers"; # 轉換錄製的文件格式的MP4 exec_record_done ffmpeg -y -i $path -acodec libmp3lame -ar 44100 -ac 1 -vcodec libx264 $dirname/$basename.mp4;
語法: live on|off
上下文: rtmp, server, application
切換現場模式,即一對多的廣播。
live on;
語法: meta on|copy|off
上下文: rtmp, server, application
集元數據發送模式。上的價值,使用戶收到一封包含像寬度,高度等的副本設定值,使客戶獲得出版商的元數據塊的精確副本,包括標準和具體領域的預約義字段重建的元數據包。關的值將關閉發送任何RTMP元數據給用戶。默認爲on。
meta copy;
語法: interleave on|off
上下文: rtmp, server, application
切換交錯模式。在這種模式下的音頻和視頻數據上相同的RTMP塊流傳輸。默認爲off。
interleave on;
語法: wait_key on|off
上下文: rtmp, server, application
使視頻流開始一個關鍵幀。默認爲關閉。
wait_key on;
語法: wait_video on|off
上下文: rtmp, server, application
直到第一個視頻幀發送禁用音頻。默認爲關閉。能夠用wait_key決定相結合,使客戶端接收視頻關鍵幀但其後全部其餘數據。然而,這一般會增長鏈接延遲。你能夠在你的編碼器,以減小延遲調整關鍵幀間隔
IE瀏覽器的最新版本須要這個選項正常播放啓用。
wait_video on;
語法: publish_notify on|off
上下文: rtmp, server, application
發送NetStream.Play.PublishNotify和NetStream.Play.UnpublishNotify給用戶。默認爲關閉。
publish_notify on;
語法: drop_idle_publisher timeout
上下文: rtmp, server, application
丟棄在指定時間內發行者鏈接這一直空閒(無音頻/視頻數據)。默認是關閉的。注意:這隻能當鏈接處於發佈模式(發送發佈命令後)。
drop_idle_publisher 10s;
語法: sync timeout
上下文: rtmp, server, application
同步的音頻和視頻流。若是訂戶帶寬不夠以接收發布速率數據,某些幀被服務器丟棄。這將致使同步問題。當時間戳差值超過指定爲同步參數的值絕對幀發送固定的。默認爲300ms。
sync 10ms;
語法: play_restart on|off
上下文: rtmp, server, application
若是啓用nginx的,RTMP發送NetStream.Play.Start和NetStream.Play.Stop到每一個用戶每次發行啓動或中止發佈。若是禁用每一個用戶只在開始和重放結束接收這些通知。默認是off。
play_restart off;
語法: idle_streams on|off
上下文: rtmp, server, application
若是禁用nginx的,RTMP防止鏈接到空閒/不存在的實時流用戶,斷開全部用戶的數據流時,斷開publisher。默認爲on。
idle_streams off;
語法: record [off|all|audio|video|keyframes|manual]*
上下文: rtmp, server, application, recorder
切換錄音模式。流能夠被記錄在FLV文件。該指令指定正是應記錄哪些:
能夠有鍵,在一個記錄指令任何相容組合。
record all; record audio keyframes;
語法: record_path path
上下文: rtmp, server, application, recorder
指定將錄製的FLV文件來記錄路徑。
record_path /tmp/rec;
語法: record_suffix value
上下文: rtmp, server, application, recorder
設置記錄文件的後綴。默認爲'。FLV「。
record_suffix _recorded.flv;
記錄後綴能夠是的strftime格式的模式。下面的指令
record_suffix -%d-%b-%y-%T.flv;
將產生的形式mystream-24-Apr-13-18:23:38.flv 全部支持的strftime格式選項能夠的strftime手冊頁上找到。
語法: record_unique on|off
上下文: rtmp, server, application, recorder
若是打開追加當前的時間戳,以錄製的文件。不然,一樣的文件,每次新的記錄發生重寫。默認是關閉的
record_unique on;
語法: record_append on|off
上下文: rtmp, server, application, recorder
切換文件追加模式。當錄音機打開追加新數據舊文件或建立它時,它的缺失。有舊的數據,並在文件中的新數據之間不存在時間間隙。默認是關閉的。
record_append on;
語法: record_lock on|off
上下文: rtmp, server, application, recorder
當打開當前記錄的文件被鎖住的fcntl調用。這能夠從其餘地方進行檢查,以找出正在錄製的文件。默認是關閉的。
record_lock on;
在FreeBSD上可使用的羊羣工具來檢查。在Linux上的flock
和fcntl是無關的,因此你只剩下編寫一個簡單的腳本文件檢查鎖定狀態。下面是這種腳本isunlocked.py的一個例子。
#!/usr/bin/python import fcntl, sys sys.stderr.close() fcntl.lockf(open(sys.argv[1], "a"), fcntl.LOCK_EX|fcntl.LOCK_NB)
語法: record_max_size size
上下文: rtmp, server, application, recorder
設置最大記錄文件大小
record_max_size 128K;
語法: record_max_frames nframes
上下文: rtmp, server, application, recorder
設置每一個錄像文件的視頻幀的最大數量。
record_max_frames 2;
語法: record_interval time
上下文: rtmp, server, application, recorder
從新啓動該數字(毫)秒後拍攝。默認關閉。零表示記錄之間沒有延遲。若是record_unique是關閉的,那麼全部的記錄片斷被寫入到同一個文件。不然,時間戳就會追加這使得文件不一樣(由於record_interval大於1秒以上)。
record_interval 1s; record_interval 15m;
語法: recorder name {...}
上下文: application
建立記錄塊。多個刻錄機能夠withing單一的應用程序來建立。全部上述記錄相關指令能夠在記錄{}塊中指定。全部的設置是從更高層次繼承。
application { live on; # default recorder record all; record_path /var/rec; recorder audio { record audio; record_suffix .audio.flv; } recorder chunked { record all; record_interval 15s; record_path /var/rec/chunked; } }
語法: record_notify on|off
上下文: rtmp, server, application, recorder
切換髮送NetStream.Record.Start和NetStream.Record.Stop狀態信息(的onStatus),以發行時的具體記錄開始或中止錄音文件。狀態描述字段保存記錄的域名(空默認記錄器)。默認關閉。
recorder myrec { record all manual; record_path /var/rec; record_notify on; }
語法: play dir|http://loc [dir|http://loc]*
上下文: rtmp, server, application
從指定目錄或HTTP位置播放FLV或MP4文件。若是參數前綴以http://那麼假定文件應該從遠程HTTP位置播放前下載。注意打不啓動,直到整個文件下載。您可使用nginx的本地緩存本地計算機上的文件。
多個播放位置能夠在一個單一的播放指令指定。當多個播放指令指定的位置列被合併,並從更高的做用域繼承。發揮每一個位置試圖直到成功定位被發現。若是沒有找到這樣的位置錯誤狀態被髮送到客戶端
索引FLV是爲了隨機搜索能力。未編入索引FLV是玩謀求/暫停禁用(僅重啓動模式)。使用的FLV索引(例如,yamdi)索引。
若是您播放錄製的記錄指令FLV文件,請不要打前忘記他們的索引。在建立未編入索引。
若是視頻和音頻編解碼器是由RTMP支持的mp4文件只能播放。最多見的狀況是H264 / AAC。
application vod { play /var/flvs; } application vod_http { play http://myserver.com/vod; } application vod_mirror { # try local location first, then access remote location play /var/local_mirror http://myserver.com/vod; }
播放 /var/flvs/dir/file.flv:
ffplay rtmp://localhost/vod//dir/file.flv
VOD後的兩條斜線使ffplay使用VOD和應用程序名稱和URL做爲playpath的其他部分。
語法: play_temp_path dir
上下文: rtmp, server, application
設置將在其中遠程VOD播文件的播放以前存儲位置。默認值是/ tmp;
play_temp_path /www; play http://example.com/videos;
語法: play_local_path dir
上下文: rtmp, server, application
設置從哪裏目錄play_temp_path複製遠程點播文件,他們徹底下載後的位置。空值禁用該功能。默認狀況下它是空的。該特徵可用於在本地緩存遠程文件。
此路徑應該是相同的裝置,play_temp_path上。
# 在/tmp/videos上搜索文件
# 若是沒有找到就找遠程的location上尋找
# 並且儲存在/tmp/videos
play_local_path /tmp/videos;
play /tmp/videos http://example.com/videos;
語法: pull url [key=value]*
上下文: application
Creates pull relay. Stream is pulled from remote machine and becomes available locally. It only happens when at least one player is playing the stream locally.
建立拉流中繼 ,流從遠程計算機上拉,而且成爲本地可用。它僅當至少一個播放流正在玩本地流發生。
Url syntax: [rtmp://]host[:port][/app[/playpath]]
.
若是應用程序丟失,則使用本地應用程序的名稱。若是playpath缺乏那麼當前流的名字來代替。
如下參數被支持:
If a value for a parameter contains spaces then you should use quotes around the WHOLEkey=value pair like this : 'pageUrl=FAKE PAGE URL'
.
若是參數的值包含空格,那麼你應該使用引號圍繞整個key = value對這樣的:'pageUrl=FAKE PAGE URL「。
pull rtmp://cdn.example.com/main/ch?id=12563 name=channel_a; pull rtmp://cdn2.example.com/another/a?b=1&c=d pageUrl=http://www.example.com/video.html swfUrl=http://www.example.com/player.swf live=1; pull rtmp://cdn.example.com/main/ch?id=12563 name=channel_a static;
語法: push url [key=value]*
上下文: application
推進具備相同的語法拉動。不像推拉指令發佈流遠程服務器。
語法: push_reconnect time
上下文: rtmp, server, application
從新鏈接超時以前等待的推後斷開鏈接。默認設置爲3秒。
push_reconnect 1s;
語法: session_relay on|off
上下文: rtmp, server, application
切換會話中繼模式。在這種模式下中繼當鏈接關閉時被破壞。當設置爲關閉時,流關閉,使得其餘的中繼也可能會被之後建立的繼電器被破壞。默認是關閉的。
session_relay on;
語法: on_connect url
上下文: rtmp, server
設置HTTP鏈接的回調。當客戶端鏈接問題的命令HTTP請求是異步發出命令和處理被掛起,直到它返回結果代碼。若是返回HTTP 2XX代碼,而後RTMP會話繼續。
3XX的代碼使RTMP重定向到另外一個應用程序的名字是從位置HTTP響應頭拍攝。不然,鏈接被丟棄。
注意:這個指令不該用範圍容許的,由於應用還處於鏈接階段不明。
HTTP請求接收多個參數。 POST方法用於application/x-www-form-urlencoded MIME type ,下面的參數被傳遞給調用者:
除了上述項目明確地傳遞給connect命令的全部參數也與回調發送。您應當區分鏈接參數從播放/發佈參數。玩家一般具備播放/流發佈名設置鏈接字符串分開的一種特殊方式。做爲一個例子下面是這些參數是如何在JWPlayer設置
... streamer: "rtmp://localhost/myapp?connarg1=a&connarg2=b", file: "mystream?strarg1=c&strarg2=d", ...
Ffplay (with librtmp) example
ffplay "rtmp://localhost app=myapp?connarg1=a&connarg2=b playpath=mystream?strarg1=c&strarg2=d"
Usage example
on_connect http://example.com/my_auth;
Redirect example
location /on_connect { if ($arg_flashver != "my_secret_flashver") { rewrite ^.*$ fallback? permanent; } return 200; }
語法: on_play url
上下文: rtmp, server, application
Sets HTTP play callback. Each time a clients issues play command an HTTP request is issued asynchronously and command processing is suspended until it returns result code. HTTP result code is then analyzed.
重定向的例如
http { ... location /local_redirect { rewrite ^.*$ newname? permanent; } location /remote_redirect { # no domain name here, only ip rewrite ^.*$ rtmp://192.168.1.123/someapp/somename? permanent; } ... } rtmp { ... application myapp1 { live on; # stream will be redirected to 'newname' on_play http://localhost:8080/local_redirect; } application myapp2 { live on; # stream will be pulled from remote location # requires nginx >= 1.3.10 on_play http://localhost:8080/remote_redirect; } ... }
HTTP請求接收多個參數。 POST方法用於application/x-www-form-urlencoded MIME type. 。下面的參數被傳遞給調用者:
除了上述項目經過明確玩命令的全部參數也與回調發送。
例如,若是流與URL訪問 rtmp://localhost/app/movie?a=100&b=face&foo=bar
then a
, b
& foo
也會被髮送回來
on_play http://example.com/my_callback;
語法: on_publish url
上下文: rtmp, server, application
上面這個指令設置了發佈命令回調,惟一的區別同樣on_play。代替遠程拉推在這種狀況下進行的。
語法: on_done url
上下文: rtmp, server, application
設置 play/publish 終止回調。上述全部適用於此。然而HTTP狀態代碼不檢查此回調。
語法: on_play_done url
上下文: rtmp, server, application
和 on_done 同樣的行爲
但只做用於 play和 event
語法: on_publish_done url
上下文: rtmp, server, application
相同的行爲on_done 但只做用於 publish 和 event
語法: on_record_done url
上下文: rtmp, server, application, recorder
設置record_done回調。除了常見的HTTP回調變量它接收到如下值
Example
on_record_done http://example.com/recorded;
語法: on_update url
上下文: rtmp, server, application
Set update callback. This callback is called with period of notify_update_timeout
. If a request returns HTTP result other than 2xx connection is terminated. This can be used to synchronize expired sessions. Two additional arguments time
and timestamp
are passed to this handler:
設置更新回調。此回調調用notify_update_timeout的時期。若是請求返回比2XX鏈接其餘HTTP結果被終止。這可用於同步過時會話。另外兩個參數的 時間和時間戳 傳遞到該處理程序
time
從 play/publish 回調開始的時間timestamp
is RTMP timestamp of the last audio/video packet sent to the client 發送到客戶端的最後的音頻/視頻分組的RTMP時間戳您可使用時間戳參數單獨限制播放時長爲每一個用戶。
on_update http://example.com/update;
語法: notify_update_timeout timeout
上下文: rtmp, server, application
集on_update回調之間超時。默認值是30秒。
notify_update_timeout 10s; on_update http://example.com/update;
語法: notify_update_strict on|off
上下文: rtmp, server, application
對於切換回調on_update嚴格模式。默認是關閉的。當全部的鏈接錯誤打開,超時以及HTTP分析錯誤和空的反應被視爲更新失敗,並致使鏈接終止。當關閉惟一有效的HTTP響應代碼等的2XX致使失敗。
notify_update_strict on; on_update http://example.com/update;
語法: notify_relay_redirect on|off
上下文: rtmp, server, application
啓用對on_play和on_publish遠程重定向本地流重定向。新的流名字是用於遠程重定向RTMP網址的MD5哈希值。默認是關閉的。
notify_relay_redirect on;
語法: notify_method get|post
上下文: rtmp, server, application, recorder
設置通知的HTTP方法。默認值是POST與 application/x-www-form-urlencoded content type.在某些狀況下獲得的是可取的,例如,若是您打算處理Nginx的HTTP {}部分呼叫。在這種狀況下,你可使用arg_*變量訪問參數。
notify_method get;
在HTTP GET方法處理 http{}部分能夠作這樣
location /on_play { if ($arg_pageUrl ~* localhost) { return 200; } return 500; }
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
語法: hls on|off
上下文: rtmp, server, application
切換HLS上的應用。
hls on; hls_path /tmp/hls; hls_fragment 15s;
在HTTP {}部分客戶打HLS設置如下的位置。
http { ... server { ... location /hls { types { application/vnd.apple.mpegurl m3u8; } root /tmp; add_header Cache-Control no-cache; # 爲了不與跨域的HTTP請求(例如,在開發過程當中)的問題 add_header Access-Control-Allow-Origin *; } } }
語法: hls_path path
上下文: rtmp, server, application
設置HLS播放列表和片斷目錄。若是該目錄不存在,將會被建立。
語法: hls_fragment time
上下文: rtmp, server, application
設置HLS片斷長度。默認爲5秒。
語法: hls_playlist_length time
上下文: rtmp, server, application
設置播放列表HLS長度。默認爲30秒。
hls_playlist_length 10m;
語法: hls_sync time
上下文: rtmp, server, application
Sets HLS timestamp synchronization threshold. Default is 2ms. This feature prevents crackling noises after conversion from low-resolution RTMP (1KHz) to high-resolution MPEG-TS (90KHz).
設置HLS時間戳同步的門檻。默認爲2ms。此功能能夠防止噼啪的噪聲從低分辨率RTMP(1KHz的)轉換爲高分辨率MPEG-TS(90KHz的)以後。
hls_sync 100ms;
語法: hls_continuous on|off
上下文: rtmp, server, application
切換HLS連續模式。在這種模式下HLS序列號從它中止了最後一次啓動。舊片斷依然古色古香。默認是關閉的。
hls_continuous on;
語法: hls_nested on|off
上下文: rtmp, server, application
切換HLS嵌套模式。在這種模式下hls_path的子目錄爲每一個數據流建立。播放列表和片斷在子目錄中建立。默認是關閉的。
hls_nested on;
語法: hls_base_url url
上下文: rtmp, server, application
設置HLS播放列表項基本URL。當空這些項目沒有前綴而且假設是在相同的位置父播放列表或低一個級別時使用hls_nested。此功能同時適用於主(變量)和從HLS播放列表。它可讓你下載播放列表,由於它包含兒童播放列表或片斷徹底引用本地播放。默認爲空。
hls_base_url http://myserver.com/hls/;
語法: hls_cleanup on|off
上下文: rtmp, server, application
切換HLS清理。默認狀況下,該功能已開啓。在這種模式下nginx的緩存管理器進程會刪除HLS目錄老HLS片斷和播放列表。
hls_cleanup off;
語法: hls_fragment_naming sequential|timestamp|system
上下文: rtmp, server, application
設置片斷的命名方式
默認值是連續的
hls_fragment_naming system;
語法: hls_fragment_naming_granularity number
上下文: rtmp, server, application
設置HLS片斷IDS粒度。若是大於零,改變IDS來劃分提供的價值。默認值是零。
# use system time rounded to 500ms as fragment names hls_fragment_naming system; hls_fragment_naming_granularity 500;
語法: hls_fragment_slicing plain|aligned
上下文: rtmp, server, application
設置片斷切片模式。
默認值是 plain.
hls_fragment_slicing aligned;
語法: hls_variant suffix [param*]
上下文: rtmp, server, application
添加HLS變項(variant entry 變量條目,翻譯不許確)。當後綴是在流名稱匹配,而後,對用hls_variant指示當前應用程序中指定的全部條目當前流建立播放列表中的變體。不帶後綴名剝離用做變量流名稱。原來的流像往常同樣處理。
如下後綴可選參數追加到播放列表M3U8 EXT-X-STREAM-INF。見HLS規範。 3.3.10。 EXT-X-STREAM-INF支持的參數的完整列表。
rtmp { server { listen 1935; application src { live on; exec ffmpeg -i rtmp://localhost/src/$name -c:a libfdk_aac -b:a 32k -c:v libx264 -b:v 128K -f flv rtmp://localhost/hls/$name_low -c:a libfdk_aac -b:a 64k -c:v libx264 -b:v 256k -f flv rtmp://localhost/hls/$name_mid -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 512K -f flv rtmp://localhost/hls/$name_hi; } application hls { live on; hls on; hls_path /tmp/hls; hls_nested on; hls_variant _low BANDWIDTH=160000; hls_variant _mid BANDWIDTH=320000; hls_variant _hi BANDWIDTH=640000; } } }
語法: hls_type live|event
上下文: rtmp, server, application
將X-PLAYLIST型播放列表指令指定HLS播放列表類型。直播HLS流一般是從當前實際位置是幾個片斷到播放列表的末尾播放。事件HLS流老是從播放開始播放。當事件模式確保播放列表的長度足以讓整個事件。默認值是live
;
hls_type event;
語法: hls_keys on|off
上下文: rtmp, server, application
啓用HLS加密。 AES-128的方法用來加密整個HLS片斷。默認關閉。
hls_keys on;
下面是一個使用HLS加密示例配置。此配置要求nginx的與--with-http_ssl_module建爲HTTPS支持。
... http { ... server { listen 443 ssl; server_name example.com; ssl_certificate /var/ssl/example.com.cert; ssl_certificate_key /var/ssl/example.com.key; location /keys { root /tmp; } } server { listen 80; server_name example.com; location /hls { root /tmp; } } } rtmp { server { listen 1935; application myapp { live on; hls on; hls_path /tmp/hls; hls_keys on; hls_key_path /tmp/keys; hls_key_url https://example.com/keys/; hls_fragments_per_key 10; } } }
語法: hls_key_path path
Context: rtmp, server, application
設置將在其中自動生成HLS密鑰保存的目錄。密鑰文件與在OpenSSL RAND_bytes()例行程序建立的.key延伸和僞隨機的16字節的內容。若是該目錄不存在,它在運行時建立的。默認狀況下,hls_path目錄用於密鑰文件。可是請記住,你一般應該限制訪問關鍵文件,這是容易當這些文件從播放列表和片斷分開存放。
hls_key_path /tmp/keys;
語法: hls_key_url url
上下文: rtmp, server, application
設置HLS密鑰文件條目的URL。當空這些項目沒有前綴和密鑰被認爲是在相同的位置播放列表。默認爲空
hls_key_url https://myserver.com/keys/;
用上述設定例的播放列表條目
#EXT-X-KEY:METHOD=AES-128,URI="https://myserver.com/keys/337.key",IV=0x00000000000000000000000000000151
語法: hls_fragments_per_key value
上下文: rtmp, server, application
設置具備相同的密鑰加密的HLS片斷的數目。零意味着只有一個密鑰的發佈開始建立,並在會話中的全部片斷與此密鑰加密。默認值是零。
hls_fragments_per_key 10;
語法: dash on|off
上下文: rtmp, server, application
應用程序切換MPEG-DASH。
dash on; dash_path /tmp/dash; dash_fragment 15s;
在HTTP {}部分設置如下的位置,爲客戶播放MPEG-DASH。
http { ... server { ... location /dash { root /tmp; add_header Cache-Control no-cache; # #爲了不與跨域的HTTP請求(例如,在開發過程當中)的問題 add_header Access-Control-Allow-Origin *; } } }
語法: dash_path path
上下文: rtmp, server, application
設置MPEG-DASH播放列表,片斷目錄。若是該目錄不存在,它將被建立。
語法: dash_fragment time
上下文: rtmp, server, application
設置MPEG-DASH片斷長度。默認爲5秒。
語法: dash_playlist_length time
上下文: rtmp, server, application
設置MPEG-DASH播放列表的長度。默認爲30秒。
dash_playlist_length 10m;
語法: dash_nested on|off
上下文: rtmp, server, application
切換MPEG-DASH嵌套模式。在這種模式下dash_path的子目錄爲每一個數據流建立。播放列表和片斷在子目錄中建立。默認是關閉的。
dash_nested on;
語法: dash_cleanup on|off
上下文: rtmp, server, application
切換MPEG-DASH清理。默認狀況下,該功能已開啓。在這種模式下nginx的緩存管理器進程從MPEG-DASH目錄中刪除舊的MPEG-DASH碎片和體現。流清單被刪除後,初始化片斷被刪除。
dash_cleanup off;
語法: access_log off|path [format_name]
上下文: rtmp, server, application
設置訪問日誌參數。日誌默認狀況下開啓。要關閉它使用ACCESS_LOG關閉指令。默認狀況下訪問日誌記錄是爲了同一個文件的HTTP訪問記錄器(log/ access.log)。您能夠指定訪問日誌指令另外一個日誌文件的路徑。第二個參數是可選的。它可用於經過名稱來指定記錄格式。見log_format指令有關格式的詳細信息。
log_format new '$remote_addr'; access_log logs/rtmp_access.log new; access_log logs/rtmp_access.log; access_log off;
語法: log_format format_name format
上下文: rtmp
建立一個名爲日誌格式。日誌格式看起來很是相同的nginx的HTTP日誌格式。幾個變量的日誌格式中支持:
connection
- connection numberremote_addr
- client addressapp
- application namename
- last stream nameargs
- last stream play/publish argumentsflashver
- client flashVerswfurl
- client swfUrltcurl
- client tcUrlpageurl
- client pageUrlcommand
- play/publish commands sent by client: NONE
, PLAY
, PUBLISH
, PLAY+PUBLISH
bytes_sent
- number of bytes sent to clientbytes_received
- number of bytes received from clienttime_local
- local time at the end of client connectionsession_time
- connection duration in secondssession_readable_time
- connection duration in human-readable formatmsec
- current unix timestamp in SEC.MSEC format默認的日誌格式有名稱相結合。下面是這種格式的定義
$remote_addr [$time_local] $command "$app" "$name" "$args" - $bytes_received $bytes_sent "$pageurl" "$flashver" ($session_readable_time)
語法: max_connections number
上下文: rtmp, server, application
設置RTMP發動機的最大鏈接數。默認關閉
max_connections 100;
統計模塊是不一樣於此處列出的全部其餘模塊NGINX HTTP模塊。所以,統計指令應位於HTTP {}塊以內
語法: rtmp_stat all
上下文: http, server, location
設置RTMP統計處理當前的HTTP位置。 RTMP統計是動態的XML文檔。要觀看在瀏覽器XHTML頁面使用rtmp_stat_stylesheet指令這份文件。
http { server { location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { root /path/to/stat/xsl/file; } } }
語法: rtmp_stat_stylesheet path
上下文: http, server, location
添加XML樣式表引用統計XML,使其在瀏覽器查看。見rtmp_stat說明和示例的詳細信息。
多進程直播經過推流剩餘nginx的工人執行。
語法: rtmp_auto_push on|off
上下文: root
切換自動推(多進程直播)模式。默認是關閉的。
語法: rtmp_auto_push_reconnect timeout
上下文: root
設置自動推送從新鏈接超時,當工做進程被殺害。默認值是100毫秒。
語法: rtmp_socket_dir dir
上下文: root
設置用於流推進UNIX域套接字目錄。默認值是/ tmp。
rtmp_auto_push on; rtmp_auto_push_reconnect 1s; rtmp_socket_dir /var/sock; rtmp { server { listen 1935; application myapp { live on; } } }
控制模塊是HTTP模塊,這使得它能夠從使用HTTP協議以外的控制設rtmp模塊。下面是如何使能控制一個例子。
http { ... server { listen 8080; server_name localhost; .... location /control { rtmp_control all; } } }
有控制模塊內的幾個子模塊的每一個控制不一樣的功能。
該子模塊啓動和中止與手動標誌建立記錄。語法:
http://server.com/control/record/start|stop?srv=SRV&app=APP&name=NAME&rec=REC
SRV = SRV - 可選的服務器{}塊RTMP {}塊中號,默認爲第一個服務器{}塊
應用= APP - 所需的應用程序名稱
NAME =名稱 - 須要流名稱
REC = REC - 可選的記錄名稱,默認爲根(未命名)記錄
用下面的命令發佈該流
ffmpeg -i http://someserver.com/mychannel.ts -c:v copy -c:a nellymoser -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystream
使用下面的命令來啓動和中止錄音rtmp { server { listen 1935; application myapp { live on; recorder rec1 { record all manual; record_suffix all.flv; record_path /tmp/rec; record_unique on; } } } }
curl "http://localhost:8080/control/record/start?app=myapp&name=mystream&rec=rec1"
curl "http://localhost:8080/control/record/stop?app=myapp&name=mystream&rec=rec1"
若是記錄開始/中止請求有時會返回什麼都沒有,你應該檢查,若是你使用多進程,單個進程的比較好
刪除 drop
該子模塊提供了一種簡單的方法來刪除客戶端鏈接。語法:
http://server.com/control/drop/publisher|subscriber|client?srv=SRV&app=APP&name=NAME&addr=ADDR&clientid=CLIENTID
srv, app, name -相同
addr - 可選的客戶端地址(一樣由rtmp_stat返回)
clientid - 可選nginx的客戶端ID(日誌和統計顯示)
第一種方法 刪除/發佈者 發行降低的鏈接。第二方法是 刪除或者客戶端刪除,若是沒有指定地址每鏈接匹配addr參數或全部客戶端(包括出版商)。
curl http://localhost:8080/control/drop/publisher?app=myapp&name=mystream curl http://localhost:8080/control/drop/client?app=myapp&name=mystream curl http://localhost:8080/control/drop/client?app=myapp&name=mystream&addr=192.168.0.1 curl http://localhost:8080/control/drop/client?app=myapp&name=mystream&clientid=1
重定向播放/客戶端發佈到一個新的數據流。語法:
http://server.com/control/redirect/publisher|subscriber|client?srv=SRV&app=APP&name=NAME&addr=ADDR&clientid=CLIENTID&newname=NEWNAME
srv, app, name, addr, clients - 和上面相同
newname - 新的流名重定向到