nginx-rtmp-module模块指令

Core(核心)

rtmp

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

The block which holds all RTMP settings

本块包含所有RTMP设置

server

语法: server { ... }
上下文: rtmp

Declares RTMP server instance

声明RTMP服务器实例

rtmp {
  server {
  }
}
listen

语法: listen (addr[:port]|port|unix:path) [bind] [ipv6only=on|off] [so_keepalive=on|off|keepidle:keepintvl:keepcnt|proxy_protocol]
上下文: server

Adds listening socket to NGINX for accepting RTMP connections

将正在监听的套接字添加到NGINX以接受RTMP连接

server {
    listen 1935;
}
application

语法: application name { ... }
上下文: server

Creates RTMP application. Unlike http location application name cannot be a pattern.

创建RTMP应用。与http的location应用名字不同, 不能使用正则模式。

server {
    listen 1935;
    application myapp {
    }
}
timeout

语法: timeout value
上下文: rtmp, server

Socket timeout. This value is primarily used for writing. Most of time RTMP module does not expect any activity on all sockets except for publisher socket. If you want broken socket to get quickly disconnected use active tools like keepalive or RTMP ping. Default is 1 minute.

套接字超时。此值主要用于写入。大多数情况下,除发布者套接字之外,RTMP模块不希望在的所有套接字上都有任何活动。如果您希望断开的套接字能够快速断开连接,请使用诸如keepalive或RTMP ping之类的活动工具。默认值为1分钟。

timeout 60s;
ping

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

RTMP ping interval. Zero turns ping off. RTMP ping is a protocol feature for active connection check. A special packet is sent to remote peer and a reply is expected within a timeout specified with ping_timeout directive. If ping reply is not received within this time then connection is closed. Default value for ping is 1 minute. Default ping timeout is 30 seconds.

RTMP ping间隔。0为关闭ping。RTMP ping是用于主动连接检查的协议功能。一个特殊的数据包被发送到远程对等端,并且在用ping_timeout指令指定的超时内需要一个回复。如果在此时间内未收到ping回复,则连接将关闭。ping的默认值为1分钟。默认ping超时为30秒。

ping 3m;
ping_timeout 30s;
ping_timeout

语法: ping_timeout value
上下文: rtmp, server

See ping description above.

请参阅上面的ping描述。

max_streams

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

Sets maximum number of RTMP streams. Data streams are multiplexed into a single data stream. Different channels are used for sending commands, audio, video etc. Default value is 32 which is usually ok for many cases.

设置RTMP流的最大数量。数据流被多路复用为单个数据流。不同的通道用于发送命令、音频、视频等。默认值为32,在许多情况下通常可以。

max_streams 32;
ack_window

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

Sets RTMP acknowledge window size. It’s the number of bytes received after which peer should send acknowledge packet to remote side. Default value is 5000000.

设置RTMP确认窗口大小。它是接收到的字节数,在该字节数之后对等方应向远程端发送确认数据包。默认值为5000000。

ack_window 5000000;
chunk_size

语法: chunk_size value
上下文: rtmp, server

Maximum chunk size for stream multiplexing. Default is 4096. The bigger this value the lower CPU overhead. This value cannot be less than 128.

流多路复用的最大块大小。默认值为4096。该值越大,CPU开销越低。此值不能小于128。

chunk_size 4096;
max_queue
max_message

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

Maximum size of input data message. All input data comes split into messages (and further in chunks). A partial message is kept in memory while waiting for it to complete. In theory incoming message can be very large which can be a problem for server stability. Default value 1M is enough for many cases.

输入数据消息的最大大小。所有输入数据都被拆分为消息(并进一步分为块)。部分消息在等待完成时保留在内存中。理论上,传入消息可能非常大,这可能是服务器稳定性的问题。在许多情况下,默认值1M就足够了。

max_message 1M;
buflen

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

Sets default buffer length. Usually client sends RTMP set_buflen command before playing and resets this setting. Default is 1000 ms.

设置默认缓冲区长度。通常客户端在播放之前发送RTMP set_buflen命令并重置此设置。默认值为1000毫秒。

buflen 5s;
out_queue
out_cork

Access(访问)

allow

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

Allow publishing/playing from addresses specified or from all addresses. Allow/deny directives are checked in order of appearance.

允许从指定的地址或所有地址发布/播放。允许/拒绝指令按出现顺序进行检查。

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

Specifies external command with arguments to be executed on every stream published. When publishing stops the process is terminated. Full path to binary should be specified as the first argument. There are no assumptions about what this process should do. However this feature is useful with ffmpeg for stream transcoding. FFmpeg is supposed to connect to nginx-rtmp as a client and output transcoded stream back to nginx-rtmp as publisher. Substitutions of form var/{var} can be used within command line:

指定要在发布的每个流上执行的带有参数的外部命令。当发布停止时,进程将终止。二进制文件的完整路径应指定为第一个参数。没有关于这个过程应该做什么的假设。但是,这个功能对于ffmpeg流代码转换很有用。FFmpeg应该作为客户端连接到nginx rtmp,并将转码后的流输出回作为发布者的nginx rtmp。可以在命令行中使用var/{var}形式的替换:

  • $name - stream name 流名称
  • $app - application name 应用名称
  • $addr - client address 客户端地址
  • $flashver - client flash version 客户端flash版本
  • $swfurl - client swf url 客户端swf url
  • $tcurl - client tc url 客户端tc url
  • $pageurl - client page url 客户端页面url

Shell-style redirects can be specified in exec_push directive for writing output and accepting input. Supported are

外壳式重定向可以在exec_push指令中指定,用于写入输出和接受输入。支持的有

  • truncating output >file
  • appending output >>file
  • descriptor redirects like 1>&2
  • input <file

Make sure there’s no space between redirection character and stream name/number.

确保重定向字符和流名称/编号之间没有空格。

You can specify full path to the command to execute or short command name. In the latter case binary is looked up in directories specified by the PATH environment variable. By default nginx clears the environment which will usually make rtmp module run only binaries located in standard directories like /bin and /usr/bin. To make this always work please keep the original PATH variable value with the following nginx directive.

可以指定要执行的命令的完整路径,也可以指定短命令名。在后一种情况下,在PATH环境变量指定的目录中查找二进制文件。默认情况下,nginx会清除环境,这通常会使rtmp模块只运行位于标准目录(如/bin/usr/bin )中的二进制文件。要使其始终有效,请使用以下nginx指令保留原始PATH变量值。

env PATH; 

The following ffmpeg call transcodes incoming stream to HLS-ready stream (H264/AAC). FFmpeg should be compiled with libx264 support for this example to work.

下面的ffmpeg调用将传入流转码为HLS就绪流(H264/AAC)。FFmpeg应该使用libx264支持进行编译,以便此示例正常工作。

application src {
    live on;
    exec_push ffmpeg -i rtmp://localhost/src/$name -vcodec libx264 -vprofile baseline -g 10 -s 300x200 -acodec aac -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

Specifies external command with arguments to be executed on play event. The command is executed when first client connects to the stream and is killed when the last one disconnects. This directive makes it possible to pull remote stream in any format for local clients.

指定具有要在播放事件上执行的参数的外部命令。该命令在第一个客户端连接到流时执行,在最后一个客户端断开连接时终止。此指令使得可以为本地客户端提取任何格式的远程流。

The feature works reliably only in single-worker mode. The reason for this is we cannot make sure external process always connects to the right worker. It will obviously connect to a random one. While this will still work in most cases it’s not a recommended architecture, it will be unstable and buggy.

该功能仅在single-worker模式下可靠工作。原因是我们无法确保外部流程始终连接到正确的worker。它显然会连接到一个随机的。虽然这在大多数情况下仍然有效——但这不是推荐的体系结构,它将是不稳定和有缺陷的。

Directive arguments are the same as for exec_push.

指令参数与exec_push的指令参数相同。

application myapp {
    live on;
    exec_pull ffmpeg -i http://example.com/video_$name.ts -c copy -f flv rtmp://localhost/$app/$name;
}

In the above configuration exec_pull directive serves all streams. That leads to certain limitations on remote stream name format. It should be possible to construct the remote url using available variables like $app, $name etc. When it’s not possible you can add exec_options on directive which permits setting additional stream options in exec-family directives. The only option supported now is name option.

在上述配置中,exec_pull指令为所有流提供服务。这导致了对远程流名称格式的某些限制。应该可以使用可用变量(如$app$name等)构建远程url。如果不可能,您可以在指令上添加exec_options on ,从而允许在exec系列指令中设置其他流选项。现在唯一支持的选项是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 is an alias of exec_push

execexec_push的别名

exec_options

语法: exec_options on|off
上下文: rtmp, server, application (see #1316)

The directive toggles exec options mode. When activated you can add exec-family directive options. The only exec option supported is name. This option makes it possible to apply exec only to specified stream. Default if off.

该指令切换exec选项模式。激活后,可以添加exec族指令选项。唯一支持的exec选项是name。通过此选项,可以仅将exec应用于指定的流。如果禁用,则为默认设置。

exec_options on;
# call my_on_publish_command only for "mystream"
exec_publish my_on_publish_command name=mystream;

# call my_on_play_command only for "another"
exec_play my_on_play_command name=another;

# execute different ffmpeg's for different streams
exec_pull ffmpeg -i http://example.com/abc.ts -c copy -f flv rtmp://localhost/$name/$app name=mystream;
exec_pull ffmpeg -i http://my.example.com/tele.ts -c copy -f flv rtmp://localhost/$name/$app name=tv;
exec_pull ffmpeg -i http://another.example.com/hello/f.ts -c copy -f flv rtmp://localhost/$name/$app name=fun;
exec_static

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

Similar to exec but runs specified command at nginx start. Does not support substitutions since has no session context.

类似于exec,但在nginx启动时运行指定的命令。不支持替换,因为没有会话上下文。

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

Sets process termination signal. Default is kill (SIGKILL). You can specify numeric or symbolic name (for POSIX.1-1990 signals).

设置进程终止信号。默认为kill(SIGKILL)。您可以指定数字或符号名称(对于POSIX.1-1990信号)。

exec_kill_signal term;
exec_kill_signal usr1;
exec_kill_signal 3;
respawn

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

If turned on respawns child process when it’s terminated while publishing is still on. Default is on;

如果启用,则在终止时重新生成子进程,而发布仍处于启用状态。默认值为启用;

respawn off;
respawn_timeout

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

Sets respawn timeout to wait before starting new child instance. Default is 5 seconds.

将重生超时设置为在启动新的子实例之前等待。默认值为5秒。

respawn_timeout 10s;
exec_publish

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

Specifies external command with arguments to be executed on publish event. Return code is not analyzed. Substitutions of exec are supported here as well. In addition args variable is supported holding query string arguments.

指定具有要在发布事件上执行的参数的外部命令。未分析返回代码。这里也支持exec的替换。此外,支持args变量保存查询字符串参数。

exec_play

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

Specifies external command with arguments to be executed on play event. Return code is not analyzed. Substitution list is the same as for exec_publish.

指定具有要在播放事件上执行的参数的外部命令。未分析返回代码。替换列表与exec_publish的替换列表相同。

exec_play_done

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

Specifies external command with arguments to be executed on play_done event. Return code is not analyzed. Substitution list is the same as for exec_publish.

指定外部命令,其中包含要在play_done事件上执行的参数。未分析返回代码。替换列表与exec_publish的替换列表相同。

exec_publish_done

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

Specifies external command with arguments to be executed on publish_done event. Return code is not analyzed. Substitution list is the same as for exec_publish.

指定具有要在publish_done事件上执行的参数的外部命令。未分析返回代码。替换列表与exec_publish的替换列表相同。

exec_record_done

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

Specifies external command with arguments to be executed when recording is finished. Substitution of exec_publish are supported here as well as additional variables

指定录制完成时要执行的带有参数的外部命令。此处支持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)

示例

# track client info
exec_play bash -c "echo $addr $pageurl >> /tmp/clients";
exec_publish bash -c "echo $addr $flashver >> /tmp/publishers";

# convert recorded file to mp4 format
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

Toggles live mode i.e. one-to-many broadcasting.

切换直播模式,即一对多广播。

live on;
meta

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

Sets metadata sending mode. The value of on makes subscribers receive reconstructed metadata packets containing predefined fields like width, height etc. The value of copy makes clients receive exact copy of publisher metadata block including both standard and specific fields. The value of off turns off sending any RTMP metadata to subscribers. Defaults to on.

设置元数据发送模式。值on使订阅者接收包含预定义字段(如宽度、高度等)的重构元数据包。值copy使客户端接收发布者元数据块的精确副本,包括标准字段和特定字段。值off将关闭向订阅者发送任何RTMP元数据的功能。默认为on。

meta copy;
interleave

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

Toggles interleave mode. In this mode audio and video data is transmitted on the same RTMP chunk stream. Defaults to off.

切换交错模式。在这种模式下,音频和视频数据在相同的RTMP块流上传输。默认为关闭。

interleave on;
wait_key

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

Makes video stream start with a key frame. Defaults to off.

使视频流从关键帧开始。默认为off。

wait_key on;
wait_video

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

Disable audio until first video frame is sent. Defaults to off. Can be combined with wait_key to make client receive video key frame with all other data following it. However this usually increases connection delay. You can tune keyframe interval in your encoder to reduce the delay.

在发送第一个视频帧之前禁用音频。默认为off。可以与wait_key组合使用,使客户端接收视频关键帧及其后面的所有其他数据。但这通常会增加连接延迟。您可以调整编码器中的关键帧间隔以减少延迟。

Recent versions of IE need this option to be enabled for normal playback.

最新版本的IE需要启用此选项才能正常播放。

wait_video on;
publish_notify

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

Send NetStream.Play.PublishNotify and NetStream.Play.UnpublishNotify to subscribers. Defaults to off.

发送 NetStream.Play.PublishNotifyNetStream.Play.UnpublishNotify 给订阅者。默认为off。

publish_notify on;
drop_idle_publisher

语法: drop_idle_publisher timeout
上下文: rtmp, server, application

Drop publisher connection which has been idle (no audio/video data) within specified time. Default is off. Note this only works when connection is in publish mode (after sending publish command).

删除指定时间内一直处于空闲状态(没有音频/视频数据)的发布服务器连接。默认设置为关闭。请注意,这仅在连接处于发布模式时(发送publish命令后)有效。

drop_idle_publisher 10s;
sync

语法: sync timeout
上下文: rtmp, server, application

Synchronize audio and video streams. If subscriber bandwidth is not enough to receive data at publisher rate, some frames are dropped by server. This leads to synchronization problem. When timestamp difference exceeds the value specified as sync argument an absolute frame is sent fixing that. Default is 300ms.

同步音频和视频流。若订阅者带宽不足以以发布者速率接收数据,则服务器会丢弃一些帧。这会导致同步问题。当时间戳差异超过指定为同步参数的值时,将发送一个绝对帧来修复此问题。默认值为300ms。

sync 10ms;
play_restart

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

If enabled nginx-rtmp sends NetStream.Play.Start and NetStream.Play.Stop to each subscriber every time publisher starts or stops publishing. If disabled each subscriber receives those notifications only at the start and end of playback. Default is off.

如果启用nginx-rtmp,每次发布者开始或停止发布时,它都会向每个订阅者发送NetStream.Play.StartNetStream.Play.Stop。如果禁用,则每个订阅者仅在播放开始和结束时接收这些通知。默认为off。

play_restart off;
idle_streams

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

If disabled nginx-rtmp prevents subscribers from connecting to idle/nonexistent live streams and disconnects all subscribers when stream publisher disconnects. Default is on.

如果禁用nginx-rtmp阻止订阅者连接到空闲/不存在的直播流,并在流发布者断开连接时断开所有订阅者的连接。默认设置为on。

idle_streams off;

Record(录制)

record

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

Toggles record mode. Stream can be recorded in flv file. This directive specifies what exactly should be recorded:

切换录制模式。流可以记录在flv文件中。该指令具体规定了应记录的内容:

  • off - no recording at all 什么都不录制
  • all - audio & video (everything) 音频和视频(所有)
  • audio - audio 音频
  • video - video 视频
  • keyframes - only key video frames 仅关键视频帧
  • manual - never start recorder automatically, use control interface to start/stop 从不自动启动记录器,使用控制界面启动/停止

There can be any compatible combination of keys in a single record directive.

在单个记录指令中可以有任何兼容的键组合。

record all;
record audio keyframes;
record_path

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

Specifies record path to put recorded flv files to.

指定要将录制的flv文件放入的记录路径。

record_path /tmp/rec;
record_suffix

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

Sets record file suffix. Defaults to ‘.flv’.

设置记录文件后缀。默认为“.flv”。

record_suffix _recorded.flv;

Record suffix can be a pattern in strftime format. The following directive

记录后缀可以是strftime格式的模式。以下指令

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

will produce files of the form mystream-24-Apr-13-18:23:38.flv. All supported strftime format options can be found on strftime man page.

将生成格式为mystream-24-Apr-13-18:23:38.flv的文件。所有支持的strftime格式选项都可以在strftime手册页上找到。

record_unique

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

If turned on appends current timestamp to recorded files. Otherwise the same file is re-written each time new recording takes place. Default is off.

如果启用,则将当前时间戳附加到记录的文件中。否则,每次进行新的录制时都会重新写入相同的文件。默认为off。

record_unique on;
record_append

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

Toggles file append mode. When turned on recorder appends new data to the old file or creates it when it’s missing. There’s no time gap between the old data and the new data in file. Default is off.

切换文件附加模式。当打开时,记录器会将新数据附加到旧文件中,或者在旧文件丢失时创建新数据。文件中的旧数据和新数据之间没有时间间隔。默认为off。

record_append on;
record_lock

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

When turned on currently recorded file gets locked with fcntl call. That can be checked from elsewhere to find out which file is being recorded. Default is off.

当打开时,当前录制的文件会被fcntl调用锁定。可以从其他地方进行检查,以找出正在记录的文件。默认为off。

record_lock on;

On FreeBSD you can use flock tool to check that. On Linux flock and fcntl are unrelated so you are left with writing a simple script checking file lock status. Here’s an example of such script isunlocked.py.

在FreeBSD上,您可以使用flock工具进行检查。在Linux上,flockfcntl是不相关的,所以您只需要编写一个简单的脚本来检查文件锁定状态。下面是这样一个脚本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

Set maximum recorded file size.

设置最大记录文件大小。

record_max_size 128K;
record_max_frames

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

Sets maximum number of video frames per recorded file.

设置每个录制文件的最大视频帧数。

record_max_frames 2;
record_interval

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

Restart recording after this number of (milli)seconds. Off by default. Zero means no delay between recordings. If record_unique is off then all record fragments are written to the same file. Otherwise timestamp is appended which makes files differ (given record_interval is longer than 1 second).

在此(毫)秒后重新开始录制。默认情况下为关闭。0表示录制之间没有延迟。如果record_unique处于关闭状态,则所有记录片段都将写入同一文件。否则会附加时间戳,从而使文件不同(给定record_interval长于1秒)。

record_interval 1s;

record_interval 15m;
recorder

语法: recorder name {...}
上下文: application

Create recorder block. Multiple recorders can be created withing single application. All the above mentioned recording-related directives can be specified in recorder{} block. All settings are inherited from higher levels.

创建记录器块。在一个应用程序中可以创建多个记录器。上述所有与录制相关的指令都可以在记录器{}块中指定。所有设置都继承自更高级别。

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

Toggles sending NetStream.Record.Start and NetStream.Record.Stop status messages (onStatus) to publisher when specific recorder starts or stops recording file. Status description field holds recorder name (empty for default recorder). Off by default.

当特定记录器启动或停止录制文件时,切换向发布者发送 NetStream.Record.StartNetStream.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

Play flv or mp4 file from specified directory or HTTP location. If the argument is prefixed with http:// then it is assumed that file should be downloaded from remote http location before playing. Note playing is not started until the whole file is downloaded. You can use local nginx to cache files on local machine.

从指定的目录或HTTP位置播放flv或mp4文件。如果参数的前缀是http://,则假定文件应该在播放之前从远程http位置下载。只有下载完整个文件后,才能开始播放笔记。您可以使用本地nginx在本地机器上缓存文件。

Multiple play locations can be specified in a single play directive. When multiple play directives are specified the location lists are merged and inherited from higher scopes. An attempt to play each location is made until a successful location is found. If such location is not found error status is sent to client.

可以在单个play指令中指定多个播放位置。当指定了多个play指令时,位置列表将合并并从更高的作用域继承。尝试播放每个位置,直到找到成功的位置。如果找不到这样的位置,则向客户端发送错误状态。

Indexed FLVs are played with random seek capability. Unindexed FLVs are played with seek/pause disabled (restart-only mode). Use FLV indexer (for example, yamdi) for indexing.

带索引的FLV具有随机寻道功能。在禁用寻道/暂停的情况下播放未索引的FLV(仅限重新启动模式)。使用FLV索引器(例如yamdi)进行索引。

If you play FLVs recorded with the record directive please do not forget to index them before playing. They are created unindexed.

如果您播放根据 record 指令录制的FLV,请不要忘记在播放前对其进行索引。它们是在未编制索引的情况下创建的。

Mp4 files can only be played if both video and audio codec are supported by RTMP. The most common case is H264/AAC.

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

Playing /var/flvs/dir/file.flv:

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

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

The two slashes after vod make ffplay use vod and application name and the rest of the url as playpath.

vod后的两个斜杠使ffplay使用vod和应用程序名称以及url的其余部分作为播放路径。

play_temp_path

语法: play_temp_path dir
上下文: rtmp, server, application

Sets location where remote VOD files are stored before playing. Default is /tmp;

设置播放前存储远程VOD文件的位置。默认为/tmp

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

语法: play_local_path dir
上下文: rtmp, server, application

Sets location where remote VOD files copied from play_temp_path directory after they are completely downloaded. Empty value disables the feature. By default it’s empty. The feature can be used for caching remote files locally.

设置远程VOD文件完全下载后从play_temp_path目录复制的位置。空值将禁用该功能。默认情况下,它是空的。该功能可用于本地缓存远程文件。

This path should be on the same device as play_temp_path.

# search file in /tmp/videos.
# if not found play from remote location
# and store in /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]]. If application is missing then local application name is used. If playpath is missing then current stream name is used instead.

Url语法: [rtmp://]host[:port][/app[/playpath]]。若应用程序丢失,则使用本地应用程序名称。如果缺少播放路径,则使用当前流名称。

The following parameters are supported:

支持以下参数:

  • app - explicit application name 显式应用名称
  • name - local stream name to bind relay to; if empty or non-specified then all local streams within application are pulled 将转播绑定到的本地流名称;如果为空或未指定,则将拉取应用中的所有本地流
  • tcUrl - auto-constructed if empty 如果为空则自动构造
  • pageUrl - page url to pretend 伪装的页面网址
  • swfUrl - swf url to pretend 伪装的 swf url
  • flashVer - flash version to pretend, default is ‘LNX.11,1,102,55’ 要假装的flash版本,默认为“LNX.11,1102,55”
  • playPath - remote play path 远程播放路径
  • live - toggles special behavior for live streaming, values: 0,1 切换直播的特定行为,值:0,1
  • start - start time in seconds 开始时间(秒)
  • stop - stop time in seconds 停止时间(秒)
  • static - makes pull static, such pull is created at nginx start 使pull为静态,这样的pull是在nginx启动时创建的

If a value for a parameter contains spaces then you should use quotes around the WHOLE key=value pair like this : 'pageUrl=FAKE PAGE URL'.

如果参数的值包含空格,则应在整键=值对周围使用引号,如下所示:'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 has the same syntax as pull. Unlike pull push directive publishes stream to remote server.

Push的语法与pull的语法相同。不同于pull, push指令将流发布到远程服务器。

push_reconnect

语法: push_reconnect time
上下文: rtmp, server, application

Timeout to wait before reconnecting pushed connection after disconnect. Default is 3 seconds.

之前推送的连接断开后,重新连接前等待的超时。默认值为3秒。

push_reconnect 1s;
session_relay

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

Toggles session relay mode. In this mode relay is destroyed when connection is closed. When the setting is off relay is destroyed when stream is closed so that another relay could possibly be created later. Default is off.

切换会话转播模式。在这种模式下,当连接关闭时,转播会被销毁。当设置为off时,当流关闭时,转播会被销毁,这样以后可能会创建另一个转播。默认为off。

session_relay on;

Notify(通知)

on_connect

语法: on_connect url
上下文: rtmp, server

Sets HTTP connection callback. When clients issues connect command an HTTP request is issued asynchronously and command processing is suspended until it returns result code. If HTTP 2xx code is returned then RTMP session continues. The code of 3xx makes RTMP redirect to another application whose name is taken from Location HTTP response header. Otherwise connection is dropped.

设置HTTP连接回调。当客户端发出connect命令时,会异步发出HTTP请求,并暂停命令处理,直到返回结果代码。如果返回HTTP 2xx代码,则RTMP会话继续。3xx的代码使RTMP重定向到另一个应用,该应用的名称取自Location HTTP响应头。否则将断开连接。

Note this directive is not allowed in application scope since application is still unknown at connection stage.

请注意,在应用范围内不允许使用此指令,因为在连接阶段应用仍然未知。

HTTP request receives a number of arguments. POST method is used with application/x-www-form-urlencoded MIME type. The following arguments are passed to caller:

HTTP请求接收多个参数。POST方法与application/x-www-form-urlencoded MIME类型一起使用。将以下参数传递给调用者:

  • call=connect
  • addr - client IP address 客户端IP地址
  • app - application name 应用名
  • flashVer - client flash version 客户端flash版本
  • swfUrl - client swf url 客户端swf url
  • tcUrl - tcUrl
  • pageUrl - client page url 客户端页面url

In addition to the above mentioned items all arguments passed explicitly to connect command are also sent with the callback. You should distinguish connect arguments from play/publish arguments. Players usually have a special way of setting connection string separate from play/publish stream name. As an example here’s how these arguments are set in JWPlayer

除了上面提到的项之外,显式传递给connect命令的所有参数也将随回调一起发送。您应该区分连接参数和播放/发布参数。播放器通常有一种特殊的方式将连接字符串与播放/发布流名称分开设置。以下是JWPlayer中如何设置这些参数的示例

...
streamer: "rtmp://localhost/myapp?connarg1=a&connarg2=b",
file: "mystream?strarg1=c&strarg2=d",
...

Ffplay (with librtmp) example (ffplay(带librtmp)示例)

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播放回调。每次客户端发出播放命令时,都会异步发出HTTP请求,并暂停命令处理,直到返回结果代码。然后分析HTTP结果代码。

  • HTTP 2xx code continues RTMP session
  • HTTP 2xx代码继续RTMP会话
  • HTTP 3xx redirects RTMP to another stream whose name is taken from Location HTTP response header. If new stream name is started with rtmp:// then remote relay is created instead. Relays require that IP address is specified instead of domain name and only work with nginx versions greater than 1.3.10. See also notify_relay_redirect.
  • HTTP 3xx将RTMP重定向到另一个流,该流的名称取自Location HTTP响应头。如果新的流名称以rtmp:// 开头,则会创建远程转播。转播要求指定IP地址而不是域名,并且只能用于大于1.3.10的nginx版本。另请参见notify_relay_redirect
  • Otherwise RTMP connection is dropped
  • 否则RTMP连接将断开

Redirect example (重定向示例)

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 request receives a number of arguments. POST method is used with application/x-www-form-urlencoded MIME type. The following arguments are passed to caller:

HTTP请求接收多个参数。POST方法与application/x-www-form-urlencoded MIME类型一起使用。将以下参数传递给调用者:

  • call=play
  • addr - client IP address 客户端IP地址
  • clientid - nginx client id (displayed in log and stat) nginx客户端id(显示在日志和stat中)
  • app - application name 应用名称
  • flashVer - client flash version 客户端flash版本
  • swfUrl - client swf url 客户端swf url
  • tcUrl - tcUrl
  • pageUrl - client page url 客户端页面url
  • name - stream name 流名称

In addition to the above mentioned items all arguments passed explicitly to play command are also sent with the callback. For example if stream is accessed with the url rtmp://localhost/app/movie?a=100&b=face&foo=bar then a, b & foo are also sent with callback.

除了上面提到的项目之外,显式传递给play命令的所有参数也会随回调一起发送。例如,如果使用url rtmp://localhost/app/movie?a=100&b=face&foo=bar访问流,然后,abfoo也会随回调一起发送。

on_play http://example.com/my_callback;
on_publish

语法: on_publish url
上下文: rtmp, server, application

The same as on_play above with the only difference that this directive sets callback on publish command. Instead of remote pull push is performed in this case.

与上面的on_play相同,唯一的区别是该指令在发布命令时设置回调。在这种情况下,在这种情况下执行push而不是远程pull。

on_done

语法: on_done url
上下文: rtmp, server, application

Sets play/publish terminate callback. All the above applies here. However HTTP status code is not checked for this callback.

设置播放/发布终止回调。以上所有内容均适用于此。但是,不会为此回调检查HTTP状态代码。

on_play_done

语法: on_play_done url
上下文: rtmp, server, application

Same behavior as on_done but only for play end event.

行为与on_tone相同,但仅适用于播放结束事件。

on_publish_done

语法: on_publish_done url
上下文: rtmp, server, application

Same behavior as on_done but only for publish end event.

与on_tone的行为相同,但仅适用于发布结束事件。

on_record_done

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

Set record_done callback. In addition to common HTTP callback variables it receives the following values

设置record_done回调。除了常见的HTTP回调变量外,它还接收以下值

  • recorder - recorder name in config or empty string for inline recorder 配置中的录制器名称或内联录制器的空字符串
  • path - recorded file 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。如果请求返回的HTTP结果不是2xx,则终止连接。这可用于同步过期的会话。将另外两个参数 timetimestamp 传递给此处理程序:

  • time is the number of seconds since play/publish call 是自播放/发布调用以来的秒数
  • timestamp is RTMP timestamp of the last audio/video packet sent to the client 是发送到客户端的最后一个音频/视频数据包的RTMP时间戳

You can use timestamp argument to individually limit playback duration for each user.

您可以使用 timestamp 参数来单独限制每个用户的播放持续时间。

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

语法: notify_update_timeout timeout
上下文: rtmp, server, application

Sets timeout between on_update callbacks. Default is 30 seconds.

设置on_update 回调之间的超时。默认值为30秒。

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

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

Toggles strict mode for on_update callbacks. Default is off. When turned on all connection errors, timeouts as well as HTTP parse errors and empty responses are treated as update failures and lead to connection termination. When off only valid HTTP response codes other that 2xx lead to failure.

切换on_update 回调的严格模式。默认为off。打开时,所有连接错误、超时以及HTTP解析错误和空响应都将被视为更新失败,并导致连接终止。关闭时,只有2xx以外的有效HTTP响应代码会导致失败。

notify_update_strict on;
on_update http://example.com/update;
notify_relay_redirect

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

Enables local stream redirect for on_play and on_publish remote redirects. New stream name is MD5 hash of RTMP URL used for remote redirect. Default is off.

on_playon_publish远程重定向启用本地流重定向。新的流名称是用于远程重定向的RTMP URL的MD5哈希。默认为禁用。

notify_relay_redirect on;
notify_method

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

Sets HTTP method for notifications. Default is POST with application/x-www-form-urlencoded content type. In certain cases GET is preferable, for example if you plan to handle the call in http{} section of nginx. In this case you can use arg_* variables to access arguments.

设置通知的HTTP方法。默认为POST,带有application/x-www-form-urlencoded内容类型。在某些情况下,GET更可取,例如,如果您计划在nginx的http{}部分处理调用。在这种情况下,您可以使用arg_*变量来访问参数。

notify_method get;

With GET method handling notifications in http{} section can be done this way

使用GET方法,可以通过以下方式处理http{}部分中的通知

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

HLS(HTTP Live streaming)

hls

语法: hls on|off
上下文: rtmp, server, application

Toggles HLS on the application.

应用切换成HLS。

hls on;
hls_path /tmp/hls;
hls_fragment 15s;

In http{} section set up the following location for clients to play HLS.

在http{}部分中,为客户端设置以下位置以播放HLS。

http {
    ...
    server {
        ...
        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
            }
            root /tmp;
            add_header Cache-Control no-cache;

            # To avoid issues with cross-domain HTTP requests (e.g. during development)
            add_header Access-Control-Allow-Origin *;
        }
    }
}
hls_path

语法: hls_path path
上下文: rtmp, server, application

Sets HLS playlist and fragment directory. If the directory does not exist it will be created.

设置HLS播放列表和片段目录。如果目录不存在,将创建该目录。

hls_fragment

语法: hls_fragment time
上下文: rtmp, server, application

Sets HLS fragment length. Defaults to 5 seconds.

设置HLS片段长度。默认为5秒。

hls_playlist_length

语法: hls_playlist_length time
上下文: rtmp, server, application

Sets HLS playlist length. Defaults to 30 seconds.

设置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

Toggles HLS continuous mode. In this mode HLS sequence number is started from where it stopped last time. Old fragments are kept. Default is off.

切换HLS连续模式。在这种模式下,HLS序列号从上次停止的位置开始。旧的碎片被保留了下来。默认为禁用。

hls_continuous on;
hls_nested

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

Toggles HLS nested mode. In this mode a subdirectory of hls_path is created for each stream. Playlist and fragments are created in that subdirectory. Default is off.

切换HLS嵌套模式。在这种模式下,会为每个流创建hls_path的子目录。播放列表和片段将在该子目录中创建。默认为禁用。

hls_nested on;
hls_base_url

语法: hls_base_url url
上下文: rtmp, server, application

Sets base url for HLS playlist items. When empty those items have no prefix and assumed to be at the same location as parent playlist or one level lower when hls_nested is used. This feature applies both to master (variant) and slave HLS playlists. It can let you download the playlist and play it locally since it contains full references to child playlists or fragments. Empty by default.

设置HLS播放列表项的基本url。当为空时,这些项目没有前缀,并且假设与父播放列表位于同一位置,或者在使用hls_nested时位于更低的一级。此功能适用于主(变体)和从属HLS播放列表。它可以让你下载播放列表并在本地播放,因为它包含对子播放列表或片段的完整引用。默认情况下为空。

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

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

Toggles HLS cleanup. By default the feature is on. In this mode nginx cache manager process removes old HLS fragments and playlists from HLS directory.

切换HLS清理。默认情况下,该功能是打开的。在这种模式下,nginx缓存管理器进程从HLS目录中删除旧的HLS片段和播放列表。

hls_cleanup off;
hls_fragment_naming

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

Sets fragment naming mode.

设置片段命名模式。

  • sequential - use increasing integers 使用递增整数
  • timestamp - use stream timestamp 使用流时间戳
  • system - use system time 使用系统时间

Default is sequential. 默认为sequential 。

hls_fragment_naming system;
hls_fragment_naming_granularity

语法: hls_fragment_naming_granularity number
上下文: rtmp, server, application

Sets granularity for hls fragment ids. If above zero, changes ids to divide the provided value. Default is zero.

设置hls片段id的粒度。如果高于0,则更改id以除以提供的值。默认值为0。

# 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

Sets fragment slicing mode.

设置片段切片模式。

  • plain - switch fragment when target duration is reached 达到目标持续时间时切换碎片
  • aligned - switch fragment when incoming timestamp is a multiple of fragment duration. This mode makes it possible to generate identical fragments on different nginx instances 当传入时间戳是片段持续时间的倍数时切换片段。这种模式可以在不同的nginx实例上生成相同的片段

Default is plain. 默认为plain 。

hls_fragment_slicing aligned;
hls_variant

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

Adds HLS variant entry. When suffix is matched on stream name then variant playlist is created for the current stream with all entries specified by hls_variant directives in current application. Stripped name without suffix is used as variant stream name. The original stream is processed as usual.

添加HLS变体条目。当后缀在流名称上匹配时,将为当前流创建变体播放列表,其中包含当前应用程序中hls_variant指令指定的所有条目。不带后缀的条带名称用作变体流名称。原始流照常处理。

Optional parameters following the suffix are appended to EXT-X-STREAM-INF in m3u8 playlist. See HLS spec. 3.3.10. EXT-X-STREAM-INF for the full list of supported parameters.

后缀后面的可选参数附加到m3u8播放列表中的EXT-X-STREAM-INF。参见HLS规范3.3.10。EXT-X-STREAM-INF获取支持参数的完整列表。

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

            exec ffmpeg -i rtmp://localhost/src/$name
              -c:a aac -b:a 32k  -c:v libx264 -b:v 128K -f flv rtmp://localhost/hls/$name_low
              -c:a aac -b:a 64k  -c:v libx264 -b:v 256k -f flv rtmp://localhost/hls/$name_mid
              -c:a 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

Sets HLS playlist type specified in X-PLAYLIST-TYPE playlist directive. Live HLS stream is usually played from the current live position which is several fragments to the end of playlist. Event HLS stream is always played from the start of playlist. When in event mode make sure playlist length is enough for the whole event. Default is live;

设置X-PLAYLIST-TYPE播放列表指令中指定的HLS播放列表类型。实时HLS流通常从当前的实时位置播放,该位置是播放列表末尾的几个片段。事件HLS流始终从播放列表的开始播放。在 event 模式下,确保播放列表的长度足以容纳整个事件。默认为 live

hls_type event;
hls_keys

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

Enables HLS encryption. AES-128 method is used to encrypt the whole HLS fragments. Off by default.

启用HLS加密。使用AES-128方法对整个HLS片段进行加密。默认情况下为关闭。

hls_keys on;

Here’s the example configuration using the HLS encryption. This configuration requires that nginx is built with --with-http_ssl_module for https support.

以下是使用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
上下文: rtmp, server, application

Sets the directory where auto-generated HLS keys are saved. Key files have .key extension and pseudo-random 16-byte content created with the OpenSSL RAND_bytes() routine. If the directory does not exist it’s created in runtime. By default, hls_path directory is used for key files. Remember however you should normally restrict access to key files which is easier when these files are stored separately from playlist and fragments.

设置保存自动生成的HLS密钥的目录。密钥文件具有.key扩展名和使用OpenSSL RAND_bytes()例程创建的伪随机16字节内容。如果目录不存在,则在运行时创建该目录。默认情况下,hls_path目录用于密钥文件。然而,请记住,您通常应该限制对关键文件的访问,当这些文件与播放列表和片段分开存储时,这会更容易。

hls_key_path /tmp/keys;
hls_key_url

语法: hls_key_url url
上下文: rtmp, server, application

Sets url for HLS key file entries. When empty those items have no prefix and keys are assumed to be at the same location as the playlist. Empty by default.

设置HLS密钥文件项的url。当为空时,这些项目没有前缀,并且假设键与播放列表位于同一位置。默认情况下为空。

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

Example playlist entry with the above setting 具有上述设置的播放列表条目示例

#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

Sets the number of HLS fragments encrypted with the same key. Zero means only one key is created at the publish start and all fragments within the session are encrypted with this key. Default is zero.

设置使用相同密钥加密的HLS片段数。0意味着在发布开始时只创建一个密钥,并且会话中的所有片段都使用该密钥加密。默认值为0。

hls_fragments_per_key 10;

MPEG-DASH

dash

语法: dash on|off
上下文: rtmp, server, application

Toggles MPEG-DASH on the application.

应用切换成MPEG-DASH。

dash on;
dash_path /tmp/dash;
dash_fragment 15s;

In http{} section set up the following location for clients to play MPEG-DASH.

http{} 部分,为客户端设置以下位置以播放MPEG-DASH。

http {
    ...
    server {
        ...
        location /dash {
            root /tmp;
            add_header Cache-Control no-cache;

            # To avoid issues with cross-domain HTTP requests (e.g. during development)
            add_header Access-Control-Allow-Origin *;
        }
    }
}
dash_path

语法: dash_path path
上下文: rtmp, server, application

Sets MPEG-DASH playlist and fragment directory. If the directory does not exists it will be created.

设置MPEG-DASH播放列表和片段目录。如果目录不存在,将创建该目录。

dash_fragment

语法: dash_fragment time
上下文: rtmp, server, application

Sets MPEG-DASH fragment length. Defaults to 5 seconds.

设置MPEG-DASH片段长度。默认为5秒。

dash_playlist_length

语法: dash_playlist_length time
上下文: rtmp, server, application

Sets MPEG-DASH playlist length. Defaults to 30 seconds.

设置MPEG-DASH播放列表长度。默认为30秒。

dash_playlist_length 10m;
dash_nested

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

Toggles MPEG-DASH nested mode. In this mode a subdirectory of dash_path is created for each stream. Playlist and fragments are created in that subdirectory. Default is off.

切换MPEG-DASH嵌套模式。在这种模式下,将为每个流创建dash_path的子目录。播放列表和片段将在该子目录中创建。默认为禁用。

dash_nested on;
dash_cleanup

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

Toggles MPEG-DASH cleanup. By default the feature is on. In this mode nginx cache manager process removes old MPEG-DASH fragments and manifests from MPEG-DASH directory. Init fragments are deleted after stream manifest is deleted.

切换MPEG-DASH清理。默认情况下,该功能是打开的。在这种模式下,nginx缓存管理器进程从MPEG-DASH目录中删除旧的MPEG-DASH片段和清单。Init片段在删除流清单后被删除。

dash_cleanup off;

Access log(访问日志)

access_log

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

Sets access log parameters. Logging is turned on by default. To turn it off use access_log off directive. By default access logging is done to the same file as HTTP access logger (logs/access.log). You can specify another log file path in access_log directive. Second argument is optional. It can be used to specify logging format by name. See log_format directive for more details about formats.

设置访问日志参数。默认情况下,日志记录处于打开状态。要关闭它,请使用access_log off 指令。默认情况下,访问日志对同一个文件进行HTTP访问记录(logs/access.log)。您可以在access_log 指令中指定另一个日志文件路径。第二个参数是可选的。它可以用于按名称指定日志记录格式。有关格式的更多详细信息,请参阅log_format 指令。

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

语法: log_format format_name format
上下文: rtmp

Creates named log format. Log formats look very much the same as nginx HTTP log formats. Several variables are supported within log format:

创建命名的日志格式。日志格式看起来与nginx HTTP日志格式非常相似。日志格式中支持几个变量:

  • connection - connection number 连接号
  • remote_addr - client address 客户端地址
  • app - application name 应用名称
  • name - last stream name 最后一个流名称
  • args - last stream play/publish arguments 最后一个流 play/publish 参数
  • flashver - client flashVer 客户端flash 版本
  • swfurl - client swfUrl 客户端swf Url
  • tcurl - client tcUrl
  • pageurl - client pageUrl 客户端页面URL
  • command - play/publish commands sent by client: NONE, PLAY, PUBLISH, PLAY+PUBLISH 播放/发布客户端发送的命令: 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 SEC.MSEC格式的当前unix时间戳

Default log format has the name combined. Here’s the definition of this format

默认日志格式具有组合名称。这是这种格式的定义

$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

Sets maximum number of connections for rtmp engine. Off by default.

设置rtmp引擎的最大连接数。默认情况下为关闭。

max_connections 100;

Statistics(统计)

Statistics module is NGINX HTTP module unlike all other modules listed here. Hence statistics directives should be located within http{} block.

统计模块是NGINX HTTP模块,与此处列出的所有其他模块不同。因此,统计指令应该位于http{} 块中。

rtmp_stat

语法: rtmp_stat all
上下文: http, server, location

Sets RTMP statistics handler to the current HTTP location. RTMP statistics is dynamic XML document. To watch this document in browser as XHTML page use rtmp_stat_stylesheet directive.

将RTMP统计处理程序设置为当前HTTP位置。RTMP统计信息是动态XML文档。要在浏览器中以XHTML页面的形式观看此文档,请使用rtmp_stat_stylesheet指令。

http {
    server {
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            root /path/to/stat/xsl/file;
        }
    }
}
rtmp_stat_stylesheet

语法: rtmp_stat_stylesheet path
上下文: http, server, location

Adds XML stylesheet reference to statistics XML to make it viewable in browser. See rtmp_stat description and example for more information.

将XML样式表引用添加到统计信息XML,使其在浏览器中可见。有关更多信息,请参阅rtmp_stat说明和示例。

Multi-worker live streaming(多worker直播)

Multi-worker live streaming is implemented through pushing stream to remaining nginx workers.

多worker直播是通过将流推送给剩余的nginx worker来实现的。

rtmp_auto_push

语法: rtmp_auto_push on|off
上下文: root

Toggles auto-push (multi-worker live streaming) mode. Default is off.

切换自动推送(多worker直播)模式。默认为禁用。

rtmp_auto_push_reconnect

语法: rtmp_auto_push_reconnect timeout
上下文: root

Sets auto-push reconnect timeout when worker is killed. Default is 100 milliseconds.

设置worker被杀死时的自动推送重新连接超时。默认值为100毫秒。

rtmp_socket_dir

语法: rtmp_socket_dir dir
上下文: root

Sets directory for UNIX domains sockets used for stream pushing. Default is /tmp.

设置用于流推送的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

Control module is NGINX HTTP module and should be located within http{} block.

控制模块是NGINX HTTP模块,应位于http{}块内。

rtmp_control

语法: rtmp_control all
上下文: http, server, location

Sets RTMP control handler to the current HTTP location.

将RTMP控制处理程序设置为当前HTTP位置。

http {
    server {
        location /control {
            rtmp_control all;
        }
    }
}

More details about control module

有关控制模块的更多详细信息

参考

https://github.com/arut/nginx-rtmp-module

https://github.com/arut/nginx-rtmp-module/wiki/Directives

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值