2016年8月18日12:42:35 参照官方文件https://github.com/arut/nginx-rtmp-module/wiki/Directives
请注意,这是粗翻译版,仅供参考,而不是精校版 后面会更新精校版
目录
- 核心
- rtmp
- server
- listen
- application
- timeout
- ping
- ping_timeout
- max_streams
- ack_window
- chunk_size
- max_queue
- max_message
- buflen
- out_queue
- out_cork
- 访问权限
- allow
- deny
- Exec 一簇函数(过程中经常调用一种函数)exec执行另一个程序的函数)
- 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协议
- 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动态自适应流媒体)
- dash
- dash_path
- dash_fragment
- dash_playlist_length
- dash_nested
- dash_cleanup
- 访问日志
- access_log
- log_format
- Limits 限制
- max_connections
- 数据统计
- rtmp_stat
- rtmp_stat_stylesheet
- Multi-worker live streaming 多线程直播流
- rtmp_auto_push
- rtmp_auto_push_reconnect
- rtmp_socket_dir
- Control 控制模块
- rtmp_control
上下文可以理解为,默认配置文件或参数,如果没有,因为每个函数都需要一些定义的参数和输入函数的参数,有些可以更少,但有些是必要的
核心
语法: rtmp { ... }上下文: root
声明RTMP服务器实例
rtmp { server { } }
语法: listen (addr[:port]|port|unix:path) [bind] [ipv6only=on|off] [so_keepalive=on|off|keepidle:keepintvl:keepcnt|proxy_protocol]上下文: server添加监听套接字NGINX接受RTMP连接
server { listen 1935;}
application
语法:application name { ... }
上下文: server
创建RTMP应用程序HTTP位置应用程序的名称不能是一种模式。
server { listen 1935; application myapp { } }
timeout 超时
语法:超时值上下文:RTMP,服务器
该值主要用于写入。大部分时间RTMP该模块预计不会对除发行插座外的所有套接字进行任何活动。如果您想快速断开插座,使用主动工具,如保存或RTMP平。默认为1分钟。
timeout 60s;
ping
语法: ping value上下文: rtmp, server
RTMP ping间隔。零变平。 RTMP平是协议功能的主动连接检查。一个特殊的数据包被发送到远程对等体和答复有望与ping_timeout指令指定的超时时间内。
如果ping回复未在此时间内收到然后关闭连接。平安默认值为1分钟。默认Ping超时是30秒。
ping 3m;ping_timeout 30s;ping_timeout
ping_timeout
语法: ping_timeout value
上下文: rtmp, server
见上面ping的描述
max_streams 单一流数据最大限制
语法: max_streams value上下文: rtmp, server
设置RTMP流的最大数目。数据流被复用成一个单一的数据流。不同信道用于发送命令,音频,视频等的默认值是32,它通常是确定为许多情况。
max_streams 32;
ack_window
语法: ack_window value上下文: rtmp, server
设置RTMP确认窗口的大小。它接收到的字节之后对等体应发送确认包到远程侧的次数。默认值是5000000。
ack_window 5000000;
chunk_size 数据块大小
语法: chunk_size value
上下文: rtmp, server
最大的块的大小为最大流复数。默认值是4096越大该值越低CPU开销。这个值不能小于128。
chunk_size 4096;
max_queue 最大队列数
语法: max_queue value
上下文: rtmp, server
照上面的语法习惯是这样,官方平没有给出文档,应该是设置最大连接数的参数,具体想知道这个是做什么的请参看源代码
max_message
语法: max_queue value上下文: rtmp, server
输入数据消息的最大大小。所有输入数据来源(成块,并进一步)分成的消息。的部分信息保存在内存中,而等待它完成。在理论上传入消息可以是非常大的,可以是对于服务器的稳定性的问题。默认值是1M足够许多情况下。
max_message 1M;
buflen 缓冲区
语法: buflen time上下文: rtmp, server
设置默认的缓冲区长度。通常客户端发送播放前RTMP set_buflen命令并重置该设置。默认值是1000毫秒。
buflen 5S;
out_queue
目前没有文档
out_cork
目前没有文档
Access 访问控制
allow
语法: 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
exec_push
语法: 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 >fileappending output >>filedescriptor redirects like 1>&2input <file
确保有重定向字符和流名称/编号之间没有空格。
您可以指定要执行的命令或短命令名的完整路径。在后一种情况下,二进制文件由PATH环境变量指定的目录中查找。默认情况下nginx的清除环境通常会使RTMP模块只运行位于标准目录如/ bin和/ USR / bin中的二进制文件。
为了使这个总是工作,请保持原来的PATH变量值具有以下nginx的指令。
env PATH;
下面的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
语法: 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
语法: exec command arg*
上下文: rtmp, server, application
EXEC是exec_push的别名
exec_options
语法: 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
语法: 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 signal上下文: rtmp, server, application
集进程终止的信号。默认值是杀(SIGKILL)。您可以指定数字或符号的名称(POSIX.1-1990信号)exec_kill_signal term;
exec_kill_signal usr1;
exec_kill_signal 3;
respawn
语法: respawn on|off
上下文: rtmp, server, application
如果重生子进程打开的时候同时发布仍然在它的终止。默认为上;
respawn off;
respawn_timeout
语法: respawn_timeout timeout上下文: rtmp, server, application
套重生超时开始新的子实例之前等待。默认值是5秒。
respawn_timeout 10s;
exec_publish
语法: exec_publish command arg*上下文: rtmp, server, application
指定与参数外部命令要在发布事件执行。返回代码不进行分析。 EXEC的替换是同时支持在这里。此外ARGS变量赞成举行查询字符串参数。
exec_play
语法: exec_play command arg*
上下文: rtmp, server, application
指定与要在打事件中执行参数外部命令。返回代码不进行分析。替代列表和exec_publish相同
exec_play_done
语法: exec_play_done command arg*
上下文: rtmp, server, application
指定与参数外部命令要在play_done事件执行。返回代码不进行分析. 替代列表和exec_publish相同
exec_publish_done
语法: exec_publish_done command arg*
上下文: rtmp, server, application
指定与参数外部命令要在publish_done事件执行。返回代码不进行分析. 替代列表和exec_publish相同
exec_record_done
语法: 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
live
语法: live on|off
上下文: rtmp, server, application
切换现场模式,即一对多的广播。
live on;
meta
语法: meta on|copy|off
上下文: rtmp, server, application
集元数据发送模式。上的价值,使用户收到一封包含像宽度,高度等的副本设定值,使客户得到出版商的元数据块的精确副本,包括标准和具体领域的预定义字段重建的元数据包。关的值将关闭发送任何RTMP元数据给用户。默认为on。
meta copy;
interleave
语法: interleave on|off
上下文: rtmp, server, application
切换交错模式。在这种模式下的音频和视频数据上相同的RTMP块流传输。默认为off。
interleave on;
wait_key
语法: wait_key on|off
上下文: rtmp, server, application
使视频流开始一个关键帧。默认为关闭。
wait_key on;
wait_video
语法: wait_video on|off
上下文: rtmp, server, application
直到第一个视频帧发送禁用音频。默认为关闭。可以用wait_key决定相结合,使客户端接收视频关键帧但其后所有其他数据。然而,这通常会增加连接延迟。你可以在你的编码器,以减少延迟调整关键帧间隔
IE浏览器的最新版本需要这个选项正常播放启用。
wait_video on;
publish_notify
语法: publish_notify on|off
上下文: rtmp, server, application
发送NetStream.Play.PublishNotify和NetStream.Play.UnpublishNotify给用户。默认为关闭。
publish_notify on;
drop_idle_publisher
语法: drop_idle_publisher timeout
上下文: rtmp, server, application
丢弃在指定时间内发行者连接这一直空闲(无音频/视频数据)。默认是关闭的。注意:这只能当连接处于发布模式(发送发布命令后)。
drop_idle_publisher 10s;
sync
语法: sync timeout
上下文: rtmp, server, application
同步的音频和视频流。如果订户带宽不够以接收发布速率数据,某些帧被服务器丢弃。这将导致同步问题。当时间戳差值超过指定为同步参数的值绝对帧发送固定的。默认为300ms。
sync 10ms;
play_restart
语法: play_restart on|off
上下文: rtmp, server, application
如果启用nginx的,RTMP发送NetStream.Play.Start和NetStream.Play.Stop到每个用户每次发行启动或停止发布。如果禁用每个用户只在开始和重放结束接收这些通知。默认是off。
play_restart off;
idle_streams
语法: idle_streams on|off
上下文: rtmp, server, application
如果禁用nginx的,RTMP防止连接到空闲/不存在的实时流用户,断开所有用户的数据流时,断开publisher。默认为on。
idle_streams off;
record
语法: record [off|all|audio|video|keyframes|manual]*
上下文: rtmp, server, application, recorder
切换录音模式。流可以被记录在FLV文件。该指令指定正是应记录哪些:
- off - 不记录在所有
- all - 音频和视频(一切)
- audio -音频
- video - 视频
- keyframes -唯一的关键帧视频
- 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
设置记录文件的后缀。默认为'。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
语法: record_unique on|off
上下文: rtmp, server, application, recorder
如果打开追加当前的时间戳,以录制的文件。否则,同样的文件,每次新的记录发生重写。默认是关闭的
record_unique on;
record_append
语法: record_append on|off
上下文: rtmp, server, application, recorder
切换文件追加模式。当录音机打开追加新数据旧文件或创建它时,它的缺失。有旧的数据,并在文件中的新数据之间不存在时间间隙。默认是关闭的。
record_append on;
record_lock
语法: 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
语法: record_max_size size
上下文: rtmp, server, application, recorder
设置最大记录文件大小
record_max_size 128K;
record_max_frames
语法: record_max_frames nframes
上下文: rtmp, server, application, recorder
设置每个录像文件的视频帧的最大数量。
record_max_frames 2;
record_interval
语法: record_interval time
上下文: rtmp, server, application, recorder
重新启动该数字(毫)秒后拍摄。默认关闭。零表示记录之间没有延迟。如果record_unique是关闭的,那么所有的记录片段被写入到同一个文件。否则,时间戳就会追加这使得文件不同(因为record_interval大于1秒以上)。
record_interval 1s;
record_interval 15m;
recorder
语法: 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
语法: 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;
}
Video on demand 视频点播
play
语法: 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
语法: play_temp_path dir
上下文: rtmp, server, application
设置将在其中远程VOD播文件的播放之前存储位置。默认值是/ tmp;
play_temp_path /www;
play http://example.com/videos;
play_local_path
语法: 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;
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.
创建拉流中继 ,流从远程计算机上拉,并且成为本地可用。它仅当至少一个播放流正在玩本地流发生。
Url syntax: [rtmp://]host[:port][/app[/playpath]]
.
如果应用程序丢失,则使用本地应用程序的名称。如果playpath缺少那么当前流的名字来代替。
以下参数被支持:
- app - 明确应用程序的名称
- name - 绑定继电器当地流名;如果为空或不指定,则应用程序中的所有当地的溪流被拉到
- tcUrl - 如果空的自动构建
- pageUrl - 伪装网页网址
- swfUrl - SWF网址假装
- flashVer - flash版本假装,默认为“LNX.11,1,102,55”
- playPath - 远程播放路径
- live - 切换特殊行为直播,值:0,1
- start - 以秒为单位的开始时间
- stop - 在几秒钟内停止时间
- static - 使静态拉流 如拉在nginx的启动创建
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
语法: push url [key=value]*
上下文: application
推动具有相同的语法拉动。不像推拉指令发布流远程服务器。
push_reconnect
语法: push_reconnect time
上下文: rtmp, server, application
重新连接超时之前等待的推后断开连接。默认设置为3秒。
push_reconnect 1s;
session_relay
语法: session_relay on|off
上下文: rtmp, server, application
切换会话中继模式。在这种模式下中继当连接关闭时被破坏。当设置为关闭时,流关闭,使得其他的中继也可能会被以后创建的继电器被破坏。默认是关闭的。
session_relay on;
Notify
on_connect
语法: on_connect url
上下文: rtmp, server
设置HTTP连接的回调。当客户端连接问题的命令HTTP请求是异步发出命令和处理被挂起,直到它返回结果代码。如果返回HTTP 2XX代码,然后RTMP会话继续。
3XX的代码使RTMP重定向到另一个应用程序的名字是从位置HTTP响应头拍摄。否则,连接被丢弃。
注意:这个指令不应用范围允许的,因为应用还处于连接阶段不明。
HTTP请求接收多个参数。 POST方法用于application/x-www-form-urlencoded MIME type ,下面的参数被传递给调用者:
- call=connect
- addr - client IP address
- app - application name
- flashVer - client flash version
- swfUrl - client swf url
- tcUrl - tcUrl
- pageUrl - client page url
除了上述项目明确地传递给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
语法: 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代码继续RTMP会议
- HTTP重定向3XX RTMP另一个流的名字是从位置HTTP响应头拍摄。如果新的流名字开始与rtmp:// 代替创建,继而远程中继会被创建。中继需要IP地址被指定,而不是域名,只用nginx的版本低于1.3.10更大的工作。又见notify_relay_redirect。
- 否则,RTMP连接断开
重定向的例如
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. 。下面的参数被传递给调用者:
- 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
除了上述项目通过明确玩命令的所有参数也与回调发送。
例如,如果流与URL访问 rtmp://localhost/app/movie?a=100&b=face&foo=bar
then a
, b
& foo
也会被发送回来
on_play http://example.com/my_callback;
on_publish
语法: on_publish url
上下文: rtmp, server, application
上面这个指令设置了发布命令回调,唯一的区别一样on_play。代替远程拉推在这种情况下进行的。
on_done
语法: on_done url
上下文: rtmp, server, application
设置 play/publish 终止回调。上述所有适用于此。然而HTTP状态代码不检查此回调。
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
设置record_done回调。除了常见的HTTP回调变量它接收到以下值
- recorder - recorder name in config or empty string for inline recorder 在配置或空字符串内联录音机录像机名
- 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:
设置更新回调。此回调调用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
语法: notify_update_timeout timeout
上下文: rtmp, server, application
集on_update回调之间超时。默认值是30秒。
notify_update_timeout 10s;
on_update http://example.com/update;
notify_update_strict
语法: 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
语法: notify_relay_redirect on|off
上下文: rtmp, server, application
启用对on_play和on_publish远程重定向本地流重定向。新的流名字是用于远程重定向RTMP网址的MD5哈希值。默认是关闭的。
notify_relay_redirect on;
notify_method
语法: 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
语法: 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
语法: hls_path path
上下文: rtmp, server, application
设置HLS播放列表和片段目录。如果该目录不存在,将会被创建。
hls_fragment
语法: hls_fragment time
上下文: rtmp, server, application
设置HLS片段长度。默认为5秒。
hls_playlist_length
语法: hls_playlist_length time
上下文: rtmp, server, application
设置播放列表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).
设置HLS时间戳同步的门槛。默认为2ms。此功能可以防止噼啪的噪声从低分辨率RTMP(1KHz的)转换为高分辨率MPEG-TS(90KHz的)之后。
hls_sync 100ms;
hls_continuous
语法: hls_continuous on|off
上下文: rtmp, server, application
切换HLS连续模式。在这种模式下HLS序列号从它停止了最后一次启动。旧片段依然古色古香。默认是关闭的。
hls_continuous on;
hls_nested
语法: hls_nested on|off
上下文: rtmp, server, application
切换HLS嵌套模式。在这种模式下hls_path的子目录为每个数据流创建。播放列表和片段在子目录中创建。默认是关闭的。
hls_nested on;
hls_base_url
语法: hls_base_url url
上下文: rtmp, server, application
设置HLS播放列表项基本URL。当空这些项目没有前缀并且假设是在相同的位置父播放列表或低一个级别时使用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
设置片段的命名方式
- sequential - 使用增加的整数
- timestamp - 使用流时间戳
- system -使用系统时间
默认值是连续的
hls_fragment_naming system;
hls_fragment_naming_granularity
语法: 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;