exec_play

The exec_play directive in the NGINX RTMP module allows the execution of external programs when a stream is played.

Syntaxexec_play command ...;
Defaultnone
Context
Arguments1+

Description

The exec_play directive is designed for use within NGINX's RTMP module to execute specified external commands whenever a media stream is played. This feature is particularly useful for integrating additional functionalities such as logging, performing analytics, running analytics scripts, or triggering other automation tasks in response to STREAM_PLAY events. The directive takes one or more arguments, which typically include the command(s) to execute, along with any necessary parameters needed by those commands.

When defined, exec_play invokes the specified command every time a user plays a stream. It operates in a non-blocking manner, allowing NGINX to serve other requests simultaneously while the external program runs. It is essential to ensure that the external commands are idempotent or can handle multiple invocations gracefully, as they may be triggered multiple times during a single stream play session. Moreover, care should be taken in managing the output and return codes of these commands to prevent unexpected behaviors.

One common scenario for utilizing exec_play is to send notifications or update central monitoring systems whenever a stream is accessed. It is a powerful directive that can significantly enhance the usability of the streaming server by extending its capabilities through external automation.

Config Example

application live {
    live on;
    exec_play /usr/local/bin/my_script.sh $name;
}

Ensure external scripts are executable and have the correct permissions set.

Be cautious about the resource consumption of the external program, as it could affect the server's performance.

Handle command outputs or errors appropriately to avoid unexpected behaviors during stream playback.

← Back to all directives