视频直播点播nginx-rtmp开发手册中文版
參照官方文檔https://github.com/arut/nginx-rtmp-module/wiki/Directives
自己做的翻譯版,參照網(wǎng)上一些版本,就一些專業(yè)詞匯做了校正?目錄
- 核心
- rtmp
- server
- listen
- application
- timeout
- ping
- ping_timeout
- max_streams
- ack_window
- chunk_size
- max_queue
- max_message
- buflen
- out_queue
- out_cork
- 訪問(wèn)權(quán)限
- allow
- deny
- exec_push
- exec_pull
- exec
- exec_options
- exec_static
- exec_kill_signal
- respawn
- respawn_timeout
- exec_publish
- exec_play
- exec_play_done
- exec_publish_done
- exec_record_done
- 直播
- live
- meta
- interleave
- wait_key
- wait_video
- publish_notify
- drop_idle_publisher
- sync
- play_restart
- idle_streams
- 錄像
- record
- record_path
- record_suffix
- record_unique
- record_append
- record_lock
- record_max_size
- record_max_frames
- record_interval
- recorder
- record_notify
- 視頻點(diǎn)播
- play
- play_temp_path
- play_local_path
- 中繼
- pull
- push
- push_reconnect
- session_relay
- 通知
- on_connect
- on_play
- on_publish
- on_done
- on_play_done
- on_publish_done
- on_record_done
- on_update
- notify_update_timeout
- notify_update_strict
- notify_relay_redirect
- notify_method
- HLS協(xié)議
- hls
- hls_path
- hls_fragment
- hls_playlist_length
- hls_sync
- hls_continuous
- hls_nested
- hls_base_url
- hls_cleanup
- hls_fragment_naming
- hls_fragment_naming_granularity
- hls_fragment_slicing
- hls_variant
- hls_type
- hls_keys
- hls_key_path
- hls_key_url
- hls_fragments_per_key
- MPEG-DASH(HTTP動(dòng)態(tài)自適應(yīng)流媒體)
- dash
- dash_path
- dash_fragment
- dash_playlist_length
- dash_nested
- dash_cleanup
- 訪問(wèn)日志
- access_log
- log_format
- Limits 限制
- max_connections
- 數(shù)據(jù)統(tǒng)計(jì)
- rtmp_stat
- rtmp_stat_stylesheet
- Multi-worker live streaming ?多線程直播流
- rtmp_auto_push
- rtmp_auto_push_reconnect
- rtmp_socket_dir
- Control ?控制模塊
- rtmp_control
?
?
上下文可以理解為,默認(rèn)配置文件或者參數(shù),如果沒(méi)有就會(huì)報(bào)錯(cuò),因?yàn)槊總€(gè)函數(shù)都需一些定義好的參數(shù)和傳入函數(shù)的參數(shù),這個(gè)有些可以少,但是有些是必須的
核心
語(yǔ)法: rtmp { ... }
上下文: root
?聲明RTMP服務(wù)器實(shí)??例
rtmp {server {} }語(yǔ)法: listen (addr[:port]|port|unix:path) [bind] [ipv6only=on|off] [so_keepalive=on|off|keepidle:keepintvl:keepcnt|proxy_protocol] 上下文: server添加監(jiān)聽(tīng)套接字NGINX接受RTMP連接server {
listen 1935;
}
application
語(yǔ)法:?application name { ... }
上下文: server
創(chuàng)建RTMP應(yīng)用。不同于HTTP位置應(yīng)用程序的名稱不能是一個(gè)模式。
server {listen 1935;application myapp {} }?
?
timeout 超時(shí)
語(yǔ)法:超時(shí)值
上下文:RTMP,服務(wù)器
?套接字超時(shí)。該值主要用于寫入。大多數(shù)時(shí)間RTMP模塊預(yù)計(jì)不會(huì)對(duì)除發(fā)行插座所有套接字的任何活動(dòng)。如果你想斷插座得到迅速斷開(kāi)連接采用主動(dòng)式工具,如?;罨騌TMP平。默認(rèn)為1分鐘。
?timeout 60s;
?
ping
?
語(yǔ)法: ping value
上下文: rtmp, server
?RTMP ping間隔。零變?yōu)槠降簟?RTMP平是主動(dòng)連接檢查的協(xié)議功能。一個(gè)特殊的數(shù)據(jù)包被發(fā)送到遠(yuǎn)程對(duì)等體和答復(fù)有望與ping_timeout指令指定的超時(shí)時(shí)間內(nèi)。
如果ping回復(fù)未在此時(shí)間內(nèi)收到然后關(guān)閉連接。平安默認(rèn)值為1分鐘。默認(rèn)Ping超時(shí)是30秒。
ping 3m;
ping_timeout 30s;
ping_timeout
?
ping_timeout
語(yǔ)法:?ping_timeout value
上下文: rtmp, server
見(jiàn)上面ping的描述
?
?max_streams 單一流數(shù)據(jù)最大限制
語(yǔ)法: max_streams value
上下文: rtmp, server
設(shè)置RTMP流的最大數(shù)目。數(shù)據(jù)流被復(fù)用成一個(gè)單一的數(shù)據(jù)流。不同信道用于發(fā)送命令,音頻,視頻等的默認(rèn)值是32,它通常是確定為許多情況。
max_streams 32;
?
ack_window?
語(yǔ)法: ack_window value
上下文: rtmp, server
?設(shè)置RTMP確認(rèn)窗口的大小。它接收到的字節(jié)之后對(duì)等體應(yīng)發(fā)送確認(rèn)包到遠(yuǎn)程側(cè)的次數(shù)。默認(rèn)值是5000000。
ack_window 5000000;
?
chunk_size 數(shù)據(jù)塊大小
語(yǔ)法:?chunk_size value
上下文: rtmp, server
最大的塊的大小為最大流復(fù)數(shù)。默認(rèn)值是4096越大該值越低CPU開(kāi)銷。這個(gè)值不能小于128。
chunk_size 4096;
max_queue 最大隊(duì)列數(shù)
語(yǔ)法:?max_queue?value
上下文: rtmp, server
照上面的語(yǔ)法習(xí)慣是這樣,官方平?jīng)]有給出文檔,應(yīng)該是設(shè)置最大連接數(shù)的參數(shù),具體想知道這個(gè)是做什么的請(qǐng)參看源代碼
?
max_message
語(yǔ)法: max_queue value
上下文: rtmp, server
輸入數(shù)據(jù)消息的最大大小。所有輸入數(shù)據(jù)來(lái)源(成塊,并進(jìn)一步)分成的消息。的部分信息保存在內(nèi)存中,而等待它完成。在理論上傳入消息可以是非常大的,可以是對(duì)于服務(wù)器的穩(wěn)定性的問(wèn)題。默認(rèn)值是1M足夠許多情況下。
max_message 1M;
?
buflen 緩沖區(qū)
語(yǔ)法: buflen time
上下文: rtmp, server
?
設(shè)置默認(rèn)的緩沖區(qū)長(zhǎng)度。通??蛻舳税l(fā)送播放前RTMP set_buflen命令并重置該設(shè)置。默認(rèn)值是1000毫秒。
buflen 5S;
out_queue
目前沒(méi)有文檔
out_cork
目前沒(méi)有文檔
?
?
Access 訪問(wèn)控制
allow
語(yǔ)法: allow [play|publish] address|subnet|all
上下文: rtmp, server, application
允許發(fā)布/從指定的地址或所有地址播放。允許/拒絕指令出現(xiàn)的順序檢查。
?
allow publish 127.0.0.1; deny publish all; allow play 192.168.0.0/24; deny play all;deny
語(yǔ)法: deny [play|publish] address|subnet|all
上下文: rtmp, server, application
參見(jiàn)allow說(shuō)明
?
Exec
exec_push
?
?
語(yǔ)法: exec_push command arg*
上下文: rtmp, server, application
?
指定帶參數(shù)的外部命令在發(fā)布每一條流時(shí)。當(dāng)發(fā)布停止時(shí)結(jié)束處理程序。二進(jìn)制完整路徑應(yīng)指定為第一個(gè)參數(shù)。這里沒(méi)有任何假設(shè)關(guān)于這個(gè)進(jìn)程必須做什么。然而,這功能對(duì)ffmpeg的流轉(zhuǎn)碼非常有用。
FFmpeg作為一個(gè)客戶端連接到nginx-RTMP并且作為發(fā)布者輸出轉(zhuǎn)碼后的流到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風(fēng)格的重定向可以使用exec_push指令指定寫入輸出和接收輸入。支持如下
- truncating output?>file
- appending output?>>file
- descriptor redirects like?1>&2
- input?<file
確保重定向字符和流名稱/編號(hào)之間沒(méi)有空格。
?
您可以指定要執(zhí)行的命令的全局路徑或短命令名。在后一種情況下,二進(jìn)制文件binary去PATH環(huán)境變量指定的目錄中查找。默認(rèn)情況下nginx清除環(huán)境,通常會(huì)使RTMP模塊只運(yùn)行位于標(biāo)準(zhǔn)目錄如/ bin和/ usr?/ bin下。
為了確保該指令總是有效,請(qǐng)通過(guò)以下nginx的指令來(lái)保持原始PATH變量值。
?
?env PATH;?
下面的ffmpeg的調(diào)用將輸入流轉(zhuǎn)碼成流HLS流(H264 / AAC)。 FFmpeg編譯時(shí)應(yīng)支持libx264&libfaac在這個(gè)例子中。
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
?
語(yǔ)法: exec_pull command arg*
上下文: rtmp, server, application
當(dāng)發(fā)生play事件時(shí)指定要執(zhí)行的外部命令和參數(shù)。當(dāng)?shù)谝粋€(gè)客戶端連接到一條流時(shí)執(zhí)行該命令,當(dāng)最后一個(gè)客戶端斷開(kāi)時(shí)該command被kill掉。該指令使得可以在本地客戶端拉取任何格式的遠(yuǎn)程流成為可能。
該功能僅在單worker模式下可靠地工作。原因是,我們不能確保外部進(jìn)程始終連接到正確的worker。它顯然連接到一個(gè)隨機(jī)的。雖然該指令在大多數(shù)情況下可以正常工作,但這不是一個(gè)建議的體系結(jié)構(gòu),這將是不穩(wěn)定并且可能出現(xiàn)bug。
?
指令參數(shù)是相同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指令服務(wù)所有流。這導(dǎo)致遠(yuǎn)程流名稱格式有一定的局限性。它應(yīng)該能夠利用現(xiàn)有的變量,比如$app,$name等構(gòu)建遠(yuǎn)程URL。
當(dāng)不可能的時(shí)候,你可以通過(guò)添加exec_options on指令來(lái)設(shè)置附加流選項(xiàng)通過(guò)exec-family指令?,F(xiàn)在支持的唯一的選項(xiàng)是name選項(xiàng)。
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
語(yǔ)法:?exec command arg*
上下文: rtmp, server, application
EXEC是exec_push的別名
?
exec_options
語(yǔ)法: exec_options on|off
上下文: rtmp, server, application
?
該指令切換Exec選項(xiàng)模式。當(dāng)被激活時(shí),你可以添加exec-family指令選項(xiàng)。唯一支持的EXEC選項(xiàng)是name。通過(guò)該選項(xiàng),可以exec指定的流。默認(rèn)為關(guān)閉狀態(tài)。
exec_options on; # call on_publish only for "mystream" exec_publish http://localhost/on_publish name=mystream;# call on_play only for "another" exec_play http://localhost/on_play name=another;# execute different ffmpeg's for different streams 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
語(yǔ)法: exec_static command arg*
上下文: rtmp, server, application
?類似exec,但在nginx啟動(dòng)時(shí)運(yùn)行指定的命令。不支持替換,因?yàn)闆](méi)有session context。
exec_static ffmpeg -i http://example.com/video.ts -c copy -f flv rtmp://localhost/myapp/mystream;exec_kill_signal
語(yǔ)法: exec_kill_signal signal
上下文: rtmp, server, application
設(shè)置進(jìn)程終止信號(hào)。默認(rèn)是kill(SIGKILL)。您可以指定數(shù)字或符號(hào)名(for POSIX.1-1990 signals)
exec_kill_signal term; exec_kill_signal usr1; exec_kill_signal 3;respawn?
?
語(yǔ)法:?respawn on|off
上下文: rtmp, server, application
如果設(shè)為on, 當(dāng)子進(jìn)程terminal的時(shí)候重啟他如果 正在發(fā)布流。默認(rèn)為on;
?respawn off;
?
respawn_timeout
語(yǔ)法: respawn_timeout timeout
上下文: rtmp, server, application
?設(shè)置重生超時(shí)時(shí)間在啟動(dòng)新的子實(shí)例時(shí)。默認(rèn)值是5秒。
respawn_timeout 10s;
?
exec_publish
語(yǔ)法: exec_publish command arg*
上下文: rtmp, server, application
指定帶參數(shù)的外部命令在發(fā)布事件發(fā)生時(shí)。返回代碼不進(jìn)行分析。 在這里替換成exec 指令也是支持的。此外 ,帶有查詢字符串參數(shù)的args 變量也是支持的。
?
exec_play
語(yǔ)法:?exec_play command arg*
上下文: rtmp, server, application
指定帶參數(shù)的外部命令在play event發(fā)生時(shí)。返回代碼不進(jìn)行分析。替代列表和exec_publish相同
exec_play_done
語(yǔ)法:?exec_play_done command arg*
上下文: rtmp, server, application
指定帶參數(shù)的外部命令在?play_done event發(fā)生時(shí)。返回代碼不進(jìn)行分析.?替代列表和exec_publish相同
exec_publish_done
語(yǔ)法:?exec_publish_done command arg*
上下文: rtmp, server, application
指定帶參數(shù)的外部命令在 publish_done event發(fā)生時(shí)。返回代碼不進(jìn)行分析.?替代列表和exec_publish相同
exec_record_done
語(yǔ)法:?exec_record_done command arg*
上下文: rtmp, server, application, recorder
指定帶參數(shù)的外部命令在 錄制?event完成時(shí)。 exec_publish和一些附加變量在這里同樣支持
- recorder?- recorder name
- path?- 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)
Live
live
語(yǔ)法:?live on|off
上下文: rtmp, server, application
切換直播模式,即一對(duì)多的廣播。
live on;meta
語(yǔ)法:?meta on|copy|off
上下文: rtmp, server, application
集元數(shù)據(jù)發(fā)送模式。上的價(jià)值,使用戶收到一封包含像寬度,高度等的副本設(shè)定值,使客戶得到出版商的元數(shù)據(jù)塊的精確副本,包括標(biāo)準(zhǔn)和具體領(lǐng)域的預(yù)定義字段重建的元數(shù)據(jù)包。關(guān)的值將關(guān)閉發(fā)送任何RTMP元數(shù)據(jù)給用戶。默認(rèn)為on。
meta copy;interleave
語(yǔ)法:?interleave on|off
上下文: rtmp, server, application
切換交錯(cuò)模式。在這種模式下的音頻和視頻數(shù)據(jù)上相同的RTMP塊流傳輸。默認(rèn)為off。
interleave on;wait_key
語(yǔ)法:?wait_key on|off
上下文: rtmp, server, application
使視頻流從一個(gè)關(guān)鍵幀開(kāi)始。默認(rèn)為關(guān)閉。
wait_key on;wait_video
語(yǔ)法:?wait_video on|off
上下文: rtmp, server, application
使音頻失效直到第一個(gè)視頻幀發(fā)送過(guò)來(lái)。默認(rèn)為關(guān)閉??梢杂脀ait_key結(jié)合使用,使客戶端接收視頻關(guān)鍵幀后接收所有其他數(shù)據(jù)。然而,這通常會(huì)增加連接延遲。你可以在你的編碼器調(diào)整關(guān)鍵幀間隔以減少延??遲。
最新版本的IE瀏覽器需要這個(gè)選項(xiàng)有效來(lái)進(jìn)行正常播放。
wait_video on;publish_notify
語(yǔ)法:?publish_notify on|off
上下文: rtmp, server, application
發(fā)送NetStream.Play.PublishNotify和NetStream.Play.UnpublishNotify給用戶。默認(rèn)為關(guān)閉。
publish_notify on;drop_idle_publisher
語(yǔ)法:?drop_idle_publisher timeout
上下文: rtmp, server, application
丟棄在指定時(shí)間內(nèi)發(fā)布者連接當(dāng)已經(jīng)空閑(無(wú)音頻/視頻數(shù)據(jù))。默認(rèn)是關(guān)閉的。注意:這只能當(dāng)連接處于發(fā)布模式有效(在發(fā)送publish命令后)。
drop_idle_publisher 10s;sync
語(yǔ)法:?sync timeout
上下文: rtmp, server, application
同步的音頻和視頻流。如果訂戶帶寬不夠以接收發(fā)布速率數(shù)據(jù),某些幀被服務(wù)器丟棄。這將導(dǎo)致同步問(wèn)題。當(dāng)時(shí)間戳差值超過(guò)指定為同步參數(shù)的值絕對(duì)幀發(fā)送固定的。默認(rèn)為300ms。
sync 10ms;play_restart
語(yǔ)法:?play_restart on|off
上下文: rtmp, server, application
如果啟用,當(dāng)每次發(fā)布者開(kāi)始或停止發(fā)布時(shí),nginx_RTMP發(fā)送NetStream.Play.Start和NetStream.Play.Stop到每個(gè)注冊(cè)者。如果禁用,每個(gè)注冊(cè)者只在開(kāi)始和重放結(jié)束時(shí)接收到這些通知。默認(rèn)是off。
play_restart off;idle_streams
語(yǔ)法:?idle_streams on|off
上下文: rtmp, server, application
如果禁用, nginx_RTMP禁止訂閱者連接到空閑/不存在的實(shí)時(shí)流,并且當(dāng)流發(fā)布者斷開(kāi)連接時(shí),斷開(kāi)所有訂閱者的連接。默認(rèn)為on。
idle_streams off;?
?
?
record
語(yǔ)法:?record [off|all|audio|video|keyframes|manual]*
上下文: rtmp, server, application, recorder
切換錄音模式。流可以被記錄在FLV文件。該指令指定正是應(yīng)記錄哪些:
- off -?不記錄在所有
- all -?音頻和視頻(一切)
- audio -音頻
- video -??視頻
- keyframes -唯一的關(guān)鍵幀視頻
- manual -?從來(lái)沒(méi)有自動(dòng)啟動(dòng)記錄儀,使用控制界面來(lái)啟動(dòng)/停止
可以有鍵,在一個(gè)記錄指令任何相容組合。
record all;record audio keyframes;record_path
語(yǔ)法:?record_path path
上下文: rtmp, server, application, recorder
指定將錄制的FLV文件來(lái)記錄路徑。
record_path /tmp/rec;record_suffix
語(yǔ)法:?record_suffix value
上下文: rtmp, server, application, recorder
設(shè)置記錄文件的后綴。默認(rèn)為'。FLV“。
record_suffix _recorded.flv;記錄后綴可以是的strftime格式的模式。下面的指令
record_suffix -%d-%b-%y-%T.flv;將產(chǎn)生的形式mystream-24-Apr-13-18:23:38.flv 所有支持的strftime格式選項(xiàng)可以的strftime手冊(cè)頁(yè)上找到。
record_unique
語(yǔ)法:?record_unique on|off
上下文: rtmp, server, application, recorder
如果打開(kāi)追加當(dāng)前的時(shí)間戳,以錄制的文件。否則,同樣的文件,每次新的記錄發(fā)生重寫。默認(rèn)是關(guān)閉的
record_unique on;record_append
語(yǔ)法:?record_append on|off
上下文: rtmp, server, application, recorder
切換文件追加模式。當(dāng)錄音機(jī)打開(kāi)追加新數(shù)據(jù)舊文件或創(chuàng)建它時(shí),它的缺失。有舊的數(shù)據(jù),并在文件中的新數(shù)據(jù)之間不存在時(shí)間間隙。默認(rèn)是關(guān)閉的。
record_append on;record_lock
語(yǔ)法:?record_lock on|off
上下文: rtmp, server, application, recorder
當(dāng)打開(kāi)當(dāng)前記錄的文件被鎖住的fcntl調(diào)用。這可以從其他地方進(jìn)行檢查,以找出正在錄制的文件。默認(rèn)是關(guān)閉的。
record_lock on;在FreeBSD上可以使用的羊群工具來(lái)檢查。在Linux上的flock?和fcntl是無(wú)關(guān)的,所以你只剩下編寫一個(gè)簡(jiǎn)單的腳本文件檢查鎖定狀態(tài)。下面是這種腳本isunlocked.py的一個(gè)例子。
#!/usr/bin/pythonimport fcntl, syssys.stderr.close() fcntl.lockf(open(sys.argv[1], "a"), fcntl.LOCK_EX|fcntl.LOCK_NB)record_max_size
語(yǔ)法:?record_max_size size
上下文: rtmp, server, application, recorder
設(shè)置最大記錄文件大小
record_max_size 128K;record_max_frames
語(yǔ)法:?record_max_frames nframes
上下文: rtmp, server, application, recorder
設(shè)置每個(gè)錄像文件的視頻幀的最大數(shù)量。
record_max_frames 2;record_interval
語(yǔ)法:?record_interval time
上下文: rtmp, server, application, recorder
重新啟動(dòng)該數(shù)字(毫)秒后拍攝。默認(rèn)關(guān)閉。零表示記錄之間沒(méi)有延遲。如果record_unique是關(guān)閉的,那么所有的記錄片段被寫入到同一個(gè)文件。否則,時(shí)間戳就會(huì)追加這使得文件不同(因?yàn)閞ecord_interval大于1秒以上)。
record_interval 1s;record_interval 15m;recorder
語(yǔ)法:?recorder name {...}
上下文: application
創(chuàng)建記錄塊。多個(gè)刻錄機(jī)可以withing單一的應(yīng)用程序來(lái)創(chuàng)建。所有上述記錄相關(guān)指令可以在記錄{}塊中指定。所有的設(shè)置是從更高層次繼承。
application {live on;# default recorderrecord 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
語(yǔ)法:?record_notify on|off
上下文: rtmp, server, application, recorder
切換發(fā)送NetStream.Record.Start和NetStream.Record.Stop狀態(tài)信息(的onStatus),以發(fā)行時(shí)的具體記錄開(kāi)始或停止錄音文件。狀態(tài)描述字段保存記錄的域名(空默認(rèn)記錄器)。默認(rèn)關(guān)閉。
recorder myrec {record all manual;record_path /var/rec;record_notify on; }?
?
?
?Video on demand?視頻點(diǎn)播
play
語(yǔ)法:?play dir|http://loc [dir|http://loc]*
上下文: rtmp, server, application
從指定目錄或HTTP位置播放FLV或MP4文件。如果參數(shù)前綴以http://那么假定文件應(yīng)該從遠(yuǎn)程HTTP位置播放前下載。注意打不啟動(dòng),直到整個(gè)文件下載。您可以使用nginx的本地緩存本地計(jì)算機(jī)上的文件。
多個(gè)播放位置可以在一個(gè)單一的播放指令指定。當(dāng)多個(gè)播放指令指定的位置列被合并,并從更高的作用域繼承。發(fā)揮每個(gè)位置試圖直到成功定位被發(fā)現(xiàn)。如果沒(méi)有找到這樣的位置錯(cuò)誤狀態(tài)被發(fā)送到客戶端
索引FLV是為了隨機(jī)搜索能力。未編入索引FLV是玩謀求/暫停禁用(僅重啟動(dòng)模式)。使用的FLV索引(例如,yamdi)索引。
如果您播放錄制的記錄指令FLV文件,請(qǐng)不要打前忘記他們的索引。在創(chuàng)建未編入索引。
如果視頻和音頻編解碼器是由RTMP支持的mp4文件只能播放。最常見(jiàn)的情況是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 locationplay /var/local_mirror http://myserver.com/vod; }播放 /var/flvs/dir/file.flv:
ffplay rtmp://localhost/vod//dir/file.flvVOD后的兩條斜線使ffplay使用VOD和應(yīng)用程序名稱和URL作為playpath的其余部分。
play_temp_path
語(yǔ)法:?play_temp_path dir
上下文: rtmp, server, application
設(shè)置將在其中遠(yuǎn)程VOD播文件的播放之前存儲(chǔ)位置。默認(rèn)值是/ tmp;
play_temp_path /www; play http://example.com/videos;play_local_path
語(yǔ)法:?play_local_path dir
上下文: rtmp, server, application
設(shè)置從哪里目錄play_temp_path復(fù)制遠(yuǎn)程點(diǎn)播文件,他們完全下載后的位置。空值禁用該功能。默認(rèn)情況下它是空的。該特征可用于在本地緩存遠(yuǎn)程文件。
此路徑應(yīng)該是相同的裝置,play_temp_path上。
# 在/tmp/videos上搜索文件 # 如果沒(méi)有找到就找遠(yuǎn)程的location上尋找 # 而且儲(chǔ)存在/tmp/videos play_local_path /tmp/videos; play /tmp/videos http://example.com/videos;Relay ?中繼
pull
語(yǔ)法:?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.
創(chuàng)建拉流中繼 ,流從遠(yuǎn)程計(jì)算機(jī)上拉,并且成為本地可用。它僅當(dāng)至少一個(gè)播放流正在玩本地流發(fā)生。
Url syntax:?[rtmp://]host[:port][/app[/playpath]].?
如果應(yīng)用程序丟失,則使用本地應(yīng)用程序的名稱。如果playpath缺少那么當(dāng)前流的名字來(lái)代替。
以下參數(shù)被支持:
- app -?明確應(yīng)用程序的名稱
- name -?綁定繼電器當(dāng)?shù)亓髅?如果為空或不指定,則應(yīng)用程序中的所有當(dāng)?shù)氐南鞅焕?/li>
- tcUrl -?如果空的自動(dòng)構(gòu)建
- pageUrl - 偽裝網(wǎng)頁(yè)網(wǎng)址
- swfUrl -?SWF網(wǎng)址假裝
- flashVer -?flash版本假裝,默認(rèn)為“LNX.11,1,102,55”
- playPath - 遠(yuǎn)程播放路徑
- live - 切換特殊行為直播,值:0,1
- start -?以秒為單位的開(kāi)始時(shí)間
- stop -??在幾秒鐘內(nèi)停止時(shí)間
- static -?使靜態(tài)拉流 如拉在nginx的啟動(dòng)創(chuàng)建
If a value for a parameter contains spaces then you should use quotes around the?WHOLEkey=value pair like this :?'pageUrl=FAKE PAGE URL'.
如果參數(shù)的值包含空格,那么你應(yīng)該使用引號(hào)圍繞整個(gè)key = value對(duì)這樣的:'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
語(yǔ)法:?push url [key=value]*
上下文: application
推動(dòng)具有相同的語(yǔ)法拉動(dòng)。不像推拉指令發(fā)布流遠(yuǎn)程服務(wù)器。
push_reconnect
語(yǔ)法:?push_reconnect time
上下文: rtmp, server, application
重新連接超時(shí)之前等待的推后斷開(kāi)連接。默認(rèn)設(shè)置為3秒。
push_reconnect 1s;session_relay
語(yǔ)法:?session_relay on|off
上下文: rtmp, server, application
切換會(huì)話中繼模式。在這種模式下中繼當(dāng)連接關(guān)閉時(shí)被破壞。當(dāng)設(shè)置為關(guān)閉時(shí),流關(guān)閉,使得其他的中繼也可能會(huì)被以后創(chuàng)建的繼電器被破壞。默認(rèn)是關(guān)閉的。
session_relay on; ??
Notify
on_connect
語(yǔ)法:?on_connect url
上下文: rtmp, server
設(shè)置HTTP連接回調(diào)。當(dāng)客戶發(fā)送一個(gè)連接命令時(shí),一個(gè) HTTP 請(qǐng)求異步發(fā)送,命令處理將被暫停,直到它返回結(jié)果代碼。當(dāng) HTTP 2XX 碼(成功狀態(tài)碼)返回時(shí),RTMP 會(huì)話繼續(xù)。返回碼 3XX (重定向狀態(tài)碼)會(huì)使 RTMP 重定向到另一個(gè)從 HTTP 返回頭里獲取到的 application。否則(其他狀態(tài)碼)連接丟棄。
?
注意:這個(gè)指令在application域內(nèi)是不允許的,因?yàn)閍pplication在connect階段還是未知的。
HTTP請(qǐng)求接收多個(gè)參數(shù)。 POST方法用于application/x-www-form-urlencoded MIME type ,下面的參數(shù)被傳遞給調(diào)用者:
- call=connect
- addr - client IP address
- app - application name
- flashVer - client flash version
- swfUrl - client swf url
- tcUrl - tcUrl
- pageUrl - client page url
除了上述項(xiàng)目明確地傳遞給connect命令的所有參數(shù)也與回調(diào)發(fā)送。您應(yīng)當(dāng)區(qū)分連接參數(shù)從播放/發(fā)布參數(shù)。玩家通常具有播放/流發(fā)布名設(shè)置連接字符串分開(kāi)的一種特殊方式。作為一個(gè)例子下面是這些參數(shù)是如何在JWPlayer設(shè)置
... 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
語(yǔ)法:?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 2XX代碼繼續(xù)RTMP會(huì)議
- HTTP重定向3XX RTMP另一個(gè)流的名字是從位置HTTP響應(yīng)頭拍攝。如果新的流名字開(kāi)始與rtmp://?代替創(chuàng)建,繼而遠(yuǎn)程中繼會(huì)被創(chuàng)建。中繼需要IP地址被指定,而不是域名,只用nginx的版本低于1.3.10更大的工作。又見(jiàn)notify_relay_redirect。
- 否則,RTMP連接斷開(kāi)
重定向的例如
HTTP請(qǐng)求接收多個(gè)參數(shù)。 POST方法用于application/x-www-form-urlencoded MIME type.?。下面的參數(shù)被傳遞給調(diào)用者:
- call=play
- addr - client IP address
- clientid - nginx client id (displayed in log and stat)
- app - application name
- flashVer - client flash version
- swfUrl - client swf url
- tcUrl - tcUrl
- pageUrl - client page url
- name - stream name
除了上述項(xiàng)目通過(guò)明確玩命令的所有參數(shù)也與回調(diào)發(fā)送。
例如,如果流與URL訪問(wèn) rtmp://localhost/app/movie?a=100&b=face&foo=bar?then?a,?b?&?foo?也會(huì)被發(fā)送回來(lái)
?
on_play http://example.com/my_callback;on_publish
語(yǔ)法:?on_publish url
上下文: rtmp, server, application
上面這個(gè)指令設(shè)置了發(fā)布命令回調(diào),唯一的區(qū)別一樣on_play。代替遠(yuǎn)程拉推在這種情況下進(jìn)行的。
on_done
語(yǔ)法:?on_done url
上下文: rtmp, server, application
設(shè)置 play/publish ?終止回調(diào)。上述所有適用于此。然而HTTP狀態(tài)代碼不檢查此回調(diào)。
on_play_done
語(yǔ)法:?on_play_done url
上下文: rtmp, server, application
和?on_done 一樣的行為?但只作用于 play和?event?
on_publish_done
語(yǔ)法:?on_publish_done url
上下文: rtmp, server, application
相同的行為on_done?但只作用于 publish?和?event?
on_record_done
語(yǔ)法:?on_record_done url
上下文: rtmp, server, application, recorder
設(shè)置record_done回調(diào)。除了常見(jiàn)的HTTP回調(diào)變量它接收到以下值
- recorder - recorder name in config or empty string for inline recorder?在配置或空字符串內(nèi)聯(lián)錄音機(jī)錄像機(jī)名
- path - ?錄制的文件路徑
Example
on_record_done http://example.com/recorded;on_update
語(yǔ)法:?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:
設(shè)置更新回調(diào)。此回調(diào)調(diào)用notify_update_timeout的時(shí)期。如果請(qǐng)求返回比2XX連接其他HTTP結(jié)果被終止。這可用于同步過(guò)期會(huì)話。另外兩個(gè)參數(shù)的 時(shí)間和時(shí)間戳 傳遞到該處理程序
- time??從?play/publish 回調(diào)開(kāi)始的時(shí)間
- timestamp?is RTMP timestamp of the last audio/video packet sent to the client?發(fā)送到客戶端的最后的音頻/視頻分組的RTMP時(shí)間戳
您可以使用時(shí)間戳參數(shù)單獨(dú)限制播放時(shí)長(zhǎng)為每個(gè)用戶。
on_update http://example.com/update;notify_update_timeout
語(yǔ)法:?notify_update_timeout timeout
上下文: rtmp, server, application
集on_update回調(diào)之間超時(shí)。默認(rèn)值是30秒。
notify_update_timeout 10s; on_update http://example.com/update;notify_update_strict
語(yǔ)法:?notify_update_strict on|off
上下文: rtmp, server, application
對(duì)于切換回調(diào)on_update嚴(yán)格模式。默認(rèn)是關(guān)閉的。當(dāng)所有的連接錯(cuò)誤打開(kāi),超時(shí)以及HTTP分析錯(cuò)誤和空的反應(yīng)被視為更新失敗,??并導(dǎo)致連接終止。當(dāng)關(guān)閉唯一有效的HTTP響應(yīng)代碼等的2XX導(dǎo)致失敗。
notify_update_strict on; on_update http://example.com/update;notify_relay_redirect
語(yǔ)法:?notify_relay_redirect on|off
上下文: rtmp, server, application
啟用對(duì)on_play和on_publish遠(yuǎn)程重定向本地流重定向。新的流名字是用于遠(yuǎn)程重定向RTMP網(wǎng)址的MD5哈希值。默認(rèn)是關(guān)閉的。
notify_relay_redirect on;notify_method
語(yǔ)法:?notify_method get|post
上下文: rtmp, server, application, recorder
設(shè)置通知的HTTP方法。默認(rèn)值是POST與?application/x-www-form-urlencoded content type.在某些情況下得到的是可取的,例如,如果您打算處理Nginx的HTTP {}部分呼叫。在這種情況下,你可以使用arg_*變量訪問(wèn)參數(shù)。
notify_method get;在HTTP GET方法處理?http{}部分可以做這樣
location /on_play {if ($arg_pageUrl ~* localhost) {return 200;}return 500; } ?-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------HLS
語(yǔ)法:?hls on|off
上下文: rtmp, server, application
切換HLS上的應(yīng)用。
hls on; hls_path /tmp/hls; hls_fragment 15s;在HTTP {}部分客戶打HLS設(shè)置以下的位置。
http {...server {...location /hls {types {application/vnd.apple.mpegurl m3u8;}root /tmp;add_header Cache-Control no-cache;# 為了避免與跨域的HTTP請(qǐng)求(例如,在開(kāi)發(fā)過(guò)程中)的問(wèn)題add_header Access-Control-Allow-Origin *;}} }hls_path
語(yǔ)法:?hls_path path
上下文: rtmp, server, application
設(shè)置HLS播放列表和片段目錄。如果該目錄不存在,將會(huì)被創(chuàng)建。
hls_fragment
語(yǔ)法:?hls_fragment time
上下文: rtmp, server, application
設(shè)置HLS片段長(zhǎng)度。默認(rèn)為5秒。
hls_playlist_length
語(yǔ)法:?hls_playlist_length time
上下文: rtmp, server, application
設(shè)置播放列表HLS長(zhǎng)度。默認(rèn)為30秒。
hls_playlist_length 10m;hls_sync
語(yǔ)法:?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).
設(shè)置HLS時(shí)間戳同步的閾值。默認(rèn)為2ms。此功能可以防止從低分辨率RTMP(1KHz的)轉(zhuǎn)換為高分辨率MPEG-TS(90KHz的)之后產(chǎn)生的噼啪的噪聲。
hls_sync 100ms;hls_continuous
語(yǔ)法:?hls_continuous on|off
上下文: rtmp, server, application
切換HLS連續(xù)模式。在這種模式下HLS序列號(hào)從它上一次停止處開(kāi)始。舊fragment依然保留。默認(rèn)是關(guān)閉的。
hls_continuous on;hls_nested
語(yǔ)法:?hls_nested on|off
上下文: rtmp, server, application
切換HLS嵌套模式。在這種模式下hls_path的子目錄為每個(gè)數(shù)據(jù)流創(chuàng)建。播放列表和片段在子目錄中創(chuàng)建。默認(rèn)是關(guān)閉的。
hls_nested on;hls_base_url
語(yǔ)法:?hls_base_url url
上下文: rtmp, server, application
設(shè)置HLS播放列表項(xiàng)基本URL。當(dāng)空這些項(xiàng)目沒(méi)有前綴并且假設(shè)是在相同的位置父播放列表或低一個(gè)級(jí)別時(shí)使用hls_nested。此功能同時(shí)適用于主(變量)和從HLS播放列表。它可以讓你下載播放列表,因?yàn)樗瑑和シ帕斜砘蚱瓮耆帽镜夭シ?。默認(rèn)為空。
hls_base_url http://myserver.com/hls/;hls_cleanup
語(yǔ)法:?hls_cleanup on|off
上下文: rtmp, server, application
切換HLS清理。默認(rèn)情況下,該功能已開(kāi)啟。在這種模式下nginx的緩存管理器進(jìn)程會(huì)刪除HLS目錄老HLS片段和播放列表。
hls_cleanup off;hls_fragment_naming
語(yǔ)法:?hls_fragment_naming sequential|timestamp|system
上下文: rtmp, server, application
設(shè)置片段的命名方式
- sequential -?使用增加的整數(shù)
- timestamp -??使用流時(shí)間戳
- system -使用系統(tǒng)時(shí)間
默認(rèn)值是連續(xù)的
hls_fragment_naming system;hls_fragment_naming_granularity
語(yǔ)法:?hls_fragment_naming_granularity number
上下文: rtmp, server, application
設(shè)置HLS片段IDS粒度。如果大于零,改變IDS來(lái)劃分提供的價(jià)值。默認(rèn)值是零。
# use system time rounded to 500ms as fragment names hls_fragment_naming system; hls_fragment_naming_granularity 500;hls_fragment_slicing
語(yǔ)法:?hls_fragment_slicing plain|aligned
上下文: rtmp, server, application
設(shè)置片段切片模式。
- plain -?當(dāng)達(dá)到目標(biāo)時(shí)的持續(xù)時(shí)間片段切換
- aligned -開(kāi)關(guān)片段時(shí)傳入的時(shí)間戳片段持續(xù)時(shí)間的倍數(shù)。該模式使得能夠產(chǎn)生不同的nginx實(shí)例相同片段
默認(rèn)值是?plain.
hls_fragment_slicing aligned;hls_variant
語(yǔ)法:?hls_variant suffix [param*]
上下文: rtmp, server, application
添加HLS變項(xiàng)(variant entry 變量條目,翻譯不準(zhǔn)確)。當(dāng)后綴是在流名稱匹配,然后,對(duì)用hls_variant指示當(dāng)前應(yīng)用程序中指定的所有條目當(dāng)前流創(chuàng)建播放列表中的變體。不帶后綴名剝離用作變量流名稱。原來(lái)的流像往常一樣處理。
以下后綴可選參數(shù)追加到播放列表M3U8 EXT-X-STREAM-INF。見(jiàn)HLS規(guī)范。 3.3.10。 EXT-X-STREAM-INF支持的參數(shù)的完整列表。
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
語(yǔ)法:?hls_type live|event
上下文: rtmp, server, application
設(shè)置HLS playlist type在X-PLAYLIST-TYPE 播放列表指令。live? HLS流通常是從當(dāng)前播放位置(是一些fragment)到播放列表末尾播放。event HLS流總是從playlist起始位置開(kāi)始播放。event模式要確保playlist的長(zhǎng)度對(duì)整個(gè)事件足夠大。默認(rèn)值是live;
hls_type event;hls_keys
語(yǔ)法:?hls_keys on|off
上下文: rtmp, server, application
啟用HLS加密。 AES-128的方法用來(lái)加密整個(gè)HLS片段。默認(rèn)關(guān)閉。
hls_keys on;下面是一個(gè)使用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
語(yǔ)法:?hls_key_path path
Context: rtmp, server, application
設(shè)置將在其中自動(dòng)生成HLS密鑰保存的目錄。密鑰文件與在OpenSSL RAND_bytes()例行程序創(chuàng)建的.key延伸和偽隨機(jī)的16字節(jié)的內(nèi)容。如果該目錄不存在,它在運(yùn)行時(shí)創(chuàng)建的。默認(rèn)情況下,hls_path目錄用于密鑰文件??。但是請(qǐng)記住,你通常應(yīng)該限制訪問(wèn)關(guān)鍵文件,這是容易當(dāng)這些文件從播放列表和片段分開(kāi)存放。
hls_key_path /tmp/keys;hls_key_url
語(yǔ)法:?hls_key_url url
上下文: rtmp, server, application
設(shè)置HLS密鑰文件條目的URL。當(dāng)空這些項(xiàng)目沒(méi)有前綴和密鑰被認(rèn)為是在相同的位置播放列表。默認(rèn)為空
hls_key_url https://myserver.com/keys/;用上述設(shè)定例的播放列表?xiàng)l目
#EXT-X-KEY:METHOD=AES-128,URI="https://myserver.com/keys/337.key",IV=0x00000000000000000000000000000151hls_fragments_per_key
語(yǔ)法:?hls_fragments_per_key value
上下文: rtmp, server, application
設(shè)置具有相同的密鑰加密的HLS片段的數(shù)目。零意味著只有一個(gè)密鑰的發(fā)布開(kāi)始創(chuàng)建,并在會(huì)話中的所有片段與此密鑰加密。默認(rèn)值是零。
hls_fragments_per_key 10;MPEG-DASH?MPEG組織批準(zhǔn)了MPEG-DASH(HTTP動(dòng)態(tài)自適應(yīng)流媒體)標(biāo)準(zhǔn)
dash
語(yǔ)法:?dash on|off
上下文: rtmp, server, application
應(yīng)用程序切換MPEG-DASH。
dash on; dash_path /tmp/dash; dash_fragment 15s;在HTTP {}部分設(shè)置以下的位置,為客戶播放MPEG-DASH。
http {...server {...location /dash {root /tmp;add_header Cache-Control no-cache;# #為了避免與跨域的HTTP請(qǐng)求(例如,在開(kāi)發(fā)過(guò)程中)的問(wèn)題add_header Access-Control-Allow-Origin *;}} }dash_path
語(yǔ)法:?dash_path path
上下文: rtmp, server, application
設(shè)置MPEG-DASH播放列表,片段目錄。如果該目錄不存在,它將被創(chuàng)建。
dash_fragment
語(yǔ)法:?dash_fragment time
上下文: rtmp, server, application
設(shè)置MPEG-DASH片段長(zhǎng)度。默認(rèn)為5秒。
dash_playlist_length
語(yǔ)法:?dash_playlist_length time
上下文: rtmp, server, application
設(shè)置MPEG-DASH播放列表的長(zhǎng)度。默認(rèn)為30秒。
dash_playlist_length 10m;dash_nested
語(yǔ)法:?dash_nested on|off
上下文: rtmp, server, application
切換MPEG-DASH嵌套模式。在這種模式下dash_path的子目錄為每個(gè)數(shù)據(jù)流創(chuàng)建。播放列表和片段在子目錄中創(chuàng)建。默認(rèn)是關(guān)閉的。
dash_nested on;dash_cleanup
語(yǔ)法:?dash_cleanup on|off
上下文: rtmp, server, application
切換MPEG-DASH清理。默認(rèn)情況下,該功能已開(kāi)啟。在這種模式下nginx的緩存管理器進(jìn)程從MPEG-DASH目錄中刪除舊的MPEG-DASH碎片和體現(xiàn)。流清單被刪除后,初始化片段被刪除。
dash_cleanup off;Access log
access_log
語(yǔ)法:?access_log off|path [format_name]
上下文: rtmp, server, application
設(shè)置訪問(wèn)日志參數(shù)。日志默認(rèn)情況下開(kāi)啟。要關(guān)閉它使用ACCESS_LOG關(guān)閉指令。默認(rèn)情況下訪問(wèn)日志記錄是為了同一個(gè)文件的HTTP訪問(wèn)記錄器(log/ access.log)。您可以指定訪問(wèn)日志指令另一個(gè)日志文件的路徑。第二個(gè)參數(shù)是可選的。它可用于通過(guò)名稱來(lái)指定記錄格式。見(jiàn)log_format指令有關(guān)格式的詳細(xì)信息。
log_format new '$remote_addr'; access_log logs/rtmp_access.log new; access_log logs/rtmp_access.log; access_log off;log_format
語(yǔ)法:?log_format format_name format
上下文: rtmp
創(chuàng)建一個(gè)名為日志格式。日志格式看起來(lái)非常相同的nginx的HTTP日志格式。幾個(gè)變量的日志格式中支持:
- connection?- connection number
- remote_addr?- client address
- app?- application name
- name?- last stream name
- args?- last stream play/publish arguments
- flashver?- client flashVer
- swfurl?- client swfUrl
- tcurl?- client tcUrl
- pageurl?- client pageUrl
- command?- play/publish commands sent by client:?NONE,?PLAY,?PUBLISH,?PLAY+PUBLISH
- bytes_sent?- number of bytes sent to client
- bytes_received?- number of bytes received from client
- time_local?- local time at the end of client connection
- session_time?- connection duration in seconds
- session_readable_time?- connection duration in human-readable format
- msec?- current unix timestamp in SEC.MSEC format
默認(rèn)的日志格式有名稱相結(jié)合。下面是這種格式的定義
$remote_addr [$time_local] $command "$app" "$name" "$args" - $bytes_received $bytes_sent "$pageurl" "$flashver" ($session_readable_time)Limits
max_connections
語(yǔ)法:?max_connections number
上下文: rtmp, server, application
設(shè)置RTMP發(fā)動(dòng)機(jī)的最大連接數(shù)。默認(rèn)關(guān)閉
max_connections 100;Statistics
統(tǒng)計(jì)模塊是不同于此處列出的所有其他模塊NGINX HTTP模塊。因此,統(tǒng)計(jì)指令應(yīng)位于HTTP {}塊之內(nèi)
rtmp_stat
語(yǔ)法:?rtmp_stat all
上下文: http, server, location
設(shè)置RTMP統(tǒng)計(jì)處理當(dāng)前的HTTP位置。 RTMP統(tǒng)計(jì)是動(dòng)態(tài)的XML文檔。要觀看在瀏覽器XHTML頁(yè)面使用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
語(yǔ)法:?rtmp_stat_stylesheet path
上下文: http, server, location
添加X(jué)ML樣式表引用統(tǒng)計(jì)XML,使其在瀏覽器查看。見(jiàn)rtmp_stat說(shuō)明和示例的詳細(xì)信息。
Multi-worker live streaming
多進(jìn)程直播通過(guò)推流剩余nginx的工人執(zhí)行。
rtmp_auto_push
語(yǔ)法:?rtmp_auto_push on|off
上下文: root
切換自動(dòng)推(多進(jìn)程直播)模式。默認(rèn)是關(guān)閉的。
rtmp_auto_push_reconnect
語(yǔ)法:?rtmp_auto_push_reconnect timeout
上下文: root
設(shè)置自動(dòng)推送重新連接超時(shí),當(dāng)工作進(jìn)程被殺害。默認(rèn)值是100毫秒。
rtmp_socket_dir
語(yǔ)法:?rtmp_socket_dir dir
上下文: root
設(shè)置用于流推動(dòng)UNIX域套接字目錄。默認(rèn)值是/ tmp。
rtmp_auto_push on; rtmp_auto_push_reconnect 1s; rtmp_socket_dir /var/sock;rtmp {server {listen 1935;application myapp {live on;}} }?
?Control ?控制模塊
?控制模塊是HTTP模塊,這使得它可以從使用??HT??TP協(xié)議之外的控制設(shè)rtmp模塊。下面是如何使能控制一個(gè)例子。
http { ...server {listen 8080;server_name localhost;....location /control {rtmp_control all;}} }有控制模塊內(nèi)的幾個(gè)子模塊的每個(gè)控制不同的功能。
錄制
該子模塊啟動(dòng)和停止與手動(dòng)標(biāo)志創(chuàng)建記錄。語(yǔ)法:
http://server.com/control/record/start|stop?srv=SRV&app=??APP&name=NAME&rec=REC
SRV = SRV - 可選的服務(wù)器{}塊RTMP {}塊中號(hào),默認(rèn)為第一個(gè)服務(wù)器{}塊
應(yīng)用= APP - 所需的應(yīng)用程序名稱
NAME =名稱 - 需要流名稱
REC = REC - 可選的記錄名稱,默認(rèn)為根(未命名)記錄
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"
addr - 可選的客戶端地址(同樣由rtmp_stat返回)
clientid??- 可選nginx的客戶端ID(日志和統(tǒng)計(jì)顯示)
第一種方法 刪除/發(fā)布者 發(fā)行下降的連接??。第二方法是 刪除或者客戶端刪除,如果沒(méi)有指定地址每連接匹配addr參數(shù)或所有客戶端(包括出版商)。
Redirect 重定向
?
重定向播放/客戶端發(fā)布到一個(gè)新的數(shù)據(jù)流。語(yǔ)法:
http://server.com/control/redirect/publisher|subscriber|client?srv=SRV&app=APP&name=NAME&addr=ADDR&clientid=CLIENTID&newname=NEWNAMEsrv, app, name, addr, clients - 和上面相同
newname -?新的流名重定向到
?
Debug log
如果您需要解決您可能需要觀看調(diào)試日志流的問(wèn)題。對(duì)于--with調(diào)試標(biāo)志配置Nginx的。
cd nginx-X.Y.Z ./configure --add-module=/path/to/nginx-rtmp-module --with-debug ...編譯一套nginx的error.log中水平nginx.conf調(diào)試后
error_log logs/error.log debug;這之后,你將有很多的error.log中調(diào)試信息。
?
?
Exec wrapper in bash
你可以用任何語(yǔ)言編寫的exec包裝。然而,你應(yīng)該注意終止進(jìn)程。當(dāng)出版商關(guān)閉流的所有執(zhí)行處理被終止。如果指定的exec指令,而不是真正的ffmpeg的包裝,那么你最終可能會(huì)與你的ffmpeg還活著,孤兒,直到超時(shí)讀取輸入數(shù)據(jù)。
該解決辦法是用信號(hào)陷阱。下面是在bash這種包裝的一個(gè)例子。
#!/bin/bashon_die () {# kill all childrenpkill -KILL -P $$ }trap 'on_die' TERM ffmpeg -i rtmp://localhost/myapp/$1 -c copy -f flv rtmp://localhost/myapp2/$1 & wait該腳本注冊(cè)它終止子的ffmpeg SIGTERM處理器。 nginx的,RTMP發(fā)送默認(rèn)的信號(hào)是SIGKILL不能被捕獲。對(duì)于上面的腳本按預(yù)期的行為,你需要exec_kill_signal指令來(lái)改變EXEC終止信號(hào)。它接受數(shù)字或符號(hào)信號(hào)名稱(POSIX.1-1990信號(hào))。這里的示例應(yīng)用程序。
application myapp {live on;exec /var/scripts/exec_wrapper.sh $name;exec_kill_signal term; }application myapp2 {live on; }?
?
?
?
?
?
Examples 一些實(shí)例
?
簡(jiǎn)單的視頻點(diǎn)播
rtmp {server {listen 1935;application vod {play /var/flvs;}} }簡(jiǎn)單的直播服務(wù)
rtmp {server {listen 1935;application live {live on;}} }重新翻譯遠(yuǎn)程流
rtmp {server {listen 1935;application tv {live on;pull rtmp://cdn.example.com:443/programs/main pageUrl=http://www.example.com/index.html name=maintv;}} }重新翻譯與HLS支持遠(yuǎn)程流
rtmp {server {listen 1935;application tv {live on;hls on;hls_path /tmp/tv2;hls_fragment 15s;pull rtmp://tv2.example.com:443/root/new name=tv2;}} }http {server {listen 80;location /tv2 {alias /tmp/tv2;}} }物流通過(guò)RTMP你的X屏幕
ffmpeg -f x11grab -follow_mouse centered -r 25 -s cif -i :0.0 -f flv rtmp://localhost/myapp/screenSet up live streaming
?
要建立RTMP支持,你需要添加RTMP{}部分nginx.conf(PREFIX/conf/nginx.conf))。股票nginx.conf只包含HTTP{}部分。
使用此nginx.conf,而不是原始的配置:
#user nobody; worker_processes 1;error_log logs/error.log debug;events {worker_connections 1024; }http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 8080;server_name localhost;# sample handlers#location /on_play {# if ($arg_pageUrl ~* localhost) {# return 201;# }# return 202;#}#location /on_publish {# return 201;#}#location /vod {# alias /var/myvideos;#}# rtmp statlocation /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {# you can move stat.xsl to a different locationroot /usr/build/nginx-rtmp-module;}# rtmp controllocation /control {rtmp_control all;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}} }rtmp {server {listen 1935;ping 30s;notify_method get;application myapp {live on;# sample play/publish handlers#on_play http://localhost:8080/on_play;#on_publish http://localhost:8080/on_publish;# sample recorder#recorder rec1 {# record all;# record_interval 30s;# record_path /tmp;# record_unique on;#}# sample HLS#hls on;#hls_path /tmp/hls;#hls_sync 100ms;}# Video on demand#application vod {# play /var/Videos;#}# Video on demand over HTTP#application vod_http {# play http://localhost:8080/vod/;#}} }Statistics (統(tǒng)計(jì))
在瀏覽器中輸入?http://localhost:8080/stat??看到目前的流媒體統(tǒng)計(jì),連接的客戶端,帶寬等。
Publishing with ffmpeg
發(fā)布現(xiàn)場(chǎng)視頻流最簡(jiǎn)單的方法是使用的ffmpeg(或avconv)。它已經(jīng)安裝在大多數(shù)系統(tǒng)中,也方便安裝在其他的上面。
RTMP僅支持的編解碼器的數(shù)量有限。最流行的RTMP視頻編解碼器是H264,索倫森-H263(又名FLV)和音頻編解碼器AAC,MP3,得到Nellymoser,Speex語(yǔ)音。
如果您的視頻與這些編解碼器編碼(最常見(jiàn)的是對(duì)H264 / AAC),那么你不需要任何轉(zhuǎn)換。否則,你需要將視頻轉(zhuǎn)換為支持的編解碼之一。
我們將流測(cè)試文件?/var/videos/test.mp4?to server with ffmpeg.
Streaming without conversion (given?test.mp4?codecs are compatible with RTMP)
ffmpeg -re -i /var/Videos/test.mp4 -c copy -f flv rtmp://localhost/myapp/mystreamStreaming and encoding audio (AAC) and video (H264), need?libx264?and?libfaac
ffmpeg -re -i /var/Videos/test.mp4 -c:v libx264 -c:a libfaac -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystreamStreaming and encoding audio (MP3) and video (H264), need?libx264?and?libmp3lame
ffmpeg -re -i /var/Videos/test.mp4 -c:v libx264 -c:a libmp3lame -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystreamStreaming and encoding audio (Nellymoser) and video (Sorenson H263)
ffmpeg -re -i /var/Videos/test.mp4 -c:v flv -c:a nellymoser -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystreamPublishing video from webcam
ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264 -an -f flv rtmp://localhost/myapp/mystreamPlaying with ffplay
ffplay rtmp://localhost/myapp/mystreamPublishing and playing with flash
See?test/rtmp-publisher?directory for test flash applets and html.
總結(jié)
以上是生活随笔為你收集整理的视频直播点播nginx-rtmp开发手册中文版的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: nginx: [emerg] bind(
- 下一篇: nginx基本数据结构及接口