Suggestions

close search

Archiving

OpenTok archiving lets you record, save, and retrieve OpenTok sessions.

Basic workflow

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: The recommended maximum number of streams in an archive is five. You can record up to nine streams; however, in a composed archive quality may degrade if you record more than five streams. If more than nine streams are published to the session, they are not recorded. Also, archive recordings are limited to 120 minutes in length.

There is no limit to the number of archives you can record. (Note, however, that automatically archived sessions will restart a new recording every 120 minutes 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 sent in the clients. For example, the OpenTok.js library includes archiveStarted and archiveStopped events dispatched by the Session object.

Archive storage

Use your TokBox Account to specify your own Amazon S3 bucket or Windows Azure container for completed archive files to be uploaded to. See Using an Amazon S3 bucket with OpenTok archiving and Using an Windows Azure container with OpenTok archiving.

If you do not set an Amazon S3 bucket or Windows Azure container, or if uploading to the specified bucket or container fails, recorded archives are available for retrieval by download from the OpenTok cloud. Archives made available on the OpenTok cloud are available for 72 hours from the time they are created. To prevent this fallback storage, log in to your TokBox Account, select the project, and set the option to disable the archive storage fallback.

Audio-only and video-only archives

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.)

Individual stream and composed archives

Archive output file can be of one of the following formats:

Working with individual stream archives

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 containers

Individual stream archive media is delivered as a ZIP archive, with a .webm container for each stream. This is not a playable container; the stream container is treated like a transport stream — all data received at the archive server is written directly to file, without inspection or processing. This design has several consequences that make the container unsuitable for direct playback in most video players:

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.

Individual stream archive manifest

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",
  "sessionId" : "2_MX4xMDB-fjE0MjkzMDQ3NzY3NTZ-WUpRUGVFUmhFSkRmVGljeU5zVnJpaXYxfn4"
}

This JSON file includes the following properties:

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.

Post processing individual archives

A sample post processor application is available at https://github.com/opentok/archiving-composer

Automatically archived sessions

You can also have a session be automatically archived. You can specify this when you create the session, using one of the OpenTok server SDKs. The archive for an automatically archived session starts as soon as a client connected to the session starts publishing a stream.

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 2 hours (120 minutes), the session is recorded to multiple, consecutive MP4 files, of up to 2 hours each in length, until the archive is stopped.

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 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.

Archive status changes

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:

Use your TokBox Account to specify a callback URL. 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" : "",
    "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:

You can also view the status of archives at the TokBox Account:

  1. Navigate to your TokBox Account page.
  2. From the list of projects in the left of the page, select the project that will contain sessions that you are archiving.
  3. In the Archiving section, click the Archive List tab. Details on archives in the project are listed.

Archive security

You can secure your archives in the following ways:

More information

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.