Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Compositions


(warning)

Warning

This documentation 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, 2026(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

The Twilio Recording Composition API lets you transcode and combine the individual Track Recordings stored by the Twilio Video Recordings API. This API relies on the following REST resources:

  • The Composition Instance Resource : a Composition represents a media file created as a result of applying a set of media processing operations onto a number of source Recordings.
  • The Compositions List Resource represents the list of previously created Compositions.

These REST resources are located beneath of the following base URL:


_10
https://video.twilio.com



These are the URI schemes for the Recording Composition REST API and the supported methods:

  • /v1/Compositions/
    • GET : List Composition resources.
    • POST : Create new composition resource.
  • /v1/Compositions/{CompositionSid}
    • GET : Retrieve a Composition resource.
    • DELETE : Delete a Composition resource.
  • /v1/Compositions/{CompositionSid}/Media
    • GET : Retrieve a Composition media file sub-resource.

Composition Instance Resource

composition-instance-resource page anchor

Resource URI

resource-uri page anchor

_10
/v1/Compositions/{CompositionSid}

A Composition Instance Resource has the following properties

Resource properties
account_sidtype: SID<AC>Not PII

The SID of the Account(link takes you to an external page) that created the Composition resource.


statustype: enum<STRING>Not PII

The status of the composition. Can be: enqueued, processing, completed, deleted or failed. enqueued is the initial state and indicates that the composition request has been received and is scheduled for processing; processing indicates the composition is being processed; completed indicates the composition has been completed and is available for download; deleted means the composition media has been deleted from the system, but its metadata is still available for 30 days; failed indicates the composition failed to execute the media processing task.

Possible values:
enqueuedprocessingcompleteddeletedfailed

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_completedtype: string<DATE TIME>Not PII

The date and time in GMT when the composition's media processing task finished, specified in ISO 8601(link takes you to an external page) format.


date_deletedtype: string<DATE TIME>Not PII

The date and time in GMT when the composition generated media was deleted, specified in ISO 8601(link takes you to an external page) format.


sidtype: SID<CJ>Not PII

The unique string that we created to identify the Composition resource.


room_sidtype: SID<RM>Not PII

The SID of the Group Room that generated the audio and video tracks used in the composition. All media sources included in a composition must belong to the same Group Room.


audio_sourcestype: string[]PII MTL: 30 days

The array of track names to include in the composition. The composition includes all audio sources specified in audio_sources except those specified in audio_sources_excluded. The track names in this property can include an asterisk as a wild card character, which matches zero or more characters in a track name. For example, student* includes tracks named student as well as studentTeam.


audio_sources_excludedtype: string[]PII MTL: 30 days

The array of track names to exclude from the composition. The composition includes all audio sources specified in audio_sources except for those specified in audio_sources_excluded. The track names in this property can include an asterisk as a wild card character, which matches zero or more characters in a track name. For example, student* excludes student as well as studentTeam. This parameter can also be empty.


video_layouttype: objectPII MTL: 30 days

An object that describes the video layout of the composition in terms of regions. See Specifying Video Layouts(link takes you to an external page) for more info.


resolutiontype: stringNot PII

The dimensions of the video image in pixels expressed as columns (width) and rows (height). The string's format is {width}x{height}, such as 640x480.


trimtype: booleanNot PII

Whether to remove intervals with no media, as specified in the POST request that created the composition. Compositions with trim enabled are shorter when the Room is created and no Participant joins for a while as well as if all the Participants leave the room and join later, because those gaps will be removed. See Specifying Video Layouts(link takes you to an external page) for more info.


formattype: enum<STRING>Not PII

The container format of the composition's media files as specified in the POST request that created the Composition resource. See POST Parameters(link takes you to an external page) for more information.

Possible values:
mp4webm

bitratetype: integerNot PII

The average bit rate of the composition's media.


sizetype: integer<INT64>Not PII

The size of the composed media file in bytes.


durationtype: integerNot PII

The duration of the composition's media file in seconds.


media_external_locationtype: string<URI>Not PII

The URL of the media file associated with the composition when stored externally. See External S3 Compositions for more details.


status_callbacktype: string<URI>Not PII

The URL called using the status_callback_method to send status information on every composition event.


status_callback_methodtype: enum<HTTP METHOD>Not PII

The HTTP method used to call status_callback. Can be: POST or GET, defaults to POST.

Possible values:
GETPOST

urltype: string<URI>Not PII

The absolute URL of the resource.


linkstype: object<URI MAP>Not PII

The URL of the media file associated with the composition.

Returns the single Composition identified by {CompositionSid}.

Not supported.

Deletes the media file associated with the Composition identified by {CompositionSID} and sets the Composition status as deleted. In case the media file was stored in an external S3 bucket this request has no effect on such file. Once a Composition has been deleted, its metadata (i.e. it REST resource record) is kept during 30 days.


Composition Instance Media Sub-Resource

composition-media-sub-resource page anchor

_10
/v1/Compositions/{CompositionSid}/Media

Retrieves the Composition media file through an HTTP redirection. The format of the provided media file is the one specified in the Format property of the Composition (see table above). By default, the redirection URL is available for 600 seconds, but this can be configured to a value between 1 and 3600 seconds via the Ttl request param. If the composition is not yet available, a 404 is returned.

The HTTP GET request accepts the following parameters

NameDescription
ContentDispositionOptional. Sets the Content-Disposition header of the redirect_to URL. Possible values are attachment or inline. Default value attachment%3B%20filename%3D%22CJxx.xxx%22 (not PII)
TtlOptional. Duration in seconds for which the redirect_to URL can be used to retrieve the media file. The default Ttl is 600 seconds. The minimum supported Ttl value is 1 second and the maximum supported value is 3600 seconds. (not PII)

Remark that ContentDisposition affects the content disposition of the redirection URL. This parameter behaves as specified in RFC-6266(link takes you to an external page):

  • The value attachment indicates that browsers should prompt the user to store the file locally. In this case, the specification of a filename is mandatory. As shown in the table above, we use this as default and set filename to the Composition SID followed by the format extension. For example, for an MP4 Composition it will take the form CJXXXX.mp4 .
  • The value inline indicates default processing based on the media type. Hence, whenever the browser supports the composition format, the file will be played. Otherwise, the file is downloaded. Remark that when inline is used it is strongly recommended to provide a filename for the latter case. When doing so, remember that the ContentDisposition parameter must be URLEncoded. For example:

_10
inline%3B%20filename%3D%22MyFile.mp4%22

Not supported.

Not supported.


Compositions List Resource

compositions-list-resource page anchor

_10
/v1/Compositions/

Creates a new Composition Instance Resource and, when appropriate, launches a media processing task. The result of this task is a composed media file that, by default, is stored in Twilio's cloud.

Developers can create a new Composition as soon as its associated Group Room exists. However, the processing task gets started only when the Room status is Completed. This guarantees that all required recording sources are available.

This HTTP POST always returns a 201 if the request is accepted (i.e. well formed), and a 4xx otherwise depending on the type of error.

Supported POST Parameters

http-post-parameters page anchor

The following table shows all the parameters that can be used when creating a new Composition Instance Resource.

Request body parameters
RoomSidtype: SID<RM>Not PII
Required

The SID of the Group Room with the media tracks to be used as composition sources.


VideoLayouttype: objectPII MTL: 30 days

An object that describes the video layout of the composition in terms of regions. See Specifying Video Layouts(link takes you to an external page) for more info. Please, be aware that either video_layout or audio_sources have to be provided to get a valid creation request


AudioSourcestype: string[]PII MTL: 30 days

An array of track names from the same group room to merge into the new composition. Can include zero or more track names. The new composition includes all audio sources specified in audio_sources except for those specified in audio_sources_excluded. The track names in this parameter can include an asterisk as a wild card character, which will match zero or more characters in a track name. For example, student* includes student as well as studentTeam. Please, be aware that either video_layout or audio_sources have to be provided to get a valid creation request


AudioSourcesExcludedtype: string[]PII MTL: 30 days

An array of track names to exclude. The new composition includes all audio sources specified in audio_sources except for those specified in audio_sources_excluded. The track names in this parameter can include an asterisk as a wild card character, which will match zero or more characters in a track name. For example, student* excludes student as well as studentTeam. This parameter can also be empty.


Resolutiontype: stringNot PII

A string that describes the columns (width) and rows (height) of the generated composed video in pixels. Defaults to 640x480. The string's format is {width}x{height} where:

  • 16 <= {width} <= 1280
  • 16 <= {height} <= 1280
  • {width} * {height} <= 921,600

Typical values are:

  • HD = 1280x720
  • PAL = 1024x576
  • VGA = 640x480
  • CIF = 320x240

Note that the resolution imposes an aspect ratio to the resulting composition. When the original video tracks are constrained by the aspect ratio, they are scaled to fit. See Specifying Video Layouts(link takes you to an external page) for more info.


Formattype: enum<STRING>Not PII

The container format of the composition's media files. Can be: mp4 or webm and the default is webm. If you specify mp4 or webm, you must also specify one or more audio_sources and/or a video_layout element that contains a valid video_sources list, otherwise an error occurs.

Possible values:
mp4webm

StatusCallbacktype: string<URI>Not PII

The URL we should call using the status_callback_method to send status information to your application on every composition event. If not provided, status callback events will not be dispatched.


StatusCallbackMethodtype: enum<HTTP METHOD>Not PII

The HTTP method we should use to call status_callback. Can be: POST or GET and the default is POST.

Possible values:
GETPOST

Trimtype: booleanNot PII

Whether to clip the intervals where there is no active media in the composition. The default is true. Compositions with trim enabled are shorter when the Room is created and no Participant joins for a while as well as if all the Participants leave the room and join later, because those gaps will be removed. See Specifying Video Layouts(link takes you to an external page) for more info.

Specifying Video Layouts

specifying-video-layouts page anchor

Video layouts are organized in terms of regions. A region is a rectangular area where a set of video sources are displayed following the region placement rules. The VideoLayout of a Composition must contain at least one region but it may contain many. Regions are independent meaning that the way placement works in a region does not affect placement in other regions.

A Composition's VideoLayout is specified as a JSON dictionary of regions following this scheme:


_11
VideoLayout = {
_11
"a-region-name": {
_11
region properties
_11
},
_11
_11
"other-region-name": {
_11
other region properties
_11
}
_11
_11
...
_11
}

The region properties define the size and position of the region, the video sources to include in the region and the placement rules. Regions support the following properties (recall that a "Yes" in the column "Default value/mandatory" indicates a mandatory property)

ParameterDefault value / mandatoryDescription
x_pos0X axis value (in pixels) of the region's upper left corner relative to the upper left corner of the Composition viewport. Regions cannot overflow the Composition's area, so x_pos has to be a positive integer less than or equal to the difference between the Composition's width and the width of the region. If the region's width is missing from the request, it defaults to 16 pixels for this validation.
y_pos0Y axis value (in pixels) of the region's upper left corner relative to the upper left corner of the Composition viewport. Regions cannot overflow the composition's area, so y_pos has to be a positive integer less than or equal to the difference between the Composition's height and the height of this region. If the region's height is missing from the request, it defaults to 16 pixels for this validation.
z_pos0Z position controlling the region's visibility in case of overlaps. Regions with higher values are stacked on top of regions with lower value for visibility purposes. z_pos must be in the range [-99, 99].
widthComposition's width - x_posRegion's Width. It must be in the range [16, Composition's width - x_pos]. This constraint guarantees that the region fits into the Composition's viewport.
heightComposition's height - y_posRegion's Height. It must be in the range [16, Composition's height - y_pos]. This constraint guarantees that the region fits into the Composition's viewport.
max_columnsMaximum number of columns of the region's placement grid. By default, the region has as many columns as needed to layout all the specified video sources. max_columns must be in the range [1, 1000].
max_rowsMaximum number of rows of the region's placement grid. By default, the region has as many rows as needed to layout all the specified video sources. max_rows must be in the range [1, 1000].
cells_excludedA list of cell indices on the regions layout grid where no video sources can be assigned. Index of first cell (upper left) is 0. Indices grow from left to right and from top to bottom. These values must be in the range [0, 999999].
reuseshow_oldestDefines how the region's grid cells are reused for placement purposes. Possible values are: -none: used cells are never reused.-show_oldest: a cell can only be reused when the video source it contains ends.-show_newest: a cell can be reused even if the video source it contains has not ended.
video_sourcesYesThe array of video sources that should be placed in this region. All the specified sources must belong to the same Room. It can include: -Zero or more RecordingTrackSid-Zero or more MediaTrackSid-Zero or more ParticipantSid -Zero or more Track names. These can be specified using wildcards (e.g. student*). The wildcard can be applied either at the beginning or at the end of the track name. The use of [*] has semantics "all if any" meaning zero or more (i.e. all) depending on whether the target room had video tracks.
video_sources_excludedAn array of video sources to exclude from this region. This region will attempt to display all sources specified in video_sources except for the ones specified in video_sources_excluded. This parameter may include: -Zero or more RecordingTrackSid-Zero or more MediaTrackSid-Zero or more ParticipantSid -Zero or more Track names. These can be specified using wildcards (e.g. student*).

The use of a VideoLayout not compliant with this specification shall cause the corresponding POST request to be answered with a 4xx code.

Region Positioning and Size

region-positioning-and-size page anchor

The following figure illustrates how regions are positioned:

Region Positioning and Size.

You may find useful to remember these rules:

  • The Composition's width and height are defined through the Resolution parameter.
  • Regions are positioned relative to the Composition top-left corner using x_pos and y_pos .
  • Region dimensions are defined through the width and height properties.
  • Regions must fit inside their Composition. This makes the following mandatory:
    • x_pos + width must not be over the Composition's width .
    • y_pos + height must not be over the Composition's height .
  • In case width or height are not specified, by default the region shall occupy all the available remaining space on the Composition's viewport.
  • When multiple regions overlap, their visibility depend on the z_pos property. Regions with higher z_pos will be visible on top of regions with lower z_pos .

The Region as a Grid

region-as-a-grid page anchor

The placement of video_sources in a region takes place through a grid (i.e. matrix) where every cell is a container where one (and only one) video source may be displayed at a time. Region grids are static meaning that their number of rows and columns do not change during the Composition duration. The specific number of rows and columns depends on the region's max_columns and max_rows properties. There are three different situations:

The Region as a Grid.

Unconstrained Grid

In this case, neither max_columns nor max_rows are specified in the VideoLayout. Twilio computes for you the grid dimensions to guarantee that all the provided video_sources are displayed. Due to this, the cells in the grid will be at least equal to the maximum number of simultaneous video sources in the Composition (video sources are considered to be simultaneous at a given time when their media is active at that time). For this, we try to keep the grid as square as possible making it to grow first in columns and then in rows so that their difference is never over 1. The following table illustrates this:

Maximum simultaneous video sourcesRegion's grid dimensions (rows x columns)
11x1
21x2
32x2
42x2
52x3
62x3
73x3
93x3
103x4
123x4
174x5
204x5

Unconstrained Dimension

In this case, only one of max_columns or max_rows is specified. The grid dimensions are computed following the "Unconstrained Grid" algorithm (i.e. trying to keep the grid as square as possible) but without exceeding the specified maximum constraint. After that, the unconstrained dimension grows in order to guarantee that all the specified video sources are displayed. The following examples illustrate this:

Maximum simultaneous video sourcesmax_rowsmax_columnsRegion's grid dimensions (rows x columns)
111x1
111x1
211x2
212x1
311x3
313x1
422x2
422x2
522x3
523x2
622x3
623x2
722x4
724x2
922x5
925x2
1222x6
1226x2

Constrained Grid In this case, both max_columns and max_rows are specified. The grid dimensions are computed following the above specified algorithms but keeping both dimensions under their limits. Due to this, the maximum number of cells is max_columns * max_rows. If the number of simultaneous video sources exceeds that value, then some video sources shall not be displayed. The following example illustrates the effect.

Maximum simultaneous video sourcesmax_rowsmax_columnsRegion's grid dimensions (rows x columns)
1111x1
1121x1
1221x1
2111x1 (1 source not displayed)
2121x2
2221x2
3111x1 (2 sources not displayed)
3121x2 (1 source not displayed)
3222x2
4111x1 (3 sources not displayed)
4121x2 (2 sources not displayed)
4222x2
5111x1 (4 sources not displayed)
5121x2 (2 sources not displayed)
5222x2 (1 source not displayed)
9171x7 (2 sources not displayed)
9272x5
9373x3

Displaying Video Sources

displaying-video-sources page anchor

Video sources are displayed in region grid cells. Cells size and aspect ratio is controlled by:

  • The region pixel dimensions, as defined by the width and height parameters.
  • The region grid dimensions (i.e. number of rows and columns), as introduced in the section above.

Hence, cells would have approximately (rounding effects not considered):

  • Width equal to the region's width divided by the number of columns.
  • Heigh equal to the region's height divided by the number of rows.

The display of the original video track sources in cells is performed using "object-fit contain" CSS semantics. This means that the original video is rescaled as necessary to fit into the target aspect ratio and that the remaining areas of the cell are filled in black. The following images illustrate how this happens

Displaying Video Sources in Cells.

Video sources are assigned to cells from left-to-right and from top-to-bottom in the region grid. However, this assignment depends on the value of the reuse property. For understanding how reuse works, we need some definitions:

  • We say a cell is fresh at a given time when it has not displayed any video source up to that time.
  • We say a cell is used at a given time when it is displaying a video source at that time.
  • We say a cell is idle at a given time when it has been used previously but its video source media has ended at that time.

Based on this, the possible values for reuse are the following:

  • none : in this case, used cells are never reused again and stay idle until the composition ends. Newer video sources are assigned only to fresh cells following the left-to-right top-to-bottom order. In constrained grids, we may run out of fresh cells. In that case, no further video sources are displayed.
  • show_oldest : in this case idle cells can be reused. Hence, newer video sources are assigned to both idle or fresh cells in left-to-right top-to-bottom order. In constrained grids, when running out of fresh cells, newer video sources will be displayed only as idle cells become available. In such constrained situation, this model gives display priority to older video sources (i.e. to the video sources starting first), which justifies its show_oldest name.
  • show_newest : when this value is specified, video sources are displayed first in idle and fresh cells in the left-to-right top-to-bottom order. In constrained grids it may happen that we run out of both fresh and idle cells. In that case, used cells are reused so that newer video sources are displayed on top of older video sources. When there are several available used cells, the one whose media ends first is selected. As it can be understood, this model gives display priority to newer video sources (i.e. to video sources starting later), which justifies its show_newest name.

The difference between the different reuse modes can be visually appreciated in the following figure:

Graphical examples using Reuse.

As it can be observed, in this figure we assume a Room with 5 video tracks. These are numbered from 0 to 4. The Room timeline shows the time intervals (relative to the Room starting time) when such tracks are in published state. Below it, we show a number of compositions subject to the following constraints:

  • 1x1 Region Composition : in this case, the Composition has a single region where max_rows=1 and max_columns=1 . When reuse=none the first track (i.e. the one identified as 0) takes the single fresh cell of the region for display. In the gaps where this track is unpublished, the cell is never reused and the Composition stays black (in case Trim=false ) or terminates (in case Trim=true ). If reuse=show_newest newer tracks have higher priority than older tracks. Due to this, track 1 is stacked on top of track 0 and displayed while it is active. Later, tracks 2, 3 and 4 take the single region cell as soon as their media is activated. In the case where reuse=show_oldest , the first track occupying the single region cell keeps it until it ends. After that, newer tracks can take it (observe how the end of track 2 allows track 3 to be displayed and how the end of track 3 does the same with track 4.)
  • 1x2 Region Composition : now the Composition has a single region with two cells ( max_rows=1 and max_columns=2 ). Due to this, tracks 0 and 1 can be displayed simultaneously. For tracks 2, 3 and 4 their display is controlled by the reuse model. When reuse=none , tracks 0 and 1 take the two fresh cells. After that, no further tracks can reuse such cells and the Composition stays black (in case Trim=false ) or terminates (in case Trim=true ). If reuse=show_newest 2 and 3 can reuse the idle cells, but when 4 arrives it reuses the used cell with track ending first (in this case 2). When reuse=show_oldest 2 and 3 have priority and hence 4 needs to wait until an idle cell is made available, which takes place when 2 ends.
  • Unconstrained Region Composition : in this case, the Composition has a single cell where neither max_rows nor max_columns have been specified. Hence, the region grid dimensions are automatically calculated to fit all the specified video sources. When reuse=none , we need 5 cells given that video sources can only occupy fresh cells. Due to this, the system uses a 2x3 grid. When reuse=show_newest or reuse=show_oldest the required grid needs to have only 3 cells given that the maximum number of simultaneous tracks is 3 (i.e. what happens during the interval in which 2, 3 and 4 are published). Hence, the system computes a 2x2 grid. Observe that when using unconstrained grids, both show_newest and show_oldest generate the same video placement for the region. This is due to the fact that in an unconstrained grid it is guaranteed that the number of video sources never exceeds the number of cells in the grid. Hence, no used cells need ever to be reused.

The Trim Composition parameter controls what happens to the composition when there is no active media. That is, during the gaps in which neither audio tracks nor video tracks are published. We define two types of such gaps:

  • Initial gap: Compositions have an initial gap when at the beginning of the Room there is no active media. The initial gap ends when the first recording included in the composition starts. The initial gap is always trimmed in Compositions.
  • Later gap: for any other gap not being an initial gap.

Later gaps are trimmed depending on the value of the trim parameter.

  • trim=false : The Composition keeps all the later gaps as black video with silent audio. Hence, these idle intervals with no media may appear at the end or in the middle of the Composition.
  • trim=true (default) : the Composition clips all gaps where there is no media published. Note that when an audio track is active in the composition during an interval it shall not be clipped even if there are no active video tracks on it.

The following figure illustrates how trimmed Compositions behave in the scenarios introduced in the section above.

Composing different layouts in a room (trim=true).

Retrieves the list Composition Instance Records belonging to the specified AccountSid with paging data.

Supported GET Parameters
get-list-query-parameters page anchor

The following GET query string parameters allow you to limit the list returned. Note, parameters are case-sensitive.

URI parameters
Statustype: enum<STRING>Not PII
Query Parameter

Read only Composition resources with this status. Can be: enqueued, processing, completed, deleted, or failed.

Possible values:
enqueuedprocessingcompleteddeletedfailed

DateCreatedAftertype: string<DATE TIME>Not PII
Query Parameter

Read only Composition resources created on or after this ISO 8601(link takes you to an external page) date-time with time zone.


DateCreatedBeforetype: string<DATE TIME>Not PII
Query Parameter

Read only Composition resources created before this ISO 8601 date-time with time zone.


RoomSidtype: SID<RM>Not PII
Query Parameter

Read only Composition resources with this Room SID.


PageSizetype: integerNot PII
Query Parameter

How many resources to return in each list page. The default is 50, and the maximum is 1000.


Pagetype: integerNot PII
Query Parameter

The page index. This value is simply for client state.


PageTokentype: stringNot PII
Query Parameter

The page token. This is provided by the API.

Note: deleted Compositions are not returned by default. For retrieving the deleted Compositions list you must explicitly specify Status=deleted.


Creating Transcoding Compositions

example-transcode page anchor

Example: Transcode a Video Recording

example-transcode-video-recording page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where a video Track with MediaTrackSid=MTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX is published and recorded with RecordingTrackSid=RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. We want then to generate a Composition containing such video Track but transcoded to the H.264/mp4 format. Considering that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )
  • You want to use the default resolution (VGA = 640x480 )

You can create the desired Composition using the following:

Transcode a Video Recording

transcode-a-video-recording page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_21
// Download the helper library from https://www.twilio.com/docs/node/install
_21
// Find your Account SID and Auth Token at twilio.com/console
_21
// and set the environment variables. See http://twil.io/secure
_21
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_21
const authToken = process.env.TWILIO_AUTH_TOKEN;
_21
const client = require('twilio')(accountSid, authToken);
_21
_21
client.video.v1.compositions
_21
.create({
_21
videoLayout: {
_21
transcode: {
_21
video_sources: [
_21
'RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_21
]
_21
}
_21
},
_21
statusCallback: 'https://www.example.com/callbacks',
_21
format: 'mp4',
_21
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_21
})
_21
.then(composition => console.log(composition.sid));

Output

_36
{
_36
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_36
"status": "processing",
_36
"date_created": "2015-07-30T20:00:00Z",
_36
"date_completed": null,
_36
"date_deleted": null,
_36
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_36
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_36
"audio_sources": [
_36
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_36
"user*"
_36
],
_36
"audio_sources_excluded": [
_36
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_36
],
_36
"video_layout": {
_36
"transcode": {
_36
"video_sources": [
_36
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_36
]
_36
}
_36
},
_36
"trim": true,
_36
"format": "mp4",
_36
"resolution": "1920x1080",
_36
"bitrate": 0,
_36
"size": 0,
_36
"duration": 0,
_36
"media_external_location": null,
_36
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_36
"status_callback": "https://www.example.com/callbacks",
_36
"status_callback_method": "POST",
_36
"links": {
_36
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_36
}
_36
}

Example: Transcode an Audio Recording

example-transcode-audio-recording page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where an audio Track with MediaTrackSid=MTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX is publishes and recorded with RecordingTrackSid=RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. We want then to generate a Composition containing such audio Track but transcoded to the AAC/mp4 format. Considering that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )

You can create the desired Composition using the following:

Transcode an Audio Recording

transcode-an-audio-recording page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_15
// Download the helper library from https://www.twilio.com/docs/node/install
_15
// Find your Account SID and Auth Token at twilio.com/console
_15
// and set the environment variables. See http://twil.io/secure
_15
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_15
const authToken = process.env.TWILIO_AUTH_TOKEN;
_15
const client = require('twilio')(accountSid, authToken);
_15
_15
client.video.v1.compositions
_15
.create({
_15
audioSources: ['RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'],
_15
statusCallback: 'https://www.example.com/callbacks',
_15
format: 'mp4',
_15
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_15
})
_15
.then(composition => console.log(composition.sid));

Output

_50
{
_50
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_50
"status": "processing",
_50
"date_created": "2015-07-30T20:00:00Z",
_50
"date_completed": null,
_50
"date_deleted": null,
_50
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_50
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_50
"audio_sources": [
_50
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_50
],
_50
"audio_sources_excluded": [
_50
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_50
],
_50
"video_layout": {
_50
"custom": {
_50
"video_sources": [
_50
"user*"
_50
],
_50
"video_sources_excluded": [
_50
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_50
],
_50
"reuse": "show_oldest",
_50
"x_pos": 100,
_50
"y_pos": 600,
_50
"z_pos": 10,
_50
"width": 800,
_50
"height": 0,
_50
"max_columns": 0,
_50
"max_rows": 0,
_50
"cells_excluded": [
_50
2,
_50
3
_50
]
_50
}
_50
},
_50
"trim": true,
_50
"format": "mp4",
_50
"resolution": "1920x1080",
_50
"bitrate": 0,
_50
"size": 0,
_50
"duration": 0,
_50
"media_external_location": null,
_50
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_50
"status_callback": "https://www.example.com/callbacks",
_50
"status_callback_method": "POST",
_50
"links": {
_50
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_50
}
_50
}

Remark that, in spite of this being an only-audio composition, it shows default video settings in the corresponding response parameters.

Creating Compositions with Simple Layouts

example-compose page anchor

Example: Compose one Participant's Media

example-compose-participant page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where a Participant with ParticipantSid=PAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX publishes both audio and video tracks to the Room. In this Room there may be other Participants publishing audio and video without affecting this example's result.

We want to generate a Composition showing the Participant's video Track and having as audio the one of that Participant. Considering that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )
  • You want to use mp4 as target format
  • You want to use the default resolution (VGA = 640x480 )

You can create the desired Composition using the following:

Compose one Participant's Media

compose-one-participants-media page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_22
// Download the helper library from https://www.twilio.com/docs/node/install
_22
// Find your Account SID and Auth Token at twilio.com/console
_22
// and set the environment variables. See http://twil.io/secure
_22
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_22
const authToken = process.env.TWILIO_AUTH_TOKEN;
_22
const client = require('twilio')(accountSid, authToken);
_22
_22
client.video.v1.compositions
_22
.create({
_22
audioSources: ['PAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'],
_22
videoLayout: {
_22
single: {
_22
video_sources: [
_22
'PAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_22
]
_22
}
_22
},
_22
statusCallback: 'https://www.example.com/callbacks',
_22
format: 'mp4',
_22
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_22
})
_22
.then(composition => console.log(composition.sid));

Output

_35
{
_35
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"status": "processing",
_35
"date_created": "2015-07-30T20:00:00Z",
_35
"date_completed": null,
_35
"date_deleted": null,
_35
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"audio_sources": [
_35
"PAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_35
],
_35
"audio_sources_excluded": [
_35
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_35
],
_35
"video_layout": {
_35
"single": {
_35
"video_sources": [
_35
"PAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_35
]
_35
}
_35
},
_35
"trim": true,
_35
"format": "mp4",
_35
"resolution": "1920x1080",
_35
"bitrate": 0,
_35
"size": 0,
_35
"duration": 0,
_35
"media_external_location": null,
_35
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"status_callback": "https://www.example.com/callbacks",
_35
"status_callback_method": "POST",
_35
"links": {
_35
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_35
}
_35
}

Example: Compose One Participant's Video with all Room Participants' Audios

example-compose-participant-video-with-all-audios page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where a Participant with ParticipantSid=PAXXXX publishes both audio and video Tracks. In that Room others participant publish also their audio and video Tracks. We want generate a Composition showing PAXXXX video but having as audio the complete set of Room audio Tracks mixed. Considering that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )
  • You want to use mp4 as target format
  • You want to use the default resolution (VGA = 640x480 )

You can create the desired Composition using the following:

Compose One Participant's Video with all Room Participants' Audios

compose-one-participants-video-with-all-room-participants-audios page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_22
// Download the helper library from https://www.twilio.com/docs/node/install
_22
// Find your Account SID and Auth Token at twilio.com/console
_22
// and set the environment variables. See http://twil.io/secure
_22
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_22
const authToken = process.env.TWILIO_AUTH_TOKEN;
_22
const client = require('twilio')(accountSid, authToken);
_22
_22
client.video.v1.compositions
_22
.create({
_22
audioSources: ['*'],
_22
videoLayout: {
_22
single: {
_22
video_sources: [
_22
'PAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_22
]
_22
}
_22
},
_22
statusCallback: 'https://www.example.com/callbacks',
_22
format: 'mp4',
_22
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_22
})
_22
.then(composition => console.log(composition.sid));

Output

_35
{
_35
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"status": "processing",
_35
"date_created": "2015-07-30T20:00:00Z",
_35
"date_completed": null,
_35
"date_deleted": null,
_35
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"audio_sources": [
_35
"*"
_35
],
_35
"audio_sources_excluded": [
_35
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_35
],
_35
"video_layout": {
_35
"single": {
_35
"video_sources": [
_35
"PAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_35
]
_35
}
_35
},
_35
"trim": true,
_35
"format": "mp4",
_35
"resolution": "1920x1080",
_35
"bitrate": 0,
_35
"size": 0,
_35
"duration": 0,
_35
"media_external_location": null,
_35
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"status_callback": "https://www.example.com/callbacks",
_35
"status_callback_method": "POST",
_35
"links": {
_35
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_35
}
_35
}

Example: Compose the Complete Room in a Grid

example-compose-room page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where multiple Participants publish both audio and video Tracks. We want generate a Composition showing all the room videos in a grid, as shown in the figure below, and with all audio tracks mixed.

Grid Room Composition Layout.

Considering that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )
  • You want to use mp4 as target format
  • You want to use VGA resolution ( 640x480 )
  • You want an unconstrained grid composition with the default cell reuse strategy ( show_oldest ).

You can create the desired Composition using the following:

Compose the complete Room in a grid (with all Participants' audio and video)

compose-the-complete-room-in-a-grid-with-all-participants-audio-and-video page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_22
// Download the helper library from https://www.twilio.com/docs/node/install
_22
// Find your Account SID and Auth Token at twilio.com/console
_22
// and set the environment variables. See http://twil.io/secure
_22
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_22
const authToken = process.env.TWILIO_AUTH_TOKEN;
_22
const client = require('twilio')(accountSid, authToken);
_22
_22
client.video.v1.compositions
_22
.create({
_22
audioSources: ['*'],
_22
videoLayout: {
_22
grid: {
_22
video_sources: [
_22
'*'
_22
]
_22
}
_22
},
_22
statusCallback: 'https://www.example.com/callbacks',
_22
format: 'mp4',
_22
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_22
})
_22
.then(composition => console.log(composition.sid));

Output

_35
{
_35
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"status": "processing",
_35
"date_created": "2015-07-30T20:00:00Z",
_35
"date_completed": null,
_35
"date_deleted": null,
_35
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"audio_sources": [
_35
"*"
_35
],
_35
"audio_sources_excluded": [
_35
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_35
],
_35
"video_layout": {
_35
"grid": {
_35
"video_sources": [
_35
"*"
_35
]
_35
}
_35
},
_35
"trim": true,
_35
"format": "mp4",
_35
"resolution": "1920x1080",
_35
"bitrate": 0,
_35
"size": 0,
_35
"duration": 0,
_35
"media_external_location": null,
_35
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_35
"status_callback": "https://www.example.com/callbacks",
_35
"status_callback_method": "POST",
_35
"links": {
_35
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_35
}
_35
}

Example: Compose a Specific Set of Track Recordings in a Grid

example-compose-array page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where different Participants publish their audio and video Tracks. Imagine that we have special interest in some of these tracks that we identify in the following way:

  • RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX : the RecordingTrackSid of of video Track.
  • MTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX : the MediaTrackSid of a video Track.
  • teacher-webcast : the Track name of a video track.

We want to generate a composition showing the three video Tracks in a single row and with no audio, as shown in the figure below.

Three Tracks Composition Layout.

Considering that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )
  • You want to use mp4 as target format
  • You want to use the default resolution (VGA = 640x480 )

You can create the desired Composition using the following:

Compose a set of Tracks in a grid

compose-a-set-of-tracks-in-a-grid page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_24
// Download the helper library from https://www.twilio.com/docs/node/install
_24
// Find your Account SID and Auth Token at twilio.com/console
_24
// and set the environment variables. See http://twil.io/secure
_24
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_24
const authToken = process.env.TWILIO_AUTH_TOKEN;
_24
const client = require('twilio')(accountSid, authToken);
_24
_24
client.video.v1.compositions
_24
.create({
_24
videoLayout: {
_24
grid: {
_24
max_rows: 1,
_24
video_sources: [
_24
'RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
_24
'MTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
_24
'teacher-webcast'
_24
]
_24
}
_24
},
_24
statusCallback: 'https://www.example.com/callbacks',
_24
format: 'mp4',
_24
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_24
})
_24
.then(composition => console.log(composition.sid));

Output

_39
{
_39
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"status": "processing",
_39
"date_created": "2015-07-30T20:00:00Z",
_39
"date_completed": null,
_39
"date_deleted": null,
_39
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"audio_sources": [
_39
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"user*"
_39
],
_39
"audio_sources_excluded": [
_39
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_39
],
_39
"video_layout": {
_39
"grid": {
_39
"max_rows": 1,
_39
"video_sources": [
_39
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"MTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"teacher-webcast"
_39
]
_39
}
_39
},
_39
"trim": true,
_39
"format": "mp4",
_39
"resolution": "1920x1080",
_39
"bitrate": 0,
_39
"size": 0,
_39
"duration": 0,
_39
"media_external_location": null,
_39
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"status_callback": "https://www.example.com/callbacks",
_39
"status_callback_method": "POST",
_39
"links": {
_39
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_39
}
_39
}

Compose a Specific Set of Track Recordings as a Sequence

example-compose-sequence page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where a teacher presents lessons to their students. These lessons consist on talks and screensharing presentations that occur in sequence. These may overlap or have idle intervals where no media is published. The Track names of the published media comply with the following pattern:

  • For video: teacher-video-sess-1 , teacher-video-sess-2 , etc.
  • For audio: teacher-audio-sess-1 , teacher-audio-sess-2 , etc.

In this context, we want to create a Compositions showing only one video source at a time. That one must match with the video track published later by the teacher at any time. We want the teacher's audio to be included in the Composition. We don't want the Composition to contain the idle intervals where the teacher is not publishing media. In this context, considering that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )
  • You want to use mp4 as target format
  • You want to use the default resolution (VGA = 640x480 )

You can create the desired Composition using the following:

Compose a set of Tracks as a sequence

compose-a-set-of-tracks-as-a-sequence page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_25
// Download the helper library from https://www.twilio.com/docs/node/install
_25
// Find your Account SID and Auth Token at twilio.com/console
_25
// and set the environment variables. See http://twil.io/secure
_25
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_25
const authToken = process.env.TWILIO_AUTH_TOKEN;
_25
const client = require('twilio')(accountSid, authToken);
_25
_25
client.video.v1.compositions
_25
.create({
_25
audioSources: ['teacher-audio-sess-*'],
_25
videoLayout: {
_25
sequence: {
_25
max_rows: 1,
_25
max_columns: 1,
_25
reuse: 'show_newest',
_25
video_sources: [
_25
'teacher-video-sess-*'
_25
]
_25
}
_25
},
_25
statusCallback: 'https://www.example.com/callbacks',
_25
format: 'mp4',
_25
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_25
})
_25
.then(composition => console.log(composition.sid));

Output

_38
{
_38
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_38
"status": "processing",
_38
"date_created": "2015-07-30T20:00:00Z",
_38
"date_completed": null,
_38
"date_deleted": null,
_38
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_38
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_38
"audio_sources": [
_38
"teacher-audio-sess-*"
_38
],
_38
"audio_sources_excluded": [
_38
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_38
],
_38
"video_layout": {
_38
"sequence": {
_38
"max_rows": 1,
_38
"max_columns": 1,
_38
"reuse": "show_newest",
_38
"video_sources": [
_38
"teacher-video-sess-*"
_38
]
_38
}
_38
},
_38
"trim": true,
_38
"format": "mp4",
_38
"resolution": "1920x1080",
_38
"bitrate": 0,
_38
"size": 0,
_38
"duration": 0,
_38
"media_external_location": null,
_38
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_38
"status_callback": "https://www.example.com/callbacks",
_38
"status_callback_method": "POST",
_38
"links": {
_38
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_38
}
_38
}

Creating Compositions with Complex Layouts

example-complex page anchor

Example: Creating a PiP (Picture-in-Picture) Composition

example-pip page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where an expert presents a topic with two audio tracks:

  • One track is from his microphone and has the MediaTrackSid= MTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  • One acting as a background soundtrack with Track name = soundtrack

He also has two video tracks:

  • A webcam video track with MediaTrackSid= MTYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
  • A screensharing video Track with Track name screen-presentation .

In this context, we want to create a PiP Composition including the above mentioned audio Tracks and showing:

  • The video track screen-presentation occupying the complete Composition background.
  • The video track MTYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY in a small box located at the top-left corner of the Composition overlayed on top of screen-presentation as shown on the figure below.
PiP Composition Layout.

Assuming that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )
  • You want to use mp4 as target format
  • You want to use HD resolution ( 1280x720 )

You can create the desired Composition using the following:

Creating a Picture-in-Picture Composition

creating-a-picture-in-picture-composition page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_32
// Download the helper library from https://www.twilio.com/docs/node/install
_32
// Find your Account SID and Auth Token at twilio.com/console
_32
// and set the environment variables. See http://twil.io/secure
_32
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_32
const authToken = process.env.TWILIO_AUTH_TOKEN;
_32
const client = require('twilio')(accountSid, authToken);
_32
_32
client.video.v1.compositions
_32
.create({
_32
audioSources: ['MTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'soundtrack'],
_32
videoLayout: {
_32
main: {
_32
z_pos: 1,
_32
video_sources: 'screen-presentation'
_32
},
_32
pip: {
_32
z_pos: 2,
_32
x_pos: 1000,
_32
y_pos: 30,
_32
width: 240,
_32
height: 180,
_32
video_sources: [
_32
'MTYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
_32
]
_32
}
_32
},
_32
statusCallback: 'https://www.example.com/callbacks',
_32
resolution: '1280x720',
_32
format: 'mp4',
_32
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_32
})
_32
.then(composition => console.log(composition.sid));

Output

_45
{
_45
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"status": "processing",
_45
"date_created": "2015-07-30T20:00:00Z",
_45
"date_completed": null,
_45
"date_deleted": null,
_45
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"audio_sources": [
_45
"MTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"soundtrack"
_45
],
_45
"audio_sources_excluded": [
_45
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_45
],
_45
"video_layout": {
_45
"main": {
_45
"z_pos": 1,
_45
"video_sources": "screen-presentation"
_45
},
_45
"pip": {
_45
"z_pos": 2,
_45
"x_pos": 1000,
_45
"y_pos": 30,
_45
"width": 240,
_45
"height": 180,
_45
"video_sources": [
_45
"MTYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"
_45
]
_45
}
_45
},
_45
"trim": true,
_45
"format": "mp4",
_45
"resolution": "1280x720",
_45
"bitrate": 0,
_45
"size": 0,
_45
"duration": 0,
_45
"media_external_location": null,
_45
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_45
"status_callback": "https://www.example.com/callbacks",
_45
"status_callback_method": "POST",
_45
"links": {
_45
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_45
}
_45
}

Example: Composing a Room with Natural Layouts

example-presentation-multiple-layouts page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where a lecture is taking place. The Participants are the following:

  • A teacher publishes the following Tracks:
    • A webcam video Track with name teacher-webcam-video .
    • An screensharing video Track with name teacher-screen-video .
    • An audio Track with name teacher-audio .
  • A variable number of students publishing each the following (i varies from student to student):
    • A webcam video track with name student-i-video
    • An audio Track with name student-i-audio

In this context, imagine that we want to create the following Composition:

  • Track teacher-screen-video must be shown as Composition background occupying its complete viewport. A track with such disposition is sometimes called "main".
  • The rest of video tracks should be shown in a row at the bottom of the Composition, as shown in the figure below.
  • All the audio tracks of the Room should be mixed for the Composition.
Focus + Row Composition Layout.

Assuming that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )
  • You want to use mp4 as target format
  • You want to use HD resolution ( 1280x720 )

You can create the desired Composition using the following:

Compose a Room with main+row layout

compose-a-room-with-mainrow-layout page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_38
// Download the helper library from https://www.twilio.com/docs/node/install
_38
// Find your Account SID and Auth Token at twilio.com/console
_38
// and set the environment variables. See http://twil.io/secure
_38
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_38
const authToken = process.env.TWILIO_AUTH_TOKEN;
_38
const client = require('twilio')(accountSid, authToken);
_38
_38
client.video.v1.compositions
_38
.create({
_38
audioSources: ['*'],
_38
videoLayout: {
_38
main: {
_38
z_pos: 1,
_38
video_sources: [
_38
'teacher-screen-video'
_38
]
_38
},
_38
row: {
_38
z_pos: 2,
_38
x_pos: 10,
_38
y_pos: 530,
_38
width: 1260,
_38
height: 160,
_38
max_rows: 1,
_38
video_sources: [
_38
'*'
_38
],
_38
video_sources_excluded: [
_38
'teacher-screen-video'
_38
]
_38
}
_38
},
_38
statusCallback: 'https://www.example.com/callbacks',
_38
resolution: '1280x720',
_38
format: 'mp4',
_38
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_38
})
_38
.then(composition => console.log(composition.sid));

Output

_50
{
_50
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_50
"status": "processing",
_50
"date_created": "2015-07-30T20:00:00Z",
_50
"date_completed": null,
_50
"date_deleted": null,
_50
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_50
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_50
"audio_sources": [
_50
"*"
_50
],
_50
"audio_sources_excluded": [
_50
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_50
],
_50
"video_layout": {
_50
"main": {
_50
"z_pos": 1,
_50
"video_sources": [
_50
"teacher-screen-video"
_50
]
_50
},
_50
"row": {
_50
"z_pos": 2,
_50
"x_pos": 10,
_50
"y_pos": 530,
_50
"width": 1260,
_50
"height": 160,
_50
"max_rows": 1,
_50
"video_sources": [
_50
"*"
_50
],
_50
"video_sources_excluded": [
_50
"teacher-screen-video"
_50
]
_50
}
_50
},
_50
"trim": true,
_50
"format": "mp4",
_50
"resolution": "1280x720",
_50
"bitrate": 0,
_50
"size": 0,
_50
"duration": 0,
_50
"media_external_location": null,
_50
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_50
"status_callback": "https://www.example.com/callbacks",
_50
"status_callback_method": "POST",
_50
"links": {
_50
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_50
}
_50
}

Imagine now that you want the Composition to have a slightly different layout:

  • Track teacher-screen-video must be shown as Composition background occupying its complete viewport.
  • Track teacher-webcam-video must be shown as a small window in the top-right corner of the Composition.
  • The rest of video tracks should be shown in a column on the left with no more than 5 rows as shown on the figure below.
  • All the audio tracks of the Room should be mixed for the Composition.
PiP + Column Composition Layout.

In this case, the required code would be the following:

Compose a Room using a column+PiP layout

compose-a-room-using-a-columnpip-layout page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_47
// Download the helper library from https://www.twilio.com/docs/node/install
_47
// Find your Account SID and Auth Token at twilio.com/console
_47
// and set the environment variables. See http://twil.io/secure
_47
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_47
const authToken = process.env.TWILIO_AUTH_TOKEN;
_47
const client = require('twilio')(accountSid, authToken);
_47
_47
client.video.v1.compositions
_47
.create({
_47
audioSources: ['*'],
_47
videoLayout: {
_47
main: {
_47
z_pos: 1,
_47
video_sources: [
_47
'teacher-screen-video'
_47
]
_47
},
_47
pip: {
_47
z_pos: 2,
_47
x_pos: 1000,
_47
y_pos: 30,
_47
width: 240,
_47
height: 180,
_47
video_sources: [
_47
'teacher-webcam-video'
_47
]
_47
},
_47
column: {
_47
z_pos: 3,
_47
x_pos: 40,
_47
y_pos: 10,
_47
width: 190,
_47
height: 700,
_47
max_rows: 5,
_47
max_columns: 1,
_47
reuse: 'show_newest',
_47
video_sources: [
_47
'student-*'
_47
]
_47
}
_47
},
_47
statusCallback: 'https://www.example.com/callbacks',
_47
resolution: '1280x720',
_47
format: 'mp4',
_47
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_47
})
_47
.then(composition => console.log(composition.sid));

Output

_59
{
_59
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_59
"status": "processing",
_59
"date_created": "2015-07-30T20:00:00Z",
_59
"date_completed": null,
_59
"date_deleted": null,
_59
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_59
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_59
"audio_sources": [
_59
"*"
_59
],
_59
"audio_sources_excluded": [
_59
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_59
],
_59
"video_layout": {
_59
"main": {
_59
"z_pos": 1,
_59
"video_sources": [
_59
"teacher-screen-video"
_59
]
_59
},
_59
"pip": {
_59
"z_pos": 2,
_59
"x_pos": 1000,
_59
"y_pos": 30,
_59
"width": 240,
_59
"height": 180,
_59
"video_sources": [
_59
"teacher-webcam-video"
_59
]
_59
},
_59
"column": {
_59
"z_pos": 3,
_59
"x_pos": 40,
_59
"y_pos": 10,
_59
"width": 190,
_59
"height": 700,
_59
"max_rows": 5,
_59
"max_columns": 1,
_59
"reuse": "show_newest",
_59
"video_sources": [
_59
"student-*"
_59
]
_59
}
_59
},
_59
"trim": true,
_59
"format": "mp4",
_59
"resolution": "1280x720",
_59
"bitrate": 0,
_59
"size": 0,
_59
"duration": 0,
_59
"media_external_location": null,
_59
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_59
"status_callback": "https://www.example.com/callbacks",
_59
"status_callback_method": "POST",
_59
"links": {
_59
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_59
}
_59
}

Example: Composing a Room with Mosaic Layout

example-mosaic-layout page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where an interview is taking place through the following tracks:

  • The interviewed publishes the following:
    • A video Track named interviewed-video .
    • An audio Track named interviewed-audio .
  • A number of interviewers publishing each:
    • A video Track named interviewer-i-video .
    • An audio Track named interviewed-i-audio .
  • An advisor, who can only be listened by the interviewed, publishes:
    • An audio Track named advisor-audio .

We want to create the following Composition:

  • Track interviewed-video must be shown centered in the middle of the composition.
  • The rest of video tracks should be shown around that one, as the figure indicates.
  • All the audio tracks of the Room should be mixed for the Composition except for advisor-audio that should not be included.
Mosaic Composition Layout.

Assuming that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )
  • You want to use mp4 as target format
  • You want to use HD resolution ( 1280x720 )

You can create the desired Composition using the following:

Compose a Room with mosaic layout

compose-a-room-with-mosaic-layout page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_45
// Download the helper library from https://www.twilio.com/docs/node/install
_45
// Find your Account SID and Auth Token at twilio.com/console
_45
// and set the environment variables. See http://twil.io/secure
_45
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_45
const authToken = process.env.TWILIO_AUTH_TOKEN;
_45
const client = require('twilio')(accountSid, authToken);
_45
_45
client.video.v1.compositions
_45
.create({
_45
audioSources: ['*'],
_45
audioSourcesExcluded: ['advisor-audio'],
_45
videoLayout: {
_45
interviewed: {
_45
z_pos: 2,
_45
x_pos: 400,
_45
y_pos: 180,
_45
width: 480,
_45
height: 360,
_45
video_sources: [
_45
'interviewed-video'
_45
]
_45
},
_45
interviewers: {
_45
z_pos: 1,
_45
x_pos: 10,
_45
y_pos: 0,
_45
width: 1260,
_45
height: 720,
_45
max_rows: 3,
_45
max_columns: 3,
_45
cells_excluded: [
_45
'4'
_45
],
_45
reuse: 'show_newest',
_45
video_sources: [
_45
'interviewer-*'
_45
]
_45
}
_45
},
_45
statusCallback: 'https://www.example.com/callbacks',
_45
resolution: '1280x720',
_45
format: 'mp4',
_45
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_45
})
_45
.then(composition => console.log(composition.sid));

Output

_56
{
_56
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_56
"status": "processing",
_56
"date_created": "2015-07-30T20:00:00Z",
_56
"date_completed": null,
_56
"date_deleted": null,
_56
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_56
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_56
"audio_sources": [
_56
"*"
_56
],
_56
"audio_sources_excluded": [
_56
"advisor-audio"
_56
],
_56
"video_layout": {
_56
"interviewed": {
_56
"z_pos": 2,
_56
"x_pos": 400,
_56
"y_pos": 180,
_56
"width": 480,
_56
"height": 360,
_56
"video_sources": [
_56
"interviewed-video"
_56
]
_56
},
_56
"interviewers": {
_56
"z_pos": 1,
_56
"x_pos": 10,
_56
"y_pos": 0,
_56
"width": 1260,
_56
"height": 720,
_56
"max_rows": 3,
_56
"max_columns": 3,
_56
"cells_excluded": [
_56
"4"
_56
],
_56
"reuse": "show_newest",
_56
"video_sources": [
_56
"interviewer-*"
_56
]
_56
}
_56
},
_56
"trim": true,
_56
"format": "mp4",
_56
"resolution": "1280x720",
_56
"bitrate": 0,
_56
"size": 0,
_56
"duration": 0,
_56
"media_external_location": null,
_56
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_56
"status_callback": "https://www.example.com/callbacks",
_56
"status_callback_method": "POST",
_56
"links": {
_56
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_56
}
_56
}

Example: Creating a Chess-Table Layout Composition

example-chess-table-layout page anchor

In this example we assume a Room with RoomSid=RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX where a number of participants publish their audio and video tracks. For fun, we want to create the layout depicted on the following figure.

Chess-Table Composition Layout.

Assuming that:

  • Your application credentials are ( SKXXXX:your_api_key_secret )
  • You want to use mp4 as target format
  • You want to use HD resolution ( 1280x720 )

You can create the desired Composition using the following:

Compose a Room with a chess-table like layout

compose-a-room-with-a-chess-table-like-layout page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_36
// Download the helper library from https://www.twilio.com/docs/node/install
_36
// Find your Account SID and Auth Token at twilio.com/console
_36
// and set the environment variables. See http://twil.io/secure
_36
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_36
const authToken = process.env.TWILIO_AUTH_TOKEN;
_36
const client = require('twilio')(accountSid, authToken);
_36
_36
client.video.v1.compositions
_36
.create({
_36
audioSources: ['*'],
_36
videoLayout: {
_36
chess_table: {
_36
x_pos: 10,
_36
y_pos: 0,
_36
width: 1260,
_36
height: 720,
_36
max_rows: 3,
_36
max_columns: 3,
_36
reuse: 'show_newest',
_36
cells_excluded: [
_36
'1',
_36
'3',
_36
'5',
_36
'7'
_36
],
_36
video_sources: [
_36
'*'
_36
]
_36
}
_36
},
_36
statusCallback: 'https://www.example.com/callbacks',
_36
resolution: '1280x720',
_36
format: 'mp4',
_36
roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
_36
})
_36
.then(composition => console.log(composition.sid));

Output

_48
{
_48
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_48
"status": "processing",
_48
"date_created": "2015-07-30T20:00:00Z",
_48
"date_completed": null,
_48
"date_deleted": null,
_48
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_48
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_48
"audio_sources": [
_48
"*"
_48
],
_48
"audio_sources_excluded": [
_48
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_48
],
_48
"video_layout": {
_48
"chess_table": {
_48
"x_pos": 10,
_48
"y_pos": 0,
_48
"width": 1260,
_48
"height": 720,
_48
"max_rows": 3,
_48
"max_columns": 3,
_48
"reuse": "show_newest",
_48
"cells_excluded": [
_48
"1",
_48
"3",
_48
"5",
_48
"7"
_48
],
_48
"video_sources": [
_48
"*"
_48
]
_48
}
_48
},
_48
"trim": true,
_48
"format": "mp4",
_48
"resolution": "1280x720",
_48
"bitrate": 0,
_48
"size": 0,
_48
"duration": 0,
_48
"media_external_location": null,
_48
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_48
"status_callback": "https://www.example.com/callbacks",
_48
"status_callback_method": "POST",
_48
"links": {
_48
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_48
}
_48
}

Getting compositions

example-get page anchor

Example: Get a Composition Instance Resource

example-get-composition page anchor

For executing this example you need:

  • Your application credentials ( SKXXXX:your_api_key_secret )
  • The CompositionSid ( CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX )

Get a Composition Instance Resource

get-a-composition-instance-resource page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.video.v1.compositions('CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_10
.fetch()
_10
.then(composition => console.log(composition.status));

Output

_63
{
_63
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_63
"status": "completed",
_63
"date_created": "2015-07-30T20:00:00Z",
_63
"date_completed": "2015-07-30T20:01:33Z",
_63
"date_deleted": null,
_63
"sid": "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_63
"room_sid": "RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_63
"audio_sources": [
_63
"PAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_63
"user*"
_63
],
_63
"audio_sources_excluded": [
_63
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_63
],
_63
"video_layout": {
_63
"grid": {
_63
"video_sources": [
_63
"*"
_63
],
_63
"video_sources_excluded": [
_63
"MTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_63
],
_63
"reuse": "show_oldest",
_63
"x_pos": 100,
_63
"y_pos": 600,
_63
"z_pos": 10,
_63
"width": 0,
_63
"height": 0,
_63
"max_columns": 0,
_63
"max_rows": 0,
_63
"cells_excluded": []
_63
},
_63
"pip": {
_63
"video_sources": [
_63
"RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
_63
],
_63
"video_sources_excluded": [],
_63
"reuse": "none",
_63
"x_pos": 100,
_63
"y_pos": 600,
_63
"z_pos": 10,
_63
"width": 0,
_63
"height": 0,
_63
"max_columns": 0,
_63
"max_rows": 0,
_63
"cells_excluded": []
_63
}
_63
},
_63
"resolution": "1280x720",
_63
"format": "webm",
_63
"bitrate": 64,
_63
"size": 4,
_63
"duration": 6,
_63
"trim": true,
_63
"media_external_location": null,
_63
"url": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_63
"status_callback": "https://mycallbackurl.com",
_63
"status_callback_method": "POST",
_63
"links": {
_63
"media": "https://video.twilio.com/v1/Compositions/CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media"
_63
}
_63
}

Example: List a Page of Completed Compositions

example-get-completed-compositions page anchor

For executing this example you need:

  • Your application credentials ( SKXXXX:your_api_key_secret )

List all completed Compositions

list-all-completed-compositions page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.video.v1.compositions
_10
.list({status: 'completed', limit: 20})
_10
.then(compositions => compositions.forEach(c => console.log(c.sid)));

Output

_12
{
_12
"compositions": [],
_12
"meta": {
_12
"page": 0,
_12
"page_size": 10,
_12
"first_page_url": "https://video.twilio.com/v1/Compositions?Status=enqueued&PageSize=10&Page=0",
_12
"previous_page_url": "https://video.twilio.com/v1/Compositions?Status=enqueued&PageSize=10&Page=0",
_12
"url": "https://video.twilio.com/v1/Compositions?Status=enqueued&PageSize=10&Page=0",
_12
"next_page_url": "https://video.twilio.com/v1/Compositions?Status=enqueued&PageSize=10&Page=1",
_12
"key": "compositions"
_12
}
_12
}

Example: List all Compositions for a given Room

example-get-compositions-for-room page anchor

For executing this example you need:

  • Your application credentials ( SKXXXX:your_api_key_secret )
  • The target RoomSid ( RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX )

List all Compositions for a Room SID

list-all-compositions-for-a-room-sid page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.video.v1.compositions
_10
.list({roomSid: 'RMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', limit: 20})
_10
.then(compositions => compositions.forEach(c => console.log(c.sid)));

Output

_12
{
_12
"compositions": [],
_12
"meta": {
_12
"page": 0,
_12
"page_size": 10,
_12
"first_page_url": "https://video.twilio.com/v1/Compositions?Status=enqueued&PageSize=10&Page=0",
_12
"previous_page_url": "https://video.twilio.com/v1/Compositions?Status=enqueued&PageSize=10&Page=0",
_12
"url": "https://video.twilio.com/v1/Compositions?Status=enqueued&PageSize=10&Page=0",
_12
"next_page_url": "https://video.twilio.com/v1/Compositions?Status=enqueued&PageSize=10&Page=1",
_12
"key": "compositions"
_12
}
_12
}

Example: Get a Composition Media File

example-get-composition-media-file page anchor

For executing this example you need:

  • Your application credentials ( SKXXXX:your_api_key_secret )
  • The CompositionSid (CJXXXX)
  • In this example we also specify a Ttl of 3600 seconds.

Get a Composition Media File

get-a-composition-media-file page anchor
Node.js
Python
C#
Java
PHP
Ruby
curl

_32
const fs = require('fs');
_32
const request = require('request');
_32
_32
// Download the helper library from https://www.twilio.com/docs/node/install
_32
// Find your Account SID and Auth Token at twilio.com/console
_32
// and set the environment variables. See http://twil.io/secure
_32
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_32
const authToken = process.env.TWILIO_AUTH_TOKEN;
_32
const client = require('twilio')(accountSid, authToken);
_32
_32
const compositionSid = "CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
_32
const uri =
_32
"https://video.twilio.com/v1/Compositions/" +
_32
compositionSid +
_32
"/Media?Ttl=3600";
_32
_32
client
_32
.request({
_32
method: "GET",
_32
uri: uri,
_32
})
_32
.then((response) => {
_32
// For example, download the media to a local file
_32
const file = fs.createWriteStream("myFile.mp4");
_32
const r = request(response.body.redirect_to);
_32
r.on("response", (res) => {
_32
res.pipe(file);
_32
});
_32
})
_32
.catch((error) => {
_32
console.log("Error fetching /Media resource " + error);
_32
});

Output

_10
{
_10
"redirect_to":
_10
"https://com-twilio-us1-video-composition.s3.amazonaws.com/ACXXXX/CJXXXX.webm?
_10
X-Amz-Security-Token=XXXXX&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=XXXXXXXXXXXXXXX&
_10
X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Credential=XXXX&X-Amz-Signature=XXXXX"
_10
}

Deleting Compositions

example-delete page anchor

Example: Delete a Composition Instance

example-delete-composition page anchor

For executing this example you need:

  • Your application credentials ( SKXXXX:your_api_key_secret )
  • The Composition SID to delete ( CJXXXX )
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Find your Account SID and Auth Token at twilio.com/console
_10
// and set the environment variables. See http://twil.io/secure
_10
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_10
const authToken = process.env.TWILIO_AUTH_TOKEN;
_10
const client = require('twilio')(accountSid, authToken);
_10
_10
client.video.v1.compositions('CJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').remove();


Known limitations

known-issues page anchor
  • The time taken to process a Composition depends on the duration of the Room and the load that the Composition service is under at the time of the request. No specific delivery time is guaranteed.
  • The only supported formats are MP4 and WebM.
  • The maximum size of all selected Recordings for a Composition is 40 GB. For estimation of Recording's size check this table .
  • It is not allowed to delete a Composition Instance Resource with Status=failed . These instances will not count against your Storage capacity.
  • Compositions and Compositions Hooks may fail if one or more recordings has a short duration of 2 seconds or less. We recommend removing recordings with these short durations prior to creating compositions.

Rate this page: