日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

视频直播点播nginx-rtmp开发手册中文版

發(fā)布時間:2024/2/28 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 视频直播点播nginx-rtmp开发手册中文版 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

參照官方文檔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
  • 訪問權(quán)限
    • allow
    • deny
    Exec 一簇函數(shù)(進程往往要調(diào)用一種exec函數(shù)以執(zhí)行另一個程序)
  • 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
  • 視頻點播
    • 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動態(tài)自適應(yīng)流媒體)
    • dash
    • dash_path
    • dash_fragment
    • dash_playlist_length
    • dash_nested
    • dash_cleanup
  • 訪問日志
    • access_log
    • log_format
  • Limits 限制
    • max_connections
  • 數(shù)據(jù)統(tǒng)計
    • rtmp_stat
    • rtmp_stat_stylesheet
  • Multi-worker live streaming ?多線程直播流
    • rtmp_auto_push
    • rtmp_auto_push_reconnect
    • rtmp_socket_dir
  • Control ?控制模塊
    • rtmp_control

?

?

上下文可以理解為,默認配置文件或者參數(shù),如果沒有就會報錯,因為每個函數(shù)都需一些定義好的參數(shù)和傳入函數(shù)的參數(shù),這個有些可以少,但是有些是必須的

核心

語法: rtmp { ... }
上下文: root

?聲明RTMP服務(wù)器實??例

rtmp {server {} }語法: listen (addr[:port]|port|unix:path) [bind] [ipv6only=on|off] [so_keepalive=on|off|keepidle:keepintvl:keepcnt|proxy_protocol] 上下文: server添加監(jiān)聽套接字NGINX接受RTMP連接

server {
listen 1935;
}

application

語法:?application name { ... }
上下文: server

創(chuàng)建RTMP應(yīng)用。不同于HTTP位置應(yīng)用程序的名稱不能是一個模式。

server {listen 1935;application myapp {} }

?

?

timeout 超時

語法:超時值
上下文:RTMP,服務(wù)器

?套接字超時。該值主要用于寫入。大多數(shù)時間RTMP模塊預(yù)計不會對除發(fā)行插座所有套接字的任何活動。如果你想斷插座得到迅速斷開連接采用主動式工具,如保活或RTMP平。默認為1分鐘。

?timeout 60s;

?

ping

?

語法: ping value
上下文: rtmp, server

?RTMP ping間隔。零變?yōu)槠降簟?RTMP平是主動連接檢查的協(xié)議功能。一個特殊的數(shù)據(jù)包被發(fā)送到遠程對等體和答復(fù)有望與ping_timeout指令指定的超時時間內(nèi)。

如果ping回復(fù)未在此時間內(nèi)收到然后關(guān)閉連接。平安默認值為1分鐘。默認Ping超時是30秒。

ping 3m;
ping_timeout 30s;
ping_timeout

?

ping_timeout

語法:?ping_timeout value
上下文: rtmp, server

見上面ping的描述

?

?max_streams 單一流數(shù)據(jù)最大限制

語法: max_streams value
上下文: rtmp, server

設(shè)置RTMP流的最大數(shù)目。數(shù)據(jù)流被復(fù)用成一個單一的數(shù)據(jù)流。不同信道用于發(fā)送命令,音頻,視頻等的默認值是32,它通常是確定為許多情況。

max_streams 32;

?

ack_window?

語法: ack_window value
上下文: rtmp, server

?設(shè)置RTMP確認窗口的大小。它接收到的字節(jié)之后對等體應(yīng)發(fā)送確認包到遠程側(cè)的次數(shù)。默認值是5000000。

ack_window 5000000;

?

chunk_size 數(shù)據(jù)塊大小

語法:?chunk_size value
上下文: rtmp, server

最大的塊的大小為最大流復(fù)數(shù)。默認值是4096越大該值越低CPU開銷。這個值不能小于128。

chunk_size 4096;

max_queue 最大隊列數(shù)

語法:?max_queue?value
上下文: rtmp, server

照上面的語法習(xí)慣是這樣,官方平?jīng)]有給出文檔,應(yīng)該是設(shè)置最大連接數(shù)的參數(shù),具體想知道這個是做什么的請參看源代碼

?

max_message

語法: max_queue value
上下文: rtmp, server

輸入數(shù)據(jù)消息的最大大小。所有輸入數(shù)據(jù)來源(成塊,并進一步)分成的消息。的部分信息保存在內(nèi)存中,而等待它完成。在理論上傳入消息可以是非常大的,可以是對于服務(wù)器的穩(wěn)定性的問題。默認值是1M足夠許多情況下。

max_message 1M;

?

buflen 緩沖區(qū)

語法: buflen time
上下文: rtmp, server

?

設(shè)置默認的緩沖區(qū)長度。通常客戶端發(fā)送播放前RTMP set_buflen命令并重置該設(shè)置。默認值是1000毫秒。

buflen 5S;

out_queue

目前沒有文檔

out_cork

目前沒有文檔

?

?

Access 訪問控制

allow

語法: 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

語法: deny [play|publish] address|subnet|all
上下文: rtmp, server, application

參見allow說明

?

Exec

exec_push

?

?


語法: exec_push command arg*
上下文: rtmp, server, application

?

指定帶參數(shù)的外部命令在發(fā)布每一條流時。當(dāng)發(fā)布停止時結(jié)束處理程序。二進制完整路徑應(yīng)指定為第一個參數(shù)。這里沒有任何假設(shè)關(guān)于這個進程必須做什么。然而,這功能對ffmpeg的流轉(zhuǎn)碼非常有用。

FFmpeg作為一個客戶端連接到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

確保重定向字符和流名稱/編號之間沒有空格。

?

您可以指定要執(zhí)行的命令的全局路徑或短命令名。在后一種情況下,二進制文件binary去PATH環(huán)境變量指定的目錄中查找。默認情況下nginx清除環(huán)境,通常會使RTMP模塊只運行位于標(biāo)準(zhǔn)目錄如/ bin和/ usr?/ bin下。

為了確保該指令總是有效,請通過以下nginx的指令來保持原始PATH變量值。

?

?env PATH;?

下面的ffmpeg的調(diào)用將輸入流轉(zhuǎn)碼成流HLS流(H264 / AAC)。 FFmpeg編譯時應(yīng)支持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

?

語法: exec_pull command arg*
上下文: rtmp, server, application

當(dāng)發(fā)生play事件時指定要執(zhí)行的外部命令和參數(shù)。當(dāng)?shù)谝粋€客戶端連接到一條流時執(zhí)行該命令,當(dāng)最后一個客戶端斷開時該command被kill掉。該指令使得可以在本地客戶端拉取任何格式的遠程流成為可能。

該功能僅在單worker模式下可靠地工作。原因是,我們不能確保外部進程始終連接到正確的worker。它顯然連接到一個隨機的。雖然該指令在大多數(shù)情況下可以正常工作,但這不是一個建議的體系結(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)致遠程流名稱格式有一定的局限性。它應(yīng)該能夠利用現(xiàn)有的變量,比如$app,$name等構(gòu)建遠程URL。

當(dāng)不可能的時候,你可以通過添加exec_options on指令來設(shè)置附加流選項通過exec-family指令。現(xiàn)在支持的唯一的選項是name選項。

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

語法:?exec command arg*
上下文: rtmp, server, application

EXEC是exec_push的別名

?

exec_options

語法: exec_options on|off
上下文: rtmp, server, application

?

該指令切換Exec選項模式。當(dāng)被激活時,你可以添加exec-family指令選項。唯一支持的EXEC選項是name。通過該選項,可以exec指定的流。默認為關(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

語法: exec_static command arg*
上下文: rtmp, server, application

?類似exec,但在nginx啟動時運行指定的命令。不支持替換,因為沒有session context。

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

設(shè)置進程終止信號。默認是kill(SIGKILL)。您可以指定數(shù)字或符號名(for POSIX.1-1990 signals)

exec_kill_signal term; exec_kill_signal usr1; exec_kill_signal 3;

respawn?

?

語法:?respawn on|off
上下文: rtmp, server, application

如果設(shè)為on, 當(dāng)子進程terminal的時候重啟他如果 正在發(fā)布流。默認為on;

?respawn off;

?

respawn_timeout

語法: respawn_timeout timeout
上下文: rtmp, server, application

?設(shè)置重生超時時間在啟動新的子實例時。默認值是5秒。

respawn_timeout 10s;

?

exec_publish

語法: exec_publish command arg*
上下文: rtmp, server, application

指定帶參數(shù)的外部命令在發(fā)布事件發(fā)生時。返回代碼不進行分析。 在這里替換成exec 指令也是支持的。此外 ,帶有查詢字符串參數(shù)的args 變量也是支持的。

?

exec_play

語法:?exec_play command arg*
上下文: rtmp, server, application

指定帶參數(shù)的外部命令在play event發(fā)生時。返回代碼不進行分析。替代列表和exec_publish相同

exec_play_done

語法:?exec_play_done command arg*
上下文: rtmp, server, application

指定帶參數(shù)的外部命令在?play_done event發(fā)生時。返回代碼不進行分析.?替代列表和exec_publish相同

exec_publish_done

語法:?exec_publish_done command arg*
上下文: rtmp, server, application

指定帶參數(shù)的外部命令在 publish_done event發(fā)生時。返回代碼不進行分析.?替代列表和exec_publish相同

exec_record_done

語法:?exec_record_done command arg*
上下文: rtmp, server, application, recorder

指定帶參數(shù)的外部命令在 錄制?event完成時。 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)
# 跟蹤客戶信息 exec_play bash -c "echo $addr $pageurl >> /tmp/clients"; exec_publish bash -c "echo $addr $flashver >> /tmp/publishers";# 轉(zhuǎn)換錄制的文件格式的MP4 exec_record_done ffmpeg -y -i $path -acodec libmp3lame -ar 44100 -ac 1 -vcodec libx264 $dirname/$basename.mp4;

Live

live

語法:?live on|off
上下文: rtmp, server, application

切換直播模式,即一對多的廣播。

live on;

meta

語法:?meta on|copy|off
上下文: rtmp, server, application

集元數(shù)據(jù)發(fā)送模式。上的價值,使用戶收到一封包含像寬度,高度等的副本設(shè)定值,使客戶得到出版商的元數(shù)據(jù)塊的精確副本,包括標(biāo)準(zhǔn)和具體領(lǐng)域的預(yù)定義字段重建的元數(shù)據(jù)包。關(guān)的值將關(guān)閉發(fā)送任何RTMP元數(shù)據(jù)給用戶。默認為on。

meta copy;

interleave

語法:?interleave on|off
上下文: rtmp, server, application

切換交錯模式。在這種模式下的音頻和視頻數(shù)據(jù)上相同的RTMP塊流傳輸。默認為off。

interleave on;

wait_key

語法:?wait_key on|off
上下文: rtmp, server, application

使視頻流從一個關(guān)鍵幀開始。默認為關(guān)閉。

wait_key on;

wait_video

語法:?wait_video on|off
上下文: rtmp, server, application

使音頻失效直到第一個視頻幀發(fā)送過來。默認為關(guān)閉。可以用wait_key結(jié)合使用,使客戶端接收視頻關(guān)鍵幀后接收所有其他數(shù)據(jù)。然而,這通常會增加連接延遲。你可以在你的編碼器調(diào)整關(guān)鍵幀間隔以減少延??遲。

最新版本的IE瀏覽器需要這個選項有效來進行正常播放。

wait_video on;

publish_notify

語法:?publish_notify on|off
上下文: rtmp, server, application

發(fā)送NetStream.Play.PublishNotify和NetStream.Play.UnpublishNotify給用戶。默認為關(guān)閉。

publish_notify on;

drop_idle_publisher

語法:?drop_idle_publisher timeout
上下文: rtmp, server, application

丟棄在指定時間內(nèi)發(fā)布者連接當(dāng)已經(jīng)空閑(無音頻/視頻數(shù)據(jù))。默認是關(guān)閉的。注意:這只能當(dāng)連接處于發(fā)布模式有效(在發(fā)送publish命令后)。

drop_idle_publisher 10s;

sync

語法:?sync timeout
上下文: rtmp, server, application

同步的音頻和視頻流。如果訂戶帶寬不夠以接收發(fā)布速率數(shù)據(jù),某些幀被服務(wù)器丟棄。這將導(dǎo)致同步問題。當(dāng)時間戳差值超過指定為同步參數(shù)的值絕對幀發(fā)送固定的。默認為300ms。

sync 10ms;

play_restart

語法:?play_restart on|off
上下文: rtmp, server, application

如果啟用,當(dāng)每次發(fā)布者開始或停止發(fā)布時,nginx_RTMP發(fā)送NetStream.Play.Start和NetStream.Play.Stop到每個注冊者。如果禁用,每個注冊者只在開始和重放結(jié)束時接收到這些通知。默認是off。

play_restart off;

idle_streams

語法:?idle_streams on|off
上下文: rtmp, server, application

如果禁用, nginx_RTMP禁止訂閱者連接到空閑/不存在的實時流,并且當(dāng)流發(fā)布者斷開連接時,斷開所有訂閱者的連接。默認為on。

idle_streams off;

?

?

?

record

語法:?record [off|all|audio|video|keyframes|manual]*
上下文: rtmp, server, application, recorder

切換錄音模式。流可以被記錄在FLV文件。該指令指定正是應(yīng)記錄哪些:

  • off -?不記錄在所有
  • all -?音頻和視頻(一切)
  • audio -音頻
  • video -??視頻
  • keyframes -唯一的關(guān)鍵幀視頻
  • manual -?從來沒有自動啟動記錄儀,使用控制界面來啟動/停止

可以有鍵,在一個記錄指令任何相容組合。

record all;record audio keyframes;

record_path

語法:?record_path path
上下文: rtmp, server, application, recorder

指定將錄制的FLV文件來記錄路徑。

record_path /tmp/rec;

record_suffix

語法:?record_suffix value
上下文: rtmp, server, application, recorder

設(shè)置記錄文件的后綴。默認為'。FLV“。

record_suffix _recorded.flv;

記錄后綴可以是的strftime格式的模式。下面的指令

record_suffix -%d-%b-%y-%T.flv;

將產(chǎn)生的形式mystream-24-Apr-13-18:23:38.flv 所有支持的strftime格式選項可以的strftime手冊頁上找到。

record_unique

語法:?record_unique on|off
上下文: rtmp, server, application, recorder

如果打開追加當(dāng)前的時間戳,以錄制的文件。否則,同樣的文件,每次新的記錄發(fā)生重寫。默認是關(guān)閉的

record_unique on;

record_append

語法:?record_append on|off
上下文: rtmp, server, application, recorder

切換文件追加模式。當(dāng)錄音機打開追加新數(shù)據(jù)舊文件或創(chuàng)建它時,它的缺失。有舊的數(shù)據(jù),并在文件中的新數(shù)據(jù)之間不存在時間間隙。默認是關(guān)閉的。

record_append on;

record_lock

語法:?record_lock on|off
上下文: rtmp, server, application, recorder

當(dāng)打開當(dāng)前記錄的文件被鎖住的fcntl調(diào)用。這可以從其他地方進行檢查,以找出正在錄制的文件。默認是關(guān)閉的。

record_lock on;

在FreeBSD上可以使用的羊群工具來檢查。在Linux上的flock?和fcntl是無關(guān)的,所以你只剩下編寫一個簡單的腳本文件檢查鎖定狀態(tài)。下面是這種腳本isunlocked.py的一個例子。

#!/usr/bin/pythonimport fcntl, syssys.stderr.close() fcntl.lockf(open(sys.argv[1], "a"), fcntl.LOCK_EX|fcntl.LOCK_NB)

record_max_size

語法:?record_max_size size
上下文: rtmp, server, application, recorder

設(shè)置最大記錄文件大小

record_max_size 128K;

record_max_frames

語法:?record_max_frames nframes
上下文: rtmp, server, application, recorder

設(shè)置每個錄像文件的視頻幀的最大數(shù)量。

record_max_frames 2;

record_interval

語法:?record_interval time
上下文: rtmp, server, application, recorder

重新啟動該數(shù)字(毫)秒后拍攝。默認關(guān)閉。零表示記錄之間沒有延遲。如果record_unique是關(guān)閉的,那么所有的記錄片段被寫入到同一個文件。否則,時間戳就會追加這使得文件不同(因為record_interval大于1秒以上)。

record_interval 1s;record_interval 15m;

recorder

語法:?recorder name {...}
上下文: application

創(chuàng)建記錄塊。多個刻錄機可以withing單一的應(yīng)用程序來創(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

語法:?record_notify on|off
上下文: rtmp, server, application, recorder

切換發(fā)送NetStream.Record.Start和NetStream.Record.Stop狀態(tài)信息(的onStatus),以發(fā)行時的具體記錄開始或停止錄音文件。狀態(tài)描述字段保存記錄的域名(空默認記錄器)。默認關(guān)閉。

recorder myrec {record all manual;record_path /var/rec;record_notify on; }

?

?

?

?Video on demand?視頻點播

play

語法:?play dir|http://loc [dir|http://loc]*
上下文: rtmp, server, application


從指定目錄或HTTP位置播放FLV或MP4文件。如果參數(shù)前綴以http://那么假定文件應(yīng)該從遠程HTTP位置播放前下載。注意打不啟動,直到整個文件下載。您可以使用nginx的本地緩存本地計算機上的文件。

多個播放位置可以在一個單一的播放指令指定。當(dāng)多個播放指令指定的位置列被合并,并從更高的作用域繼承。發(fā)揮每個位置試圖直到成功定位被發(fā)現(xiàn)。如果沒有找到這樣的位置錯誤狀態(tài)被發(fā)送到客戶端

索引FLV是為了隨機搜索能力。未編入索引FLV是玩謀求/暫停禁用(僅重啟動模式)。使用的FLV索引(例如,yamdi)索引。

如果您播放錄制的記錄指令FLV文件,請不要打前忘記他們的索引。在創(chuàng)建未編入索引。

如果視頻和音頻編解碼器是由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 locationplay /var/local_mirror http://myserver.com/vod; }

播放 /var/flvs/dir/file.flv:

ffplay rtmp://localhost/vod//dir/file.flv

VOD后的兩條斜線使ffplay使用VOD和應(yīng)用程序名稱和URL作為playpath的其余部分。

play_temp_path

語法:?play_temp_path dir
上下文: rtmp, server, application

設(shè)置將在其中遠程VOD播文件的播放之前存儲位置。默認值是/ tmp;

play_temp_path /www; play http://example.com/videos;

play_local_path

語法:?play_local_path dir
上下文: rtmp, server, application

設(shè)置從哪里目錄play_temp_path復(fù)制遠程點播文件,他們完全下載后的位置。空值禁用該功能。默認情況下它是空的。該特征可用于在本地緩存遠程文件。

此路徑應(yīng)該是相同的裝置,play_temp_path上。

# 在/tmp/videos上搜索文件 # 如果沒有找到就找遠程的location上尋找 # 而且儲存在/tmp/videos play_local_path /tmp/videos; play /tmp/videos http://example.com/videos;

Relay ?中繼

pull

語法:?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)建拉流中繼 ,流從遠程計算機上拉,并且成為本地可用。它僅當(dāng)至少一個播放流正在玩本地流發(fā)生。

Url syntax:?[rtmp://]host[:port][/app[/playpath]].?

如果應(yīng)用程序丟失,則使用本地應(yīng)用程序的名稱。如果playpath缺少那么當(dāng)前流的名字來代替。

以下參數(shù)被支持:

  • app -?明確應(yīng)用程序的名稱
  • name -?綁定繼電器當(dāng)?shù)亓髅?如果為空或不指定,則應(yīng)用程序中的所有當(dāng)?shù)氐南鞅焕?/li>
  • tcUrl -?如果空的自動構(gòu)建
  • pageUrl - 偽裝網(wǎng)頁網(wǎng)址
  • swfUrl -?SWF網(wǎng)址假裝
  • flashVer -?flash版本假裝,默認為“LNX.11,1,102,55”
  • playPath - 遠程播放路徑
  • live - 切換特殊行為直播,值:0,1
  • start -?以秒為單位的開始時間
  • stop -??在幾秒鐘內(nèi)停止時間
  • static -?使靜態(tài)拉流 如拉在nginx的啟動創(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)該使用引號圍繞整個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

語法:?push url [key=value]*
上下文: application

推動具有相同的語法拉動。不像推拉指令發(fā)布流遠程服務(wù)器。

push_reconnect

語法:?push_reconnect time
上下文: rtmp, server, application

重新連接超時之前等待的推后斷開連接。默認設(shè)置為3秒。

push_reconnect 1s;

session_relay

語法:?session_relay on|off
上下文: rtmp, server, application

切換會話中繼模式。在這種模式下中繼當(dāng)連接關(guān)閉時被破壞。當(dāng)設(shè)置為關(guān)閉時,流關(guān)閉,使得其他的中繼也可能會被以后創(chuàng)建的繼電器被破壞。默認是關(guān)閉的。

session_relay on; ?

?

Notify

on_connect

語法:?on_connect url
上下文: rtmp, server

設(shè)置HTTP連接回調(diào)。當(dāng)客戶發(fā)送一個連接命令時,一個 HTTP 請求異步發(fā)送,命令處理將被暫停,直到它返回結(jié)果代碼。當(dāng) HTTP 2XX 碼(成功狀態(tài)碼)返回時,RTMP 會話繼續(xù)。返回碼 3XX (重定向狀態(tài)碼)會使 RTMP 重定向到另一個從 HTTP 返回頭里獲取到的 application。否則(其他狀態(tài)碼)連接丟棄。

?

注意:這個指令在application域內(nèi)是不允許的,因為application在connect階段還是未知的。

HTTP請求接收多個參數(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

除了上述項目明確地傳遞給connect命令的所有參數(shù)也與回調(diào)發(fā)送。您應(yīng)當(dāng)區(qū)分連接參數(shù)從播放/發(fā)布參數(shù)。玩家通常具有播放/流發(fā)布名設(shè)置連接字符串分開的一種特殊方式。作為一個例子下面是這些參數(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

語法:?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會議
  • HTTP重定向3XX RTMP另一個流的名字是從位置HTTP響應(yīng)頭拍攝。如果新的流名字開始與rtmp://?代替創(chuàng)建,繼而遠程中繼會被創(chuàng)建。中繼需要IP地址被指定,而不是域名,只用nginx的版本低于1.3.10更大的工作。又見notify_relay_redirect。
  • 否則,RTMP連接斷開


重定向的例如

http {...location /local_redirect {rewrite ^.*$ newname? permanent;}location /remote_redirect {# no domain name here, only iprewrite ^.*$ 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.10on_play http://localhost:8080/remote_redirect;}... }

HTTP請求接收多個參數(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

除了上述項目通過明確玩命令的所有參數(shù)也與回調(diào)發(fā)送。

例如,如果流與URL訪問 rtmp://localhost/app/movie?a=100&b=face&foo=bar?then?a,?b?&?foo?也會被發(fā)送回來

?

on_play http://example.com/my_callback;

on_publish

語法:?on_publish url
上下文: rtmp, server, application

上面這個指令設(shè)置了發(fā)布命令回調(diào),唯一的區(qū)別一樣on_play。代替遠程拉推在這種情況下進行的。

on_done

語法:?on_done url
上下文: rtmp, server, application

設(shè)置 play/publish ?終止回調(diào)。上述所有適用于此。然而HTTP狀態(tài)代碼不檢查此回調(diào)。

on_play_done

語法:?on_play_done url
上下文: rtmp, server, application

和?on_done 一樣的行為?但只作用于 play和?event?

on_publish_done

語法:?on_publish_done url
上下文: rtmp, server, application

相同的行為on_done?但只作用于 publish?和?event?

on_record_done

語法:?on_record_done url
上下文: rtmp, server, application, recorder

設(shè)置record_done回調(diào)。除了常見的HTTP回調(diào)變量它接收到以下值

  • recorder - recorder name in config or empty string for inline recorder?在配置或空字符串內(nèi)聯(lián)錄音機錄像機名
  • path - ?錄制的文件路徑

Example

on_record_done http://example.com/recorded;

on_update

語法:?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的時期。如果請求返回比2XX連接其他HTTP結(jié)果被終止。這可用于同步過期會話。另外兩個參數(shù)的 時間和時間戳 傳遞到該處理程序

  • time??從?play/publish 回調(diào)開始的時間
  • timestamp?is RTMP timestamp of the last audio/video packet sent to the client?發(fā)送到客戶端的最后的音頻/視頻分組的RTMP時間戳

您可以使用時間戳參數(shù)單獨限制播放時長為每個用戶。

on_update http://example.com/update;

notify_update_timeout

語法:?notify_update_timeout timeout
上下文: rtmp, server, application

集on_update回調(diào)之間超時。默認值是30秒。

notify_update_timeout 10s; on_update http://example.com/update;

notify_update_strict

語法:?notify_update_strict on|off
上下文: rtmp, server, application

對于切換回調(diào)on_update嚴(yán)格模式。默認是關(guān)閉的。當(dāng)所有的連接錯誤打開,超時以及HTTP分析錯誤和空的反應(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

語法:?notify_relay_redirect on|off
上下文: rtmp, server, application

啟用對on_play和on_publish遠程重定向本地流重定向。新的流名字是用于遠程重定向RTMP網(wǎng)址的MD5哈希值。默認是關(guān)閉的。

notify_relay_redirect on;

notify_method

語法:?notify_method get|post
上下文: rtmp, server, application, recorder

設(shè)置通知的HTTP方法。默認值是POST與?application/x-www-form-urlencoded content type.在某些情況下得到的是可取的,例如,如果您打算處理Nginx的HTTP {}部分呼叫。在這種情況下,你可以使用arg_*變量訪問參數(shù)。

notify_method get;

在HTTP GET方法處理?http{}部分可以做這樣

location /on_play {if ($arg_pageUrl ~* localhost) {return 200;}return 500; } ?-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

HLS

語法:?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請求(例如,在開發(fā)過程中)的問題add_header Access-Control-Allow-Origin *;}} }

hls_path

語法:?hls_path path
上下文: rtmp, server, application

設(shè)置HLS播放列表和片段目錄。如果該目錄不存在,將會被創(chuàng)建。

hls_fragment

語法:?hls_fragment time
上下文: rtmp, server, application

設(shè)置HLS片段長度。默認為5秒。

hls_playlist_length

語法:?hls_playlist_length time
上下文: rtmp, server, application

設(shè)置播放列表HLS長度。默認為30秒。

hls_playlist_length 10m;

hls_sync

語法:?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時間戳同步的閾值。默認為2ms。此功能可以防止從低分辨率RTMP(1KHz的)轉(zhuǎn)換為高分辨率MPEG-TS(90KHz的)之后產(chǎn)生的噼啪的噪聲。

hls_sync 100ms;

hls_continuous

語法:?hls_continuous on|off
上下文: rtmp, server, application

切換HLS連續(xù)模式。在這種模式下HLS序列號從它上一次停止處開始。舊fragment依然保留。默認是關(guān)閉的。

hls_continuous on;

hls_nested

語法:?hls_nested on|off
上下文: rtmp, server, application

切換HLS嵌套模式。在這種模式下hls_path的子目錄為每個數(shù)據(jù)流創(chuàng)建。播放列表和片段在子目錄中創(chuàng)建。默認是關(guān)閉的。

hls_nested on;

hls_base_url

語法:?hls_base_url url
上下文: rtmp, server, application

設(shè)置HLS播放列表項基本URL。當(dāng)空這些項目沒有前綴并且假設(shè)是在相同的位置父播放列表或低一個級別時使用hls_nested。此功能同時適用于主(變量)和從HLS播放列表。它可以讓你下載播放列表,因為它包含兒童播放列表或片段完全引用本地播放。默認為空。

hls_base_url http://myserver.com/hls/;

hls_cleanup

語法:?hls_cleanup on|off
上下文: rtmp, server, application

切換HLS清理。默認情況下,該功能已開啟。在這種模式下nginx的緩存管理器進程會刪除HLS目錄老HLS片段和播放列表。

hls_cleanup off;

hls_fragment_naming

語法:?hls_fragment_naming sequential|timestamp|system
上下文: rtmp, server, application

設(shè)置片段的命名方式

  • sequential -?使用增加的整數(shù)
  • timestamp -??使用流時間戳
  • system -使用系統(tǒng)時間

默認值是連續(xù)的

hls_fragment_naming system;

hls_fragment_naming_granularity

語法:?hls_fragment_naming_granularity number
上下文: rtmp, server, application

設(shè)置HLS片段IDS粒度。如果大于零,改變IDS來劃分提供的價值。默認值是零。

# use system time rounded to 500ms as fragment names hls_fragment_naming system; hls_fragment_naming_granularity 500;

hls_fragment_slicing

語法:?hls_fragment_slicing plain|aligned
上下文: rtmp, server, application

設(shè)置片段切片模式。

  • plain -?當(dāng)達到目標(biāo)時的持續(xù)時間片段切換
  • aligned -開關(guān)片段時傳入的時間戳片段持續(xù)時間的倍數(shù)。該模式使得能夠產(chǎn)生不同的nginx實例相同片段

默認值是?plain.

hls_fragment_slicing aligned;

hls_variant

語法:?hls_variant suffix [param*]
上下文: rtmp, server, application

添加HLS變項(variant entry 變量條目,翻譯不準(zhǔn)確)。當(dāng)后綴是在流名稱匹配,然后,對用hls_variant指示當(dāng)前應(yīng)用程序中指定的所有條目當(dāng)前流創(chuàng)建播放列表中的變體。不帶后綴名剝離用作變量流名稱。原來的流像往常一樣處理。

以下后綴可選參數(shù)追加到播放列表M3U8 EXT-X-STREAM-INF。見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

語法:?hls_type live|event
上下文: rtmp, server, application

設(shè)置HLS playlist type在X-PLAYLIST-TYPE 播放列表指令。live? HLS流通常是從當(dāng)前播放位置(是一些fragment)到播放列表末尾播放。event HLS流總是從playlist起始位置開始播放。event模式要確保playlist的長度對整個事件足夠大。默認值是live;

hls_type event;

hls_keys

語法:?hls_keys on|off
上下文: rtmp, server, application

啟用HLS加密。 AES-128的方法用來加密整個HLS片段。默認關(guān)閉。

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

語法:?hls_key_path path
Context: rtmp, server, application

設(shè)置將在其中自動生成HLS密鑰保存的目錄。密鑰文件與在OpenSSL RAND_bytes()例行程序創(chuàng)建的.key延伸和偽隨機的16字節(jié)的內(nèi)容。如果該目錄不存在,它在運行時創(chuàng)建的。默認情況下,hls_path目錄用于密鑰文件??。但是請記住,你通常應(yīng)該限制訪問關(guān)鍵文件,這是容易當(dāng)這些文件從播放列表和片段分開存放。

hls_key_path /tmp/keys;

hls_key_url

語法:?hls_key_url url
上下文: rtmp, server, application

設(shè)置HLS密鑰文件條目的URL。當(dāng)空這些項目沒有前綴和密鑰被認為是在相同的位置播放列表。默認為空

hls_key_url https://myserver.com/keys/;

用上述設(shè)定例的播放列表條目

#EXT-X-KEY:METHOD=AES-128,URI="https://myserver.com/keys/337.key",IV=0x00000000000000000000000000000151

hls_fragments_per_key

語法:?hls_fragments_per_key value
上下文: rtmp, server, application

設(shè)置具有相同的密鑰加密的HLS片段的數(shù)目。零意味著只有一個密鑰的發(fā)布開始創(chuàng)建,并在會話中的所有片段與此密鑰加密。默認值是零。

hls_fragments_per_key 10;

MPEG-DASH?MPEG組織批準(zhǔn)了MPEG-DASH(HTTP動態(tài)自適應(yīng)流媒體)標(biāo)準(zhǔn)

dash

語法:?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請求(例如,在開發(fā)過程中)的問題add_header Access-Control-Allow-Origin *;}} }

dash_path

語法:?dash_path path
上下文: rtmp, server, application

設(shè)置MPEG-DASH播放列表,片段目錄。如果該目錄不存在,它將被創(chuàng)建。

dash_fragment

語法:?dash_fragment time
上下文: rtmp, server, application

設(shè)置MPEG-DASH片段長度。默認為5秒。

dash_playlist_length

語法:?dash_playlist_length time
上下文: rtmp, server, application

設(shè)置MPEG-DASH播放列表的長度。默認為30秒。

dash_playlist_length 10m;

dash_nested

語法:?dash_nested on|off
上下文: rtmp, server, application

切換MPEG-DASH嵌套模式。在這種模式下dash_path的子目錄為每個數(shù)據(jù)流創(chuàng)建。播放列表和片段在子目錄中創(chuàng)建。默認是關(guān)閉的。

dash_nested on;

dash_cleanup

語法:?dash_cleanup on|off
上下文: rtmp, server, application

切換MPEG-DASH清理。默認情況下,該功能已開啟。在這種模式下nginx的緩存管理器進程從MPEG-DASH目錄中刪除舊的MPEG-DASH碎片和體現(xiàn)。流清單被刪除后,初始化片段被刪除。

dash_cleanup off;

Access log

access_log

語法:?access_log off|path [format_name]
上下文: rtmp, server, application

設(shè)置訪問日志參數(shù)。日志默認情況下開啟。要關(guān)閉它使用ACCESS_LOG關(guān)閉指令。默認情況下訪問日志記錄是為了同一個文件的HTTP訪問記錄器(log/ access.log)。您可以指定訪問日志指令另一個日志文件的路徑。第二個參數(shù)是可選的。它可用于通過名稱來指定記錄格式。見log_format指令有關(guān)格式的詳細信息。

log_format new '$remote_addr'; access_log logs/rtmp_access.log new; access_log logs/rtmp_access.log; access_log off;

log_format

語法:?log_format format_name format
上下文: rtmp

創(chuàng)建一個名為日志格式。日志格式看起來非常相同的nginx的HTTP日志格式。幾個變量的日志格式中支持:

  • 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

默認的日志格式有名稱相結(jié)合。下面是這種格式的定義

$remote_addr [$time_local] $command "$app" "$name" "$args" - $bytes_received $bytes_sent "$pageurl" "$flashver" ($session_readable_time)

Limits

max_connections

語法:?max_connections number
上下文: rtmp, server, application

設(shè)置RTMP發(fā)動機的最大連接數(shù)。默認關(guān)閉

max_connections 100;

Statistics

統(tǒng)計模塊是不同于此處列出的所有其他模塊NGINX HTTP模塊。因此,統(tǒng)計指令應(yīng)位于HTTP {}塊之內(nèi)

rtmp_stat

語法:?rtmp_stat all
上下文: http, server, location

設(shè)置RTMP統(tǒng)計處理當(dāng)前的HTTP位置。 RTMP統(tǒng)計是動態(tài)的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

語法:?rtmp_stat_stylesheet path
上下文: http, server, location

添加XML樣式表引用統(tǒng)計XML,使其在瀏覽器查看。見rtmp_stat說明和示例的詳細信息。

Multi-worker live streaming

多進程直播通過推流剩余nginx的工人執(zhí)行。

rtmp_auto_push

語法:?rtmp_auto_push on|off
上下文: root

切換自動推(多進程直播)模式。默認是關(guān)閉的。

rtmp_auto_push_reconnect

語法:?rtmp_auto_push_reconnect timeout
上下文: root

設(shè)置自動推送重新連接超時,當(dāng)工作進程被殺害。默認值是100毫秒。

rtmp_socket_dir

語法:?rtmp_socket_dir dir
上下文: root

設(shè)置用于流推動UNIX域套接字目錄。默認值是/ 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模塊。下面是如何使能控制一個例子。

http { ...server {listen 8080;server_name localhost;....location /control {rtmp_control all;}} }

有控制模塊內(nèi)的幾個子模塊的每個控制不同的功能。

錄制

該子模塊啟動和停止與手動標(biāo)志創(chuàng)建記錄。語法:

http://server.com/control/record/start|stop?srv=SRV&app=??APP&name=NAME&rec=REC

SRV = SRV - 可選的服務(wù)器{}塊RTMP {}塊中號,默認為第一個服務(wù)器{}塊
應(yīng)用= APP - 所需的應(yīng)用程序名稱
NAME =名稱 - 需要流名稱
REC = REC - 可選的記錄名稱,默認為根(未命名)記錄

rtmp {server {listen 1935;application myapp {live on;recorder rec1 {record all manual;record_suffix all.flv;record_path /tmp/rec;record_unique on;}}} }用下面的命令發(fā)布該流ffmpeg -i http://someserver.com/mychannel.ts -c:v copy -c:a nellymoser -ar 44100 -ac 1 -f flv rtmp://localhost/myapp/mystream使用下面的命令來啟動和停止錄音

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"

如果記錄開始/停止請求有時會返回什么都沒有,你應(yīng)該檢查,如果你使用多進程,單個進程的比較好刪除 drop該子模塊提供了一種簡單的方法來刪除客戶端連接。語法:http://server.com/control/drop/publisher|subscriber|client?srv=SRV&app=APP&name=NAME&addr=ADDR&clientid=CLIENTIDsrv, app, name -相同

addr - 可選的客戶端地址(同樣由rtmp_stat返回)
clientid??- 可選nginx的客戶端ID(日志和統(tǒng)計顯示)
第一種方法 刪除/發(fā)布者 發(fā)行下降的連接??。第二方法是 刪除或者客戶端刪除,如果沒有指定地址每連接匹配addr參數(shù)或所有客戶端(包括出版商)。

? 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 ?

Redirect 重定向

?

重定向播放/客戶端發(fā)布到一個新的數(shù)據(jù)流。語法:

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 -?新的流名重定向到

? ?

?

Debug log

如果您需要解決您可能需要觀看調(diào)試日志流的問題。對于--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

你可以用任何語言編寫的exec包裝。然而,你應(yīng)該注意終止進程。當(dāng)出版商關(guān)閉流的所有執(zhí)行處理被終止。如果指定的exec指令,而不是真正的ffmpeg的包裝,那么你最終可能會與你的ffmpeg還活著,孤兒,直到超時讀取輸入數(shù)據(jù)。

該解決辦法是用信號陷阱。下面是在bash這種包裝的一個例子。

#!/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

該腳本注冊它終止子的ffmpeg SIGTERM處理器。 nginx的,RTMP發(fā)送默認的信號是SIGKILL不能被捕獲。對于上面的腳本按預(yù)期的行為,你需要exec_kill_signal指令來改變EXEC終止信號。它接受數(shù)字或符號信號名稱(POSIX.1-1990信號)。這里的示例應(yīng)用程序。

application myapp {live on;exec /var/scripts/exec_wrapper.sh $name;exec_kill_signal term; }application myapp2 {live on; }

?

?

?

?

?

?

Examples 一些實例

?

簡單的視頻點播

rtmp {server {listen 1935;application vod {play /var/flvs;}} }

簡單的直播服務(wù)

rtmp {server {listen 1935;application live {live on;}} }

重新翻譯遠程流

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支持遠程流

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;}} }

物流通過RTMP你的X屏幕

ffmpeg -f x11grab -follow_mouse centered -r 25 -s cif -i :0.0 -f flv rtmp://localhost/myapp/screen

Set 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)計)

在瀏覽器中輸入?http://localhost:8080/stat??看到目前的流媒體統(tǒng)計,連接的客戶端,帶寬等。

Publishing with ffmpeg

發(fā)布現(xiàn)場視頻流最簡單的方法是使用的ffmpeg(或avconv)。它已經(jīng)安裝在大多數(shù)系統(tǒng)中,也方便安裝在其他的上面。

RTMP僅支持的編解碼器的數(shù)量有限。最流行的RTMP視頻編解碼器是H264,索倫森-H263(又名FLV)和音頻編解碼器AAC,MP3,得到Nellymoser,Speex語音。

如果您的視頻與這些編解碼器編碼(最常見的是對H264 / AAC),那么你不需要任何轉(zhuǎn)換。否則,你需要將視頻轉(zhuǎn)換為支持的編解碼之一。

我們將流測試文件?/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/mystream

Streaming 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/mystream

Streaming 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/mystream

Streaming 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/mystream

Publishing video from webcam

ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264 -an -f flv rtmp://localhost/myapp/mystream

Playing with ffplay

ffplay rtmp://localhost/myapp/mystream

Publishing and playing with flash

See?test/rtmp-publisher?directory for test flash applets and html.

總結(jié)

以上是生活随笔為你收集整理的视频直播点播nginx-rtmp开发手册中文版的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。