Skip to contentSkip to navigationSkip to topbar
Rate this Page:

Recording Rules


(warning)

Warning

This page is for reference only. We are no longer onboarding new customers to Programmable Video. Existing customers can continue to use the product until December 5, 2024(link takes you to an external page).
We recommend migrating your application to the API provided by our preferred video partner, Zoom. We've prepared this migration guide(link takes you to an external page) to assist you in minimizing any service disruption.


Overview

overview page anchor

There are two ways a Participant's video and audio tracks can be recorded in the cloud:

  • Set the record_participants_on_connect flag when creating the Room. When this flag is set, recording of the participant's video and audio tracks starts when the participant connects to the Room. With this approach all participants' video and audio tracks are recorded by default.
  • Use Recording Rules. The Recording Rules can be provided when the Room is created via the REST API or the rules can be set at any time during the lifetime of the Room via the Recording Rules resource.

The Recording Rules can be used to specify which participants and tracks should be recorded or not and they provide a fine grained approach for creating Recordings. For example, rules can be defined to simply start or stop recording or they can be defined so that only one participant in a Group Room is recorded. In addition, rules can specify if just the audio tracks should be recorded or both audio and video ones.

The Recording Rules API is only available in Group Rooms.



The RecordingRules Resource

rr-resource page anchor

The RecordingRules resource is a subresource of a Room instance resource. It represents the state of the recording rules for the specified Room.

Resource URI

rr-uri page anchor

For the sake of simplicity, we define the RecordingRules Resource URI as:


_10
RECORDING_RULES_URI = https://video.twilio.com/v1/Rooms/{RoomNameOrSid}/RecordingRules

One list of rules can be specified using the Recording Rules URI per Room. It can be updated anytime during the life of the Room to include/exclude video/audio Tracks.

Resource properties
room_sidtype: SID<RM>Not PII

The SID of the Room resource for the Recording Rules


rulestype: object[]Not PII

A collection of Recording Rules that describe how to include or exclude matching tracks for recording


date_createdtype: string<DATE TIME>Not PII

The date and time in GMT when the resource was created specified in ISO 8601(link takes you to an external page) format.


date_updatedtype: string<DATE TIME>Not PII

The date and time in GMT when the resource was last updated specified in ISO 8601(link takes you to an external page) format.

Get a Room's Recording Rules (HTTP GET)

rr-get page anchor

Returns the current state of the recording rules of the specified Room.

Modify a Room's Recording Rules (HTTP POST)

rr-post page anchor

Updates the recording rules of the specified Room. The following parameters are supported:

URI parameters
RoomSidtype: stringNot PII
Path Parameter

The SID of the Room resource where the recording rules to update apply.


Request body parameters
Rulestype: objectNot PII

A JSON-encoded array of recording rules.

For a deeper understanding on how recording rules work, see the Understanding Recording Rules section below.

This resource does not support PUT or DELETE.


Understanding Recording Rules

understanding-rr page anchor

Recording rules can be set at any time during the life of the Room. If the record_participants_on_connect flag is set to true during the Room creation then a default rule to record all video and audio tracks will be automatically set.

Specifying Recording Rules

specifying-rr page anchor

A recording rule instance has the following JSON structure:


_10
{"type": rule_type, filter_name: filter_value, filter_name: filter_value, ...}

Where:

FieldDescription
rule_typeAn identifier specifying the type of rule. It must be one of the following:-include: includes the tracks that match the filters into the Recordings.-exclude: excludes the tracks that match the filters from the Recordings.
filter_name and filter_valueThe filter_name must be one of the following:-all: the filter affects all tracks. Accepts only one value: true (matches all tracks)-kind: matches tracks of a given type. Accepts video and audio as values.-publisher: matches all tracks published by the Participant with the identity (case sensitive) or SID specified as value-track: matches tracks with the name (case sensitive) or SID specified as value. A rule containing multiple filters matches the set of tracks that comply with all of them. In other words, filters combine in a rule through a logical AND.

Based on this, recording rules are specified as a JSON array containing up to 20 rules. For example:


_10
Rules = [
_10
{"type": "include", "all": true}, //rule_1
_10
{"type": "exclude", "kind": "video"}, //rule_2
_10
{"type": "include", "publisher": "Bob", "track": "screen"}, //rule_3
_10
{"type": "include", "track": "MTXXXXXXXXXXXXXXXXXXXXXXXXXXX"}, //rule_4
_10
...
_10
rule_20
_10
]

Remember that valid recording rules comply with the following:

  • The maximum number of rules that can be specified is 20.
  • An empty set of rules (i.e. [] ) is not allowed.
  • A rule containing the "all" filter must have a value of true . Notice that this means false is not allowed.
  • A rule having an “all” filter cannot have any other filters.
  • A rule must contain a "type" field.
  • If the "kind" filter is used, its value must be either audio or video .
  • A rule cannot contain duplicated filters (e.g. specify two different kind s or publisher s)

When invalid rules are specified, the current active rules will not be updated and the POST will be answered with an HTTP 400 error response like the following:


_10
{
_10
"code": 53120,
_10
"message": "Invalid Recording Rule(s)",
_10
"more_info": "https://www.twilio.com/docs/errors/53120",
_10
"status": 400
_10
}

For example, the following requests are invalid:


_10
//Invalid because it's using an empty set
_10
Rules = []


_10
//Invalid because it uses false as value of "all"
_10
Rules = [
_10
{"type":"include", "all": false}
_10
]


_10
//Invalid because it specifies a non supported kind
_10
Rules = [
_10
{"type": "include", "all": true},
_10
{"type": "exclude", "kind": "video"}
_10
]


_10
//Invalid because it repeats the "kind" filter twice
_10
Rules = [
_10
{"type": "include", "kind": "audio", "kind": "video"},
_10
]


_10
//Invalid because an "all" filter is not compatible with any other filter
_10
Rules = [
_10
{"type": "include", "all": "true", "kind": "audio"},
_10
]

Recording Rules Semantics

rr-semantics page anchor

RecordingRules are enforced by Twilio using three main principles:

  1. Recording Rules semantics are based on Algebra of Sets(link takes you to an external page) .
  2. Recording Rules are stateless.
  3. Recording Rules are enforced declaratively.

1. Recording Rules Semantics are based on Algebra of Sets

sr-algebra page anchor

We define the Set of Recording Tracks (SetRT) as the set of tracks a given Room should be recording at any time. The SetRT is computed by Twilio using Algebra of Sets based on the following algorithm:

  • The SetRT is initialized to the empty set unless the record_participants_on_connect flag is set on Room creation.
  • The subscribe rules are applied to the SetRT using Algebra of Sets in the order provided such that:
    • For any include rule we perform the union of the SetRT with the set of tracks matching the rule filters.
    • For any exclude rule we perform the set difference of the SetRT with the set of tracks matching by the rule filters.
  • All the tracks remaining in SetRT after all the rules have been evaluated are the ones recorded.

If the record_participants_on_connect is set on Room creation then the SetRT is initialized to:


_10
{"type": "include", "all": true}

Let's illustrate this using an example. Imagine a Group Room with three participants named: Alice, Bob and Carl, who publish the tracks specified in the following table:

Alice (PTA)Bob (PTB)Carl (PTC)
Audio TrackMTA_A alice-audioMTB_A bob-audioMTC_A carl-audio
Video Track (cam)MTA_C alice-camMTB_C bob-camMTC_C carl-cam
Video Track (screen)MTA_S screenMTB_S screen

Notice that, for the sake of simplicity, we have assumed the following conventions:

  • Track SIDs have the prefix MT followed by the participant initial and by a letter identifying the track nature ( _A for audio, _C for webcam, and _S for screenshare).
  • Track names are specified under their corresponding SIDs.
Example: Start Recording all Participants
example-start-recording-all-participants page anchor

To record the audio and video tracks of all participants in a Room, POST the following to the Room's RecordingRules resource:


_10
Rules = [
_10
{"type": "include", "all": true}
_10
]

Recording will start for all Participants connected to the Room. Any new Participants who join will also be recorded.

Example: Stop Recording all Participants
example-stop-recording-all-participants page anchor

To stop the recording of all video and audio tracks of all participants in a Room, POST the following to the Room's RecordingRules resource:


_10
Rules = [
_10
{"type": "exclude", "all": true}
_10
]

This will stop the Recordings for all tracks. Note that Recordings can be started again some time later by reposting with the "include", "all" rule. New Recording SIDs will be created each time a track Recording is started.

Example: Only Record the audio tracks of all Participants
example-only-record-the-audio-tracks-of-all-participants page anchor

To restrict the recording to just the audio tracks of all participants in a Room, POST the following to the Room's RecordingRules resource:


_10
Rules = [
_10
{"type": "include", "kind": "audio"}
_10
]

Video tracks of participants will not be recorded.

Example: Record the video and audio of the one Participant and the audio tracks of all other Participants
example-record-the-video-and-audio-of-the-one-participant-and-the-audio-tracks-of-all-other-participants page anchor

In this scenario we want to record the video and audio of Alice while also recording the audio tracks of the other participants. To achieve this, POST the following to the Room's RecordingRules resource:


_10
Rules = [
_10
{"type": "include", "publisher": "Alice"},
_10
{"type": "include", "kind": "audio"}
_10
]

The video and audio tracks of Alice will be recorded and there will be an audio track Recording for any other Participant who joins the Room.

2. Recording Rules are stateless

rr-stateless page anchor

The Recording Rules API is stateless. This means that it has no memory of rules. Every time a developer POSTs a set of new recording rules, the previous rules are fully erased and replaced with new rules, which are then enforced using the algorithm described in the section above.

3. Recording Rules are enforced declaratively

rr-declarative page anchor

When developers POST recording rules to Twilio, those rules are enforced in a dynamic way. That means that the algorithm does not only execute at POST time, but it is executed every time there is change in the Room's available tracks. Hence, once the rules have been POSTed, Twilio guarantees that they are enforced at any time without requiring further developer intervention.


Update Room Recording Rules to Start Recording All Participants

update-room-recording-rules-to-start-recording-all-participants page anchor
Node.js
Python
C#
Java
PHP
Ruby
curl

_11
// Download the helper library from https://www.twilio.com/docs/node/install
_11
// Your Account Sid and Auth Token from twilio.com/console
_11
// and set the environment variables. See http://twil.io/secure
_11
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_11
const authToken = process.env.TWILIO_AUTH_TOKEN;
_11
const client = require('twilio')(accountSid, authToken);
_11
_11
client.video.rooms('RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.recordingRules
_11
.update({rules: [{"type": "include", "all": true}]})
_11
.then(recording_rules => console.log(recording_rules.roomSid));

Output

_11
{
_11
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"date_created": "2015-07-30T20:00:00Z",
_11
"date_updated": "2015-07-30T20:00:00Z",
_11
"rules": [
_11
{
_11
"type": "include",
_11
"all": true
_11
}
_11
]
_11
}

Update Room Recording Rules to Only Record Audio Tracks of All Participants

update-room-recording-rules-to-only-record-audio-tracks-of-all-participants page anchor
Node.js
Python
C#
Java
PHP
Ruby
curl

_11
// Download the helper library from https://www.twilio.com/docs/node/install
_11
// Your Account Sid and Auth Token from twilio.com/console
_11
// and set the environment variables. See http://twil.io/secure
_11
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_11
const authToken = process.env.TWILIO_AUTH_TOKEN;
_11
const client = require('twilio')(accountSid, authToken);
_11
_11
client.video.rooms('RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.recordingRules
_11
.update({rules: [{"type": "include", "kind": "audio"}]})
_11
.then(recording_rules => console.log(recording_rules.roomSid));

Output

_11
{
_11
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"date_created": "2015-07-30T20:00:00Z",
_11
"date_updated": "2015-07-30T20:00:00Z",
_11
"rules": [
_11
{
_11
"type": "include",
_11
"kind": "audio"
_11
}
_11
]
_11
}

Update Room Recording Rules to Stop Recording All Participants

update-room-recording-rules-to-stop-recording-all-participants page anchor
Node.js
Python
C#
Java
PHP
Ruby
curl

_11
// Download the helper library from https://www.twilio.com/docs/node/install
_11
// Your Account Sid and Auth Token from twilio.com/console
_11
// and set the environment variables. See http://twil.io/secure
_11
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_11
const authToken = process.env.TWILIO_AUTH_TOKEN;
_11
const client = require('twilio')(accountSid, authToken);
_11
_11
client.video.rooms('RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.recordingRules
_11
.update({rules: [{"type": "exclude", "all": true}]})
_11
.then(recording_rules => console.log(recording_rules.roomSid));

Output

_11
{
_11
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"date_created": "2015-07-30T20:00:00Z",
_11
"date_updated": "2015-07-30T20:00:00Z",
_11
"rules": [
_11
{
_11
"type": "exclude",
_11
"all": true
_11
}
_11
]
_11
}


Rate this Page: