Nginx RTMP 模块 nginx-rtmp-module 指令详解

来源:互联网 发布:做室内设计效果图软件 编辑:程序博客网 时间:2024/05/16 15:56

Directives

Core

rtmp

syntax: rtmp { ... }
context: root
The block which holds all RTMP settings

server

syntax: server { ... }
context: rtmp
Declares RTMP server instance

rtmp {  server {  }}

listen

syntax: listen (addr[:port]|port|unix:path) [bind] [ipv6only=on|off] [so_keepalive=on|off|keepidle:keepintvl:keepcnt]
context: server

Adds listening socket to NGINX for accepting RTMP connections

server {    listen 1935;}

application

syntax: application name { ... }
context: server

Creates RTMP application. Unlike http location application name cannotbe a pattern.

server {    listen 1935;    application myapp {    }}

timeout

syntax: timeout value
context: 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.

timeout 60s;

ping

syntax: ping value
context: rtmp, server

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

ping 3m;ping_timeout 30s;

ping_timeout

syntax: ping_timeout value
context: rtmp, server

See ping description above.

max_streams

syntax: max_streams value
context: rtmp, server

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

max_streams 32;

ack_window

syntax: ack_window value
context: rtmp, server

Sets RTMP acknowledge window size. It's the number of bytes received afterwhich peer should send acknowledge packet to remote side. Default value is5000000.

ack_window 5000000;

chunk_size

syntax: chunk_size value
context: rtmp, server

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

chunk_size 4096;

max_queue

max_message

syntax: max_queue value
context: rtmp, server

Maximum size of input data message. All input data comes split intomessages (and further in chunks). A partial message is kept in memory whilewaiting for it to complete. In theory incoming message can bevery large which can be a problem for server stability. Default value1M is enough for many cases.

max_message 1M;

out_queue

out_cork

Access

allow

Syntax: allow [play|publish] address|subnet|all
Context: 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

Syntax: deny [play|publish] address|subnet|all
Context: rtmp, server, application

See allow for description.

Exec

exec

Syntax: exec command arg*
Context: rtmp, server, application

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

  • $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-style redirects can be specified in exec directive for writing outputand accepting input. Supported are

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

The following ffmpeg call transcodes incoming stream to HLS-readystream (H264/AAC). FFmpeg should be compiled with libx264 & libfaac supportfor this example to work.

application src {    live on;    exec 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_static

Syntax: exec_static command arg*
Context: rtmp, server, application

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

exec_static ffmpeg -i http://example.com/video.ts -c copy -f flv rtmp://localhost/myapp/mystream;

exec_kill_signal

Syntax: exec_kill_signal signal
Context: rtmp, server, application

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

exec_kill_signal term;exec_kill_signal usr1;exec_kill_signal 3;

respawn

Syntax: respawn on|off
Context: rtmp, server, application

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

respawn off;

respawn_timeout

Syntax: respawn_timeout timeout
Context: rtmp, server, application

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

respawn_timeout 10s;

exec_publish

Syntax: exec_publish command arg*
Context: rtmp, server, application

Specifies external command with arguments to be executed onpublish event. Return code is not analyzed. Substitutions ofexecare supported here as well. In addition args variable is supportedholding query string arguments.

exec_play

Syntax: exec_play command arg*
Context: rtmp, server, application

Specifies external command with arguments to be executed onplay event. Return code is not analyzed. Substitution listis the same as forexec_publish.

exec_play_done

Syntax: exec_play_done command arg*
Context: rtmp, server, application

Specifies external command with arguments to be executed onplay_done event. Return code is not analyzed. Substitution listis the same as forexec_publish.

exec_publish_done

Syntax: exec_publish_done command arg*
Context: rtmp, server, application

Specifies external command with arguments to be executed onpublish_done event. Return code is not analyzed. Substitution listis the same as forexec_publish.

exec_record_done

Syntax: exec_record_done command arg*
Context: rtmp, server, application, recorder

Specifies external command with arguments to be executed whenrecording is finished. Substitution ofexec_publish are supported hereas well as additional variables path and recorder.

# track client infoexec_play bash -c "echo $addr $pageurl >> /tmp/clients";exec_publish bash -c "echo $addr $flashver >> /tmp/publishers";# convert recorded file to mp4 formatexec_record_done ffmpeg -y -i $path -acodec libmp3lame -ar 44100 -ac 1 -vcodec libx264 $path.mp4;

Live

live

Syntax: live on|off
Context: rtmp, server, application

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

live on;

meta

Syntax: meta on|off
Context: rtmp, server, application

Toggles sending metadata to clients. Defaults to on.

meta off;

interleave

Syntax: interleave on|off
Context: rtmp, server, application

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

interleave on;

wait_key

Syntax: wait_key on|off
Context: rtmp, server, application

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

wait_key on;

wait_video

Syntax: wait_video on|off
Context: rtmp, server, application

Disable audio until first video frame is sent. Defaults to off.Can be combined withwait_key to make client receive videokey frame with all other data following it. However this usuallyincreases connection delay. You can tune keyframe interval in yourencoder to reduce the delay.

wait_video on;

publish_notify

Syntax: publish_notify on|off
Context: rtmp, server, application

Send NetStream.Publish.Start and NetStream.Publish.Stop tosubscribers. Defaults to off.

publish_notify on;

drop_idle_publisher

Syntax: drop_idle_publisher timeout
Context: rtmp, server, application

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

drop_idle_publisher 10s;

sync

Syntax: sync timeout
Context: rtmp, server, application

Synchronize audio and video streams. If subscriber bandwidthis not enough to receive data at ublisher rate some frames aredropped by server. This leads to synchronization problem. When timestamp difference exceeds the value specified assync argument an absolute frame is sent fixing that. Default is 300ms.

sync 10ms;

play_restart

Syntax: play_restart on|off
Context: rtmp, server, application

If enabled nginx-rtmp sends NetStream.Play.Start and NetStream.Play.Stopto each subscriber every time publisher starts or stops publishing. If disabledeach subscriber receives those notifications only at the start and end ofplayback. Default is on.

play_restart off;

Record

record

syntax: record [off|all|audio|video|keyframes|manual]*
context: rtmp, server, application, recorder

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

  • 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

syntax: record_path path
context: rtmp, server, application, recorder

Specifies record path to put recorded flv files to.

record_path /tmp/rec;

record_suffix

syntax: record_suffix value
context: rtmp, server, application, recorder

Sets record file suffix. Defaults to '.flv'.

record_suffix _recorded.flv;

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

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

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

record_unique

syntax: record_unique on|off
context: rtmp, server, application, recorder

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

record_unique on;

record_append

syntax: record_append on|off
context: rtmp, server, application, recorder

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

record_append on;

record_lock

syntax: record_lock on|off
context: 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.

record_lock on;

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

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

record_max_size

syntax: record_max_size size
context: rtmp, server, application, recorder

Set maximum recorded file size.

record_max_size 128K;

record_max_frames

syntax: record_max_frames nframes
context: rtmp, server, application, recorder

Sets maximum number of video frames per recorded file.

record_max_frames 2;

record_interval

syntax: record_interval time
context: rtmp, server, application, recorder

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

record_interval 1s;record_interval 15m;

recorder

syntax: recorder name {...}
context: application

Create recorder block. Multiple recorders can be created withingsingle application. All the above mentioned recording-related directives can be specified inrecorder{} block. All settingsare 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

syntax: record_notify on|off
context: rtmp, server, application, recorder

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

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

Video on demand

play

Syntax: play dir|http://loc [dir|http://loc]*
Context: rtmp, server, application

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

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

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.

Mp4 files can only be played if both video and audio codec are supportedby RTMP. The most common case is 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:

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

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

play_temp_path

Syntax: play_temp_path dir
Context: rtmp, server, application

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

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

play_local_path

Syntax: play_local_path dir
Context: rtmp, server, application

Sets location where remote VOD files copied from play_temp_pathdirectory after they are completely downloaded. Empty valuedisables the feature. By default it's empty. The feature can be usedfor caching remote files locally.

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/videosplay_local_path /tmp/videos;play /tmp/videos http://example.com/videos;

Relay

pull

Syntax: pull url [key=value]*
Context: application

Creates pull relay. Stream is pulled from remote machineand becomes available locally. It only happens when at leastone player is playing the stream locally.

Url syntax: [rtmp://]host[:port][/app[/playpath]]. If applicationis missing then local application name is used. If playpath is missingthen current stream name is used instead.

The following parameters are supported:

  • app - explicit application name
  • name - local stream name to bind relay to; if empty or non-specified thenall local streams within application are pulled
  • tcUrl - auto-constructed if empty
  • pageUrl - page url to pretend
  • swfUrl - swf url to pretend
  • flashVer - flash version to pretend, default is 'LNX.11,1,102,55'
  • playPath - remote play path
  • live - toggles special behavior for live streaming, values: 0,1
  • start - start time in seconds
  • stop - stop time in seconds
  • static - makes pull static, such pull is created at nginx start

If a value for a parameter contains spaces then you should use quotes aroundtheWHOLE key=value pair like this : '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

Syntax: push url [key=value]*
Context: application

Push has the same syntax as pull. Unlike pull push directive publishes stream to remote server.

push_reconnect

Syntax: push_reconnect time
Context: rtmp, server, application

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

push_reconnect 1s;

session_relay

Syntax: session_relay on|off
Context: 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 relaycould possibly be created later. Default is off.

session_relay on;

Notify

on_connect

Syntax: on_connect url
Context: rtmp, server

Sets HTTP connection callback. When clients issues connect commandan HTTP request is issued asynchronously and command processing issuspended until it returns result code. If HTTP 2xx code is returnedthen RTMP session continues. The code of 3xx makes RTMP redirectto another application whose name is taken from Location HTTPresponse header. Otherwise connection is dropped.

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

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

  • call=connect
  • addr - client IP address
  • app - application name
  • flashVer - client flash version
  • swfUrl - client swf url
  • tcUrl - tcUrl
  • pageUrl - client page url

In addition to the above mentioned items all arguments passed explicitly to connect command are also sent with the callback. You should distinguishconnect arguments from play/publish arguments. Players usually have a specialway of setting connection string separate from play/publish stream name.As an example here's how these arguments are set in 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

Syntax: on_play url
Context: rtmp, server, application

Sets HTTP play callback. Each time a clients issues play commandan HTTP request is issued asynchronously and command processing issuspended until it returns result code. HTTP result code is then analyzed.

  • HTTP 2xx code continues RTMP session
  • HTTP 3xx redirects RTMP to another stream whose name is taken from Location HTTP response header. If new stream name is started withrtmp://then remote relay is created instead. Relays require that IP address isspecified instead of domain name and only work with nginx versionsgreater than 1.3.10. See alsonotify_relay_redirect.
  • Otherwise RTMP connection is dropped

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 withapplication/x-www-form-urlencoded MIME type. The following arguments arepassed to caller:

  • call=play
  • addr - client IP address
  • app - application name
  • flashVer - client flash version
  • swfUrl - client swf url
  • tcUrl - tcUrl
  • pageUrl - client page 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 isaccessed with the urlrtmp://localhost/app/movie?a=100&b=face&foo=bar thena, b & foo are also sent with callback.

on_play http://example.com/my_callback;

on_publish

Syntax: on_publish url
Context: rtmp, server, application

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

on_done

Syntax: on_done url
Context: rtmp, server, application

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

on_play_done

Syntax: on_publish_done url
Context: rtmp, server, application

Same behavior as on_done but only for play end event.

on_publish_done

Syntax: on_publish_done url
Context: rtmp, server, application

Same behavior as on_done but only for publish end event.

on_record_done

syntax: on_record_done url
context: rtmp, server, application, recorder

Set record_done callback. In addition to common HTTP callbackvariables it receives recorded file path.

on_record_done http://example.com/recorded;

on_update

syntax: on_update url
context: rtmp, server, application

Set update callback. This callback is called with period of notify_update_timeout. If a request returns HTTP result otherthan 2xx connection is terminated. This can be used to synchronizeexpired sessions. Additionaltime argument is passed to this handlerwhich is the number of seconds since play/publish call.

on_update http://example.com/update;

notify_update_timeout

syntax: notify_update_timeout timeout
context: rtmp, server, application

Sets timeout between on_update callbacks. Default is 30 seconds.

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

notify_update_strict

syntax: notify_update_strict on|off
context: rtmp, server, application

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

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

notify_relay_redirect

syntax: notify_relay_redirect on|off
context: rtmp, server, application

Enables local stream redirect for on_play and on_publish remoteredirects. New stream name is RTMP URL used for remote redirect.Default is off.

notify_relay_redirect on;

notify_method

syntax: notify_method get|post
context: rtmp, server, application, recorder

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

notify_method get;

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

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

HLS

hls

Syntax: hls on|off
Context: rtmp, server, application

Toggles HLS on the application.

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

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

http {    ...    server {        ...        location /hls {            types {                application/vnd.apple.mpegurl m3u8;            }            alias /tmp/hls;        }    }}

hls_path

Syntax: hls_path path
Context: rtmp, server, application

Sets HLS playlist and fragment directory. This directory shouldexist before NGINX starts.

hls_fragment

Syntax: hls_fragment time
Context: rtmp, server, application

Sets HLS fragment length. Defaults to 5 seconds.

hls_playlist_length

Syntax: hls_playlist_length time
Context: rtmp, server, application

Sets HLS playlist length. Defaults to 30 seconds.

hls_playlist_length 10m;

hls_sync

Syntax: hls_sync time
Context: rtmp, server, application

Sets HLS timestamp synchronization threshold. Default is 2ms.This feature prevents crackling noises after conversionfrom low-resolution RTMP (1KHz) to high-resolution MPEG-TS (90KHz).

hls_sync 100ms;

hls_continuous

Syntax: hls_continuous on|off
Context: rtmp, server, application

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

hls_continuous on;

hls_nested

Syntax: hls_nested on|off
Context: rtmp, server, application

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

hls_nested on;

hls_base_url

Syntax: hls_base_url url
Context: rtmp, server, application

Sets base url for HLS playlist items. When empty thoseitems have no prefix and assumed to be at the same locationas parent playlist or one level lower whenhls_nested isused. This feature applies both to master (variant) and slave HLS playlists. It can let you download the playlist and play itlocally since it contains full references to child playlists orfragments. Empty by default.

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

hls_cleanup

Syntax: hls_cleanup on|off
Context: rtmp, server, application

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

hls_cleanup off;

Access log

access_log

Syntax: access_log off|path [format_name]
Context: rtmp, server, application

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

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

log_format

Syntax: log_format format_name format
Context: rtmp

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

  • 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

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

Syntax: max_connections number
Context: rtmp, server, application

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

max_connections 100;

Statistics

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

rtmp_stat

Syntax: rtmp_stat all
Context: http, server, location

Sets RTMP statistics handler to the current HTTP location. RTMP statistics isdynamic XML document. To watch this document in browser as XHTML pageuse rtmp_stat_stylesheet directive.

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

rtmp_stat_stylesheet

Syntax: rtmp_stat_stylesheet path
Context: http, server, location

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

Multi-worker live streaming

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

rtmp_auto_push

Syntax: rtmp_auto_push on|off
Context: root

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

rtmp_auto_push_reconnect

Syntax: rtmp_auto_push_reconnect timeout
Context: root

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

rtmp_socket_dir

Syntax: rtmp_socket_dir dir
Context: root

Sets directory for UNIX domains sockets used for stream pushing.Default is /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.

rtmp_control

Syntax: rtmp_control all
Context: http, server, location

Sets RTMP control handler to the current HTTP location.

http {    server {        location /control {            rtmp_control all;        }    }}
原创粉丝点击