record_lock

The record_lock directive controls file access for recording streams in the NGINX RTMP module, ensuring exclusive write access during stream recording.

Syntaxrecord_lock on | off;
Defaultoff
Context
Arguments1

Description

The record_lock directive is utilized within the NGINX RTMP module to manage how recording files are accessed during live streaming. By enabling record_lock, the server ensures that when a stream is being recorded, other processes attempting to modify the same file will be blocked until the recording is finished. This is crucial in preventing file corruption and data loss that could arise from concurrent write operations. It's particularly useful in scenarios where multiple streams might attempt to write to the same output file, granting a more reliable and stable recording operation.

The directive takes one argument, which can either be 'on' or 'off'. If 'on', the lock mechanism will be activated, whereas setting it to 'off' disables it, allowing for concurrent file access, which can be risky in terms of data integrity. The behavior of this directive should be considered in the context of the specific requirements of the streaming application; for example, while enabling the lock may impede performance slightly due to waiting for access, it offers greater safety for recorded output.

Config Example

application live {
    live on;
    record all;
    record_path /var/www/recordings;
    record_lock on;
}

Mistakenly using record_lock off can lead to file corruption if multiple streams write to the same output file concurrently.

Ensure the directive's context is correct; it must be placed inside an application context.

Not all storage backends may support locking, which could lead to unexpected behavior. Check file system capabilities.

← Back to all directives