Vonage Video API archiving lets you record, save and retrieve sessions.
This topic includes the following sections:
Important: You can only archive sessions that use the OpenTok Media Router (sessions with the media mode set to routed).
You can create an archive for an OpenTok session using the OpenTok REST API or one of the OpenTok Server SDKs. When you create an archive, the recording starts. You can only create an archive for sessions that have at least one client connected. (A client must start publishing a stream within one minute or the archive stops.)
As clients start and stop publishing streams, the streams are recorded.
Important: You can record up to 16 video streams with composed archiving, or 50 with individual stream archiving. (Both composed and individual stream archives can include up to 50 audio streams.) See Individual stream and composed archives. After this limit is reached, if additional streams are published to the session, they are not recorded. The maximum recorded length of an archive (the cumulative length of time when streams are published in the session) is 4 hours (14,400 seconds). See Archive duration for more details.
There is no limit to the number of archives you can record. (Note, however, that automatically archived sessions will restart a new recording every 4 hours until the recording stops.)
The OpenTok REST API and the OpenTok Server SDKs include methods for the following:
When you stop recording an archive, the OpenTok server creates an MP4 file or (in the case of individual stream archives) a ZIP file. (See Individual stream and composed archives.)
When an archive recording starts and stops, events are emitted in the clients. For example, the
OpenTok.js library includes archiveStarted
and archiveStopped
events
dispatched by the Session object.
The maximum recorded length of an archive is 4 hours (14,400 seconds). This recorded length
refers to the cumulative time in which streams are published (and being recorded).
While streams are published (and recorded), the archive's status is set to "started"
.
(See Archive status changes).
While an archive is recording without any streams published, the status is
set to "paused"
.
The maximum total length of an archive, including "started" and "paused" states, is 12 hours (43,200 seconds). Archives automatically time out (and stop recording) after 1 hour (3,600 seconds) of inactivity (when no clients are publishing streams).
Note: Automatically archived sessions result in one or more consecutive recordings, which have a maximum length of 4 hours each.
Use your Video API account to specify a target for completed archive files to be uploaded to. This can be your own Amazon S3 bucket, a bucket at an S3-compliant storage provider other than Amazon, or a Windows Azure container. For S3-compliant storage providers other than Amazon S3, we support Cloudian and Google Cloud Storage (accessed using the AWS S3 API). Other S3-compatible services may have feature limitations. See Using S3 storage with OpenTok archiving and Using a Windows Azure container with OpenTok archiving.
When the archive is completed (the archive status is set to "stopped"
), we will attempt to upload the archive file to the specified target (such as an S3 bucket or Azure container) for up to 72 hours after the archive is created (or at least 6 hours if fallback is enabled), retrying multiple times through a distributed upload scheduling policy.
If upload to the specified target is successful, the archive status is set to "uploaded"
.
If upload to the specified target fails (after retries) and fallback to OpenTok storage is enabled, we make the archive available for download from the OpenTok cloud, and the archive status is set to "available"
. Once the file is available for download from the OpenTok cloud, we will no longer attempt to upload to your specified target. Archives made available on the OpenTok cloud are available for 72 hours from the time they are created.
To prevent fallback storage to the OpenTok cloud, log in to your Video API account, select the project, and set the option to disable the archive storage fallback.
If upload to the specified target fails (after attempted retries) and fallback to OpenTok storage is disabled, the archive status is set to "failed"
.
You cannot access the archive until it is uploaded to your specified target or available on OpenTok storage.
For archives stored in the OpenTok cloud, the download URL is provided in the url
property of the archive when the archive status is set to "available"
. Each download URL used with archive storage fallback is a pre-signed URL that uses security credentials to grant time-limited permission to download the archive. After 10 minutes the pre-signed URL will expire and a new pre-signed URL must be requested using the REST API or server method to retrieve the download URL. For security, the download URL is only available from making the REST API calls or server SDK methods for retrieving archive information or listing archives (which require your account credentials).
When you create an archive using the OpenTok REST API or one of the OpenTok Server SDKs, you can specify whether the archive will record audio, video, or both. (The default is to record both.)
Archive output file can be of one of the following formats:
Composed archives — The archive is a single MP4 file composed of all streams. This is the default setting. It is also used for automatically archived sessions (see Automatically archived sessions). The MP4 file uses H.264 video and AAC audio (at 128 Kbps and a 48-Khz sample rate).
You can customize the layout of a composed archive, adjusting the visual arrangement of streams and which streams are displayed. See Customizing the video layout for composed archives.
By default, composed archives have a 640x480-pixel (SD landscape) resolution. To set a composed
archive to have a 480x640 (SD portrait), 1280x720 (HD landscape), 720x1280 (HD portrait),
1920x1080 (FHD landscape), 1080x1920 (FHD portrait) resolution, set the resolution
property
to "480x640"
, "1280x720"
, "1920x1080"
, "720x1280"
, or "1080x1920"
when calling the start archive method
of the OpenTok REST API. You may want to use a portrait aspect ratio when recording archives
that include video streams from mobile devices (which often use the portrait aspect ratio).
You can set the maximum video bitrate of a composed archive to control the size of the archive. Set the maxBitrate
option when calling the start archive method. Specify a bitrate, in bits per second, between 100,000 and 6,000,000. This setting only applies to the video bitrate of the archive. If the output archive has audio, those bits will be excluded from the limit. This option is only available for composed archives (not for individual stream archives). Note: Currently, the maximum video bitrate is only available in the REST API, not in the OpenTok server SDKs.
Individual stream archives — The archive is a ZIP container file with multiple individual media files for each stream, and a JSON metadata file for video synchronization. You can specify this format when you use one of the OpenTok server SDKs to start the archive. This format is not available for automatically archived sessions (see Automatically archived sessions).
Individual stream archive mode is intended for use with a post-processing tool, to produce customized content generated by your application. There are some considerations that developers should evaluate when choosing to use the feature.
Individual stream archive media is delivered as a ZIP archive, containing files for each audio-video stream:
Each stream container in the archive corresponds to a stream published to OpenTok. The publisher's stream ID matches its corresponding file name, and each stream ID is declared in the archive manifest.
When a stream is interrupted and resumed because of automatic reconnection or when a stream is added and removed repeatedly in a manual stream mode archive, the ZIP archive will include separate files for each of the stream's individual segments.
Stream containers are either of type .webm
, or .mkv
, depending on
your project's configuration. Archives for projects that have VP8 set as the
preferred video codec
have webm
containers, and projects that have H.264 set as the preferred video codec use the
mkv
format.
Individual stream archive containers are a capture of all the video and audio received by the archive server. This media is not processed, and therefore in most cases the container is not suitable for direct playback.
The stream container is treated like a transport stream — all media received at the archive server is written directly to file, without inspection or post-processing. This design has implications for downstream consumption of stream containers. In most cases, direct playback of an individual stream archive container will not be possible, or will have issues because of the contents of the container:
publishVideo
or
publishAudio
publisher properties.Frame presentation timestamps (PTS) are written based on NTP timestamps taken at the time of capture, offset by the timestamp of the first received frame. Even if a track is muted and later unmuted, the timestamp offset should remain consistent throughout the duration of the entire stream. When decoding in post-processing, a gap in PTS between consecutive frames will exist for the duration of the track mute: there are no "silent" frames in the container.
To produce viewable content from individual stream archiving files, you need to run the media through a post processor to repair individual stream containers or multiplex/composite multiple containers into a final product. Suggestions for getting started with downstream processing are outlined in our archiving-composer GitHub repository: https://github.com/opentok/archiving-composer.
Individual stream archives include a JSON metadata file, which provides information on the stream recordings included in the archive. It is of the following format:
{
"createdAt" : 1429305105162,
"files" : [
{
"connectionData" : "connection data for this stream's connection",
"filename" : "a1475893-99f5-4f02-b697-5d69e8e30d19.webm",
"size" : 5558064,
"startTimeOffset" : 3119,
"stopTimeOffset" : 48765,
"streamId" : "a1475893-99f5-4f02-b697-5d69e8e30d19",
"videoType": "camera"
},
{
"connectionData" : "connection data for this stream's connection",
"filename" : "5ab71b7b-d998-4683-ad2b-7769d6533666.webm",
"size" : 5396527,
"startTimeOffset" : 2799,
"stopTimeOffset" : 48764,
"streamId" : "5ab71b7b-d998-4683-ad2b-7769d6533666",
"videoType": "screen"
}
],
"id" : "297b9c62-78b3-4152-9e98-7e167354c9e6",
"name" : "archive name",
"partnerId" : 123456,
"sessionId" : "2_MX4xMDB-fjE0MjkzMDQ3NzY3NTZ-WUpRUGVFUmhFSkRmVGljeU5zVnJpaXYxfn4"
}
This JSON file includes the following properties:
id
— The unique identifier of this archive.
partnerId
— The partner/project ID of this archive
sessionId
— The session ID of this archive
name
— The name of this archive. This field is empty if name
was not specified in the call to start archive.
createdAt
— The Unix time in milliseconds for when the
archive started.
files
— An array of files included in the ZIP container.
Each file has the following properties:
streamId
— The corresponding stream ID for the stream
recorded to this file.
When a stream is interrupted and resumed because of automatic reconnection or when a stream is added and removed repeatedly in a manual stream mode archive, the individual stream archive will include separate files for each of the stream's individual segments.
filename
— The name of the recorded media file. This will be a .webm
for an archive of a session in an OpenTok project that uses VP8 as the prefered video
codec,
and it will be a .mkv
for an archive of a session in a project that uses H.264 as
the preferred video codec.
If a stream is interrupted and resumed because of automatic reconnection or when a stream is added and removed repeatedly in a manual stream mode archive, several files may be present for the same stream (corresponding to each segment), and the filename for each stream segment will be appended with an index number (such as "_1" or "_2") after the stream ID to identify the order of the segment.
startTimeOffset
— The offset, in milliseconds, for when
this file started recording (from the createdAt
time for the
archive)—see the important note below.
stopTimeOffset
— The offset, in milliseconds, for when
this file stopped recording (from the createdAt
time for the
archive)—see the important note below.
connectionData
— The
connection data
for the publishing client.
videoType
— Either "camera"
, "screen"
, or "custom"
. A "screen"
video uses
screen sharing on the publisher as the video source; a "custom" video is published
by a web client using an HTML VideoTrack element as the video source.
For a stream published from a mobile device, the screen type
can change from a camera to a screen-sharing video type. However, the property
in the archive manifest only indicates the initial video type.
Important: In an
individual stream archive,
if there is a short period where no streams are published during the recording,
the startTimeOffset
and stopTimeOffset values can be off by a bit.
This is a known issue.
A sample post processor application is available at https://github.com/opentok/archiving-composer.
When you start an archive, if you set the streamMode
to "manual"
, you can choose
the streams to include in the archive. You can add and remove streams during the archive recording.
And you can specify whether the archive will include a stream's audio or video (or both).
Otherwise, with the streamMode
set to "auto"
(the default), all streams are included
(with audio and video) in the archive. See
Starting an archive recording and
Selecting streams to be included in an archive.
However, in a composed archive there is a limit of 16 video streams and 50 audio streams
included at one time (for both automatic and manual stream modes), and streams are included based on
stream prioritization rules.
You can also have a session be automatically archived. You can specify this when you create the session, using the OpenTok REST API or one of the OpenTok server SDKs:
The archive for an automatically archived session starts as soon as a client connects to the session.
The REST API method to create a session includes an option to set the archive name and the archive resolution when creating an automatically archived session.
Note: If archiving is started and no data is streamed during the duration of the archive (no audio or video is published), the size of archive file will be 0 bytes.
Automatically archived sessions include both audio and video, and they record all streams to the same (composed) MP4 file. However, if the recording lasts longer than 4 hours (14,400 seconds), the session is recorded to multiple, consecutive MP4 files, of up to 4 hours each in length, until the archive is stopped. Consecutive automatic archives for a session will overlap slightly, so that no recorded data is missed.
You can call the OpenTok REST method for listing
archives and pass in the sessionID
query parameter to list archives for
a specified session ID. You can then determine the sequence of the separate MP4 files, by
looking at the createdAt
property of each archive listed in the JSON data returned
by the call the REST method.
You cannot stop an automatic archive using the OpenTok REST API or server SDKs. Automatic archives stop 60 seconds after the last client disconnects from the session or 60 minutes after the last client stops publishing a stream to the session.
To record multiple archives for the same session simultaneously, set the multiArchiveTag
option
when starting each archive. You must set this to a unique string
for each simultaneous archive of an ongoing session.
You can use different layouts and assign different streams to each simultaneous archive recording.
In automatically archived sessions, set the multiArchiveTag
option to
start a new simultaneous archive that is recorded simultaneously
with the automatic archives. Automatic archives start and end when the session starts and stops
on its own (following the rules for automatic archives), while you stop manually started separately.
You can register a callback URL for notification when an archive's status changes. The status of an archive is set to one of the following:
"started"
— The archive started and is in the process of being recorded."paused"
— When an archive is paused, nothing is recorded. The archive is paused
if any of the following conditions occur:
"stopped"
.
"stopped"
.
"paused"
state, the archive
recording resumes and the status changes back to "started"
.
"stopped"
— The archive stopped recording."uploaded"
— The archive is available for download from the archive upload target you specified at your
Video API account. Note that for very small archives, the
"uploaded"
status event may occur before the "stopped"
status event. If you have archive storage fallback enabled, upon fallback we will store the archive in the OpenTok cloud (and the status will be "available"
)."available"
— The archive is available for download from the OpenTok cloud."expired"
— The archive is no longer available for download from the OpenTok
cloud. (Archives on the OpenTok cloud are only available for 72 hours from the time they
are created.)"failed"
— The archive recording failed (or the archive file upload failed and fallback storage on the OpenTok cloud is disabled).Use your Video API account to specify a callback URL.
Secure callbacks: You can secure webhook callback requests with signed callbacks, using a signature secret. See Secure callbacks.
When an archive's status changes, the server sends HTTP POST requests to the URL you supply. The Content-Type for the request is application/json. The data of the request is a JSON object of the following form:
{
"id" : "b40ef09b-3811-4726-b508-e41a0f96c68f",
"event": "archive",
"createdAt" : 1384221380000,
"duration" : 328,
"name" : "Foo",
"partnerId" : 123456,
"reason" : "",
"resolution" : "640x480",
"sessionId" : "2_MX40NzIwMzJ-flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN-MC45NDQ2MzE2NH4",
"size" : 18023312,
"status" : "available",
"url" : "https://tokbox.com.archive2.s3.amazonaws.com/123456/b40ef09b-3811-4726-b508-e41a0f96c68f/archive.mp4"
}
The JSON object includes the following properties:
createdAt
— The timestamp for when the call to
start the archive occurred, expressed in milliseconds since the Unix epoch
(January 1, 1970, 00:00:00 UTC). Note that this value is rounded to the
nearest second. Also note that this value differs from the createdAt
value in the REST method for retrieving archive
and the createdAt
value in the
manifest for an individual stream archive
In those, the createdAt
value is set to the time the recording effectively started
on the OpenTok servers (not the time when the call to start the recording occurred).
Note that even if a call to start an archive is issued, the archive will not start
effectively recording on the OpenTok server until at least one client publishes a
stream in the session.duration
— The duration of the archive in seconds. For archives that are being recorded (with the
status property set "started"
), this value is set to 0.id
— The unique archive ID.name
— The name of the archive you supplied (this is optional)partnerId
— Your OpenTok API key.resolution
— The resolution of the archive (either "640x480", "480x640",
"1280x720", "720x1280", "1920x1080", or "1080x1920").
This property is only set for composed archives. You can set the resolution of a composed archive
when calling the start archive method
of the OpenTok REST API.reason
— For archives with the status "stopped"
or "failed"
, this string
describes the reason the archive stopped or failed. For archives with the status "stopped"
,
this can be set to "maximum duration exceeded"
, "maximum idle time exceeded"
,
"session ended"
, or "user initiated"
. For archives with the
status "failed"
,
this can be set to "failure"
.
sessionId
— The session ID of the OpenTok session that was archived.size
— The size of the archive file. For archives that have not been generated, this value is set to 0.status
— The status of the archive:
"available"
— The archive is available for download from OpenTok."expired"
— The archive is no longer available for download from the OpenTok
cloud. (Archives on the OpenTok cloud are only available for 72 hours from the time they
are created.)"failed"
— The archive recording failed."paused"
— When an archive is paused, nothing is recorded. The archive is paused
if any of the following conditions occur:
"stopped"
.
"stopped"
.
"paused"
state, the archive
recording resumes and the status changes back to "started"
.
"started"
— The archive started and is in the process of being recorded."stopped"
— The archive stopped recording."uploaded"
— The archive is available for download from the S3 bucket or
Azure container you specified in your Video API account.
Note that for very small archives, the "uploaded"
status event may occur before the
"stopped"
status event.streamMode
— Whether all streams are included in the archive (`"auto"`)
or you select streams to include in the archive (`"manual"`). See
Selecting streams to be included in an archive.
streams
— An array of objects corresponding to streams currently being
archived. This is only set for an archive with the status set to "started"
. Each
object in the array includes the following properties:
streams
— The stream ID of the stream included in the archive.
hasAudio
— Whether the stream's audio is included in the archive.
hasVideo
— Whether the stream's video is included in the archive.
url
— The download URL of the available archive file. This is only set for an archive with the status set to "available"
;
for other archives, (including archives with the status "uploaded"
) this property is set to null. For security, the download URL is only available from making REST API (or server SDK) calls for retrieving archive information or listing archives, or by accessing the URL by logging into your Video API account online (all which require authentication). After 10 minutes a download URL will expire and a new URL will be assigned with a new request.You can also view the status of archives at the Video API account:
You can secure your archives in the following ways:
The following sample apps demonstrate archiving with OpenTok:
See the documentation for the archiving-related methods in the OpenTok REST API and in the API references for the OpenTok server SDKs. Also, each of the server SDKs includes a sample archiving application.