exec_block

The `exec_block` directive allows the execution of external commands in response to specific RTMP events.

Syntaxexec_block { command; }
Defaultnone
Context
Argumentsnone

Description

The exec_block directive is part of the NGINX RTMP module, which defines how external commands can be executed when certain events occur during RTMP stream handling, such as publishing or closing a stream. This functionality is crucial for integrating additional processing or notifications into streaming workflows in real-time applications.

When a stream is published or closed, the directive triggers the execution of a defined command or script, passing relevant parameters such as the stream name and client identifiers. This allows developers to automate tasks such as recording management, stream notification handling, or even transcoding jobs using external tools like FFmpeg. The command is executed in the context of the NGINX worker process that handles the request, facilitating real-time feedback on streaming activities.

Due to the potential impacts on performance and security, careful attention should be paid to the commands executed via exec_block. The directive is particularly useful in advanced streaming setups where custom behaviors are needed based on user interactions or stream events. However, improper configuration or execution can lead to performance bottlenecks or security vulnerabilities, making it vital to validate inputs and handle errors appropriately.

Config Example

rtmp {
    server {
        listen 1935;

        application live {
            live on;
            exec_block {
                exec /usr/local/bin/notify_stream.sh "$name";
            }
        }
    }
}

Ensure the external command can be executed by the NGINX worker process without security restrictions.

Test the command separately to ensure it behaves as expected when called from the NGINX context.

Be cautious about using commands that may have long execution times, as they could block the worker process. Please use asynchronous handling or threading if available.

← Back to all directives