Replay Module

Required Permissions: slobs.scene-transitions

The replay module can be used to control the Streamlabs OBS replay buffer. The Streamlabs OBS replay buffer continuously records the last X seconds (where is X configurable) of streaming output. When a replay is captured via clicking a button, hotkey, or app API, the contents of that buffer are flushed to disk as a video file. This API allows you to control this module and gain access to the contents of a replay after it has been saved.

📘

The replay buffer must be both enabled and started (running) in order to save a replay.

ReplayBufferState object

PropertyTypeDescription
statusrunning |
stopping |
offline |
saving
The current state of the replay buffer.
statusTimestringAn ISO8601 timestamp representing the time that the last status change occurred.

This object describes describes the current state of the replay buffer output if it is enabled. This is similar in structure to the Streaming/Recording state from the StreamingRecording Module. This is due to the fact that the replay buffer is treated as an "output" the same as the streaming and recording outputs in OBS internally.

ReplayBufferFileInfo object

This object describes a single replay buffer video file. The id can be used to retrieve the actual contents of the file.

PropertyTypeDescription
idstringA unique identifier for this file that can be used to retrieve its contents.
filePathstringThe path to the file on the computer's hard drive. This can be useful for passing to a media source to play the file on stream. However, apps do not have filesystem access so this path cannot be used to access the file on disk. Use the id and getFileContents instead to securely access the contents of the file.

stateChanged event

This event will be emitted when the ReplayBufferState object changes. Your callback will be called with a ReplayBufferState object.

streamlabsOBS.v1.Replay.stateChanged(state => {
  console.log('Got state change', state);
});

fileSaved event

This event will be emitted when a replay file has been saved to the hard drive and is ready to be accessed. Your callback will be called with a ReplayBufferFileInfo object.

streamlabsOBS.v1.Replay.fileSaved(file => {
  console.log('New replay saved', file);
});

getState method

getState(): ReplayBufferState

Fetches the current state of the replay buffer output.

Arguments

None

Returns

This function returns a ReplayBufferState object.

Example

streamlabsOBS.v1.Replay.getState().then(state => {
  console.log('Got state', state);
});

startBuffer method

startBuffer(): void

Starts the replay buffer recording if it is not already started.

Arguments

None

Returns

None

Example

streamlabsOBS.v1.Replay.startBuffer();

stopBuffer method

stopBuffer(): void

Stops the replay buffer if it is currently running. If the buffer is in the stopping state, then calling this function will force it to stop immediately.

Arguments

None

Returns

None

Example

streamlabsOBS.v1.Replay.stopBuffer();

getEnabled method

getEnabled(): boolean

Fetches whether the replay buffer is currently enabled. The replay buffer must be enabled before you can perform any operation on it.

Arguments

None

Returns

A boolean value representing whether the replay buffer is currently enabled.

Example

streamlabsOBS.v1.Replay.getEnabled().then(enabled => {
  console.log('Buffer enabled', enabled);
});

setEnabled method

setEnabled(enabled: boolean): void

Either enables or disables the replay buffer. The replay buffer cannot be running when changes to this setting are made.

Arguments

  1. enabled: Pass true to enable the buffer, otherwise false

Returns

None

Example

streamlabsOBS.v1.Replay.setEnabled(true);

getDuration method

getDuration(): number

Returns the current duration in seconds of the replay buffer. This will be the length of replays that will be saved from this buffer.

Arguments

None

Returns

A number representing the duration in seconds of the replay buffer.

Example

streamlabsOBS.v1.Replay.getDuration().then(duration => {
  console.log('Buffer duration', duration);
});

setDuration method

setDuration(duration: number): void

Sets the duration of the replay buffer in seconds. This will be the length of replays that will be saved from this buffer. The replay buffer cannot be running when changes to this setting are made.

Arguments

  1. duration: A number representing the desired duration in seconds.

Returns

None

Example

streamlabsOBS.v1.Replay.setDuration(15);

save method

save(): void

Saves the current contents of the replay buffer as a replay on disk.

Arguments

None

Returns

None

Example

streamlabsOBS.v1.Replay.save();

getFileContents method

getFileContents(id: string): File

Retrieves the contents of the file represented by the given id.

🚧

Depending on the length of the replay buffer and the encoding used, the file contents can be quite large. Be careful to ensure you are not keeping references to these objects longer than you need to in order to avoid leaking memory.

Arguments

  1. id: The id of the file to retrieve

Returns

This function returns a File object that can be used to either embed the video or upload it to a web API for further processing.

Example

streamlabsOBS.v1.Replay.getFileContents('9ef7abad-9826-4465-bdaa-2121d6421f5e').then(file => {
  console.log('Got file!', file.name)
});