Skip to main content

Archiver Rules (Integrators)

This guide is for program-states integrators running their own integration service. It describes how that service tells the media pipeline what to archive, by returning archiverRules in its response to the bulk ping.

If you just want to record streams to S3 from the dashboard or the API, use Recording instead — you don't need this page. Archiver rules are the lower-level mechanism that the recording config sits on top of.

The bulk ping

Your integration service is pinged periodically for every active stream, to confirm the stream should keep running and to refresh per-stream policy:

PUT /ping/bulk
Content-Type: application/json

{ "privateKeys": ["<key>", "..."] }

You respond with a JSON object keyed by the same identifier (the private/auth key), each value a BulkPingEntry:

{
"<streamId>": {
"statusCode": 200,
"status": "OK",
"message": "",
"needsAuth": false,
"missing": false,
"archiverRules": { },
"appData": { },
"rtmpPush": []
}
}

Only entries with statusCode == 200 keep archiving. A non-200 tears the stream down; missing: true means the stream is unknown and is stopped. The archiverRules you return are applied to the stream and evaluated on the next ping cycle.

archiverRules

archiverRules is a map of rule name → rule object. The rule name is a label you choose; it is not a reserved value. Reusing the same name on a later ping updates that rule (see Starting and stopping).

"archiverRules": {
"my-recording-rule": {
"name": "my-recording-rule",
"type": "all",
"driver": "hlss3",
"formats": ["all"],
"minDurSec": 10,
"maxDurSec": -1,
"continuousUploadIndex": true,
"archiveLabel": "<sessionId-or-your-label>",
"tempFilePathTemplate": "/tmp/{{{ClientReferrer}}}/{{{PublicKey}}}/{{{Height}}}",
"tempFileNameTemplate": "{{{PublicKey}}}_{{{FileSeqNum}}}_{{{FileDuration}}}.ts",
"postProcessCmds": [
{
"cmd": "S3upload",
"s3Bucket": "my-bucket",
"s3Region": "us-east-1",
"cmdArgsTemplate": ["<localPath>", "my-bucket", "<remoteKey>"]
},
{ "cmd": "rm", "cmdArgsTemplate": ["<localPath>"] }
]
}
}

Rule fields

FieldTypeNotes
namestringOptional; matches the rule name.
typestringWhat to record: all, paid, unpaid, snapshot. paid/unpaid are gated by needsAuth.
driverstringOutput writer: hlss3, flvFile, flvSnapshot.
formatsstring[]Which variants to archive (see formats values). Required — empty means no tasks.
minDurSec / maxDurSecintMin/max archive duration (sec). -1 = unbounded.
warmupintSeconds after broadcast start before archiving begins.
backfillintSeconds of pre-roll to include.
segmentDurintSegment length (ms).
intervalintSnapshot interval (ms), snapshot drivers only.
tempFilePathTemplate / tempFileNameTemplatestringLocal working path/name (templated).
pathTemplate / fileTemplatestringFinal output path/name (templated).
continuousUploadIndexboolUpload/refresh the index (e.g. index.m3u8) after each segment.
strictPostProcessboolAbort the chain if any post-process command fails.
includeMetadatastring[]Field names written as object metadata on upload.
archiveLabelstringArbitrary label, available to templates as {{{ArchiveLabel}}}.
postProcessCmdsPostProcessCmd[]Run per finished segment/file.
trailerPostProcessCmdsPostProcessCmd[]Run once at the end of the archive.
liveDvrboolBuild a live-DVR manifest from the archived segments.
publicOnlyboolRestrict to public (unauthenticated) streams.

formats values

  • "all" — every FLV variant.
  • "source" — the source variant only.
  • "source-aac" — the source (or highest-bitrate FLV) variant with AAC audio.
  • "<kbps>" — a number; picks the variant with the closest total bitrate.

Non-FLV variants are skipped.

PostProcessCmd fields

FieldNotes
cmdCommand to run, e.g. S3upload, ffmpeg, rm.
cmdArgsTemplatestring[] of args; templated. For S3upload the convention is [localPath, bucket, remoteKey].
s3AccessKeyId, s3SecretKey, s3Region, s3Url, s3Bucket, s3BaseUrlS3 credentials/target for upload commands.
s3VaultConfigName of a server-side vault credential set, instead of inline keys.
s3DisablePathCleaningbool, optional.
httpTimeoutMillisecint, optional.

Template variables

The template fields (pathTemplate, fileTemplate, tempFilePathTemplate, tempFileNameTemplate) and cmdArgsTemplate entries are rendered with mustache. Use the triple-brace form {{{Var}}} (unescaped) so path separators and special characters pass through untouched. A variable with no value for a given stream renders empty.

Stream identity: {{{PublicKey}}} (excluding any variant postfix), {{{StreamName}}} (full public name incl. variant postfix), {{{PrivateKey}}}, {{{ClientReferrer}}} (project ID), {{{UserSlug}}}, {{{CallId}}}, {{{ArchiveLabel}}}.

Media properties: {{{Width}}}, {{{Height}}}, {{{VideoKbps}}}, {{{AudioKbps}}}, {{{FrameRate}}}, {{{SegmentDur}}}, {{{SequenceNumber}}}, {{{FileSeqNum}}}, {{{FileDuration}}}.

Timestamps: {{{StreamStartTime}}}, {{{ArchiveStartTime}}}, {{{ArchiveFileStartTime}}} / {{{ArchiveFileEndTime}}}, {{{FirstVideoPTS}}} / {{{LastVideoPTS}}}, plus the zero-padded start-time components SYYYY/SMM/SDD/SHH/SMm/SSS (year, month, day, hour, minute, second) and the EYYYY/EMM/… end-time equivalents — each wrapped in the same triple-brace mustache form as the variables above.

includeMetadata is a list of these variable names whose resolved values are written as object metadata on upload.

Starting and stopping archiving

How the archiverRules field is interpreted depends on whether it is absent, empty, or populated:

What you sendEffect
No archiverRules field at all (omitted)Current rules left unchanged — archiving continues as-is.
archiverRules: {} (present but empty)Clears the stream's rules — archiving stops.
archiverRules with one or more rulesReplaces the stream's rules wholesale (not a per-rule merge).
All-or-nothing

Sending archiverRules replaces the entire set — include every rule you want to keep recording. Dropping a rule that was recording stops that archive. Omitting the field and sending {} are different: leave the field out to keep current rules running; send {} only to stop archiving entirely.

For a given rule name, fields you set override the defaults, fields you omit fall back to defaults, and reusing the name on a later ping updates that rule.

Minimal example

Archive all variants of one stream; unspecified fields use defaults:

{
"<streamId>": {
"statusCode": 200,
"status": "OK",
"needsAuth": false,
"archiverRules": {
"my-recording-rule": { "type": "all", "formats": ["all"] }
}
}
}
Related
  • Recording — the dashboard/API way to archive to S3 (most users want this).
  • Clipping & VOD — produce on-demand assets from archived sessions.
  • Webhooks Overview — the program-states webhook flow this builds on.