Lab
  • DRM packaging tutorialsCourse
  • 5 things you need to know about multi-DRMCourse
  • Getting started with Doverunner Anti PiracyCourse
  • Getting started with Doverunner Forensic WatermarkingCourse
  • Getting started with Doverunner Mobile App SecurityCourse
  • Getting started with Doverunner Multi-DRMCourse
  • Getting started with Doverunner Transcoding & PackagingCourse
  • Packaging content with the DRM CLI PackagerLesson · DRM packaging tutorials
한국어

Transcoding & Packaging with the TnP API

Get a token, register storage, create a job, and poll its status with the TnP API to produce a CMAF, DRM, and Forensic Watermarking stream.

Lesson 25 min

DRM: —FWM: —Status: idle

Transcript
Transcoding and Packaging through the API. Package a video into CMAF with DRM and forensic watermarking, using nothing but REST calls. In the Console tutorial, you created a job in the browser. Everything the Console does is also available through the Transcoding and Packaging API. The flow has four parts: get a token, register input and output storage, create the job, and poll its status until the packaged stream lands in your S3 bucket. You need five things. Your site ID and access key from the Console. An S3 bucket for input and output, with IAM access keys. The video you want to package, uploaded to the input bucket. DRM and forensic watermarking enabled on your site. And an HTTP client. This lesson uses curl. Every call starts with authentication. Join your account email and access key with a colon, and encode the result as Base64. You can use the Base64 tool in Doverunner Lab Playground, under Common Tools, or one line in your terminal. Now request a token. Call the token endpoint with your site ID, and send the Base64 value in the Authorization header, after the word Basic. Note the capital B. A lowercase basic is rejected with error E9001. The response contains your bearer token. Send it in the Authorization header of every call that follows. Next, register your S3 buckets as storage. Post to the storage endpoint with a name, the bucket, whether it is an input or an output, the S3 access key pair, and the region code. Oregon uses the code RG004. The response returns a storage ID. Register the input bucket first, then repeat the call for the output bucket with io_type set to output. Buckets you registered in the Console are shared with the API. List the storages to find their IDs. Here are the input and output storages from the previous lesson. Keep both storage IDs. The job request needs them. Now the job. Post to the job endpoint. Give it a job name and a content ID. You will use the same content ID later, in forensic watermark embedding. The input names the storage ID and the file path inside the bucket. File type multi means the file has both audio and video. The output names the output storage and the path where results go. Transcoding is a list of tracks. Each video track has an ID, a codec, the width and height, and a bitrate in bits per second. This job makes 1080p and 720p renditions. The audio track needs the same, plus a source that maps it to track zero of the input. Without that mapping, the API rejects the job. Packaging comes last. For CMAF, set cmaf to true, and keep dash and hls false. CMAF can't be combined with them. Then switch on DRM encryption and forensic watermarking with their enabled flags. Optional settings, such as clear lead or multi key, are covered in the API guide. Send the request. On success, the response contains a job ID. If something is wrong, you get an error code and message instead. For example, E2141 means an audio track is set, but no input audio is mapped. Use the job ID to check progress. Call the job details endpoint, and read the job status. This job went from media info checked, to transcoding, to packaging, and finished as complete, in about five minutes. A failed job ends in an error state. All codes and their meanings are on the status and error codes page. To be notified instead of polling, attach a notification ID to the job. When the status shows success, the stream is in your output bucket, under wm-contents, your output path, and the content ID. There are two variants, zero and one, each with a CMAF manifest in both DASH and HLS formats. The Console's Job History shows the same job, with the streaming format CMAF. To recap: encode your credentials and get a token, register storage, create the CMAF job with DRM and forensic watermarking, and poll the status. Next, embed the watermark at playback time to play the watermarked stream. Learn more details about the Transcoding and Packaging API at Doverunner Docs.

What the TnP API does

The Transcoding & Packaging (TnP) API runs the same jobs as Doverunner Console from your own code or scripts. One job transcodes a source video, packages it as CMAF, protects it with Multi-DRM, and preprocesses it for Forensic Watermarking, so the stream is ready for DRM playback and watermark embedding.

The flow has five calls: get a token, register input and output storage, create a job, poll its status, and check the output.

Before you start

  • Doverunner Site ID and access key: found in Doverunner Console
  • Two AWS S3 buckets (input and output) and an IAM user with an access key that can read and write both
  • A source MP4 uploaded to the input bucket
  • DRM and Forensic Watermarking enabled on your site
  • An HTTP client, such as curl, Postman, or your own code

All calls go to https://tnp.doverunner.com/api.

1. Get an access token

Send accountId:accessKey as Base64 in a Basic authorization header. You can encode it with the Base64 encoder / decoder in the Lab's Common Tools.

GET /api/token/{siteId}
Authorization: Basic <base64(accountId:accessKey)>

The response contains data.token. Send it as the Authorization header on every other call.

Write Basic with a capital B. The lowercase basic shown in some examples returns 401 E9001 Token value is invalid.

2. Register input and output storage

Register each bucket once with POST /api/storage/{siteId}. The response returns a storage_id; keep both.

Field Value
storage_name A name for this storage
aws_bucket The S3 bucket name
io_type input or output
access_key_id / secret_key The IAM user's access key
region The service region code (RGxxx)
description Optional note

You can list registered storages with GET /api/storage/{siteId}. The input and output buckets must be in the same region as the TnP service region.

3. Create the job

Create the job with POST /api/job/{siteId}. The request has a job name and content ID, an input section, and an output section.

{
  "job_name": "my-tutorial-job",
  "content_id": "my-content-id",
  "input": {
    "storage_id": "<input storage_id>",
    "files": [
      {
        "file_type": "multi",
        "file_path": "folder/source.mp4",
        "audios": [{ "in": { "track": 0 }, "remap": { "track": 0 } }]
      }
    ]
  },
  "output": {
    "storage_id": "<output storage_id>",
    "path": "lab-contents",
    "transcodings": [ ... ],
    "packaging": { "dash": false, "hls": false, "cmaf": true },
    "drm": { "enabled": true },
    "forensic_watermarking": { "enabled": true }
  }
}
  • content_id is the ID your player and license requests use.
  • output.path is the Output Directory Path. TnP adds the content ID below it.
  • audios maps the source audio track to the output. Without it (and the matching sources in the audio transcoding), the job fails with 400 E2141.

Transcoding

transcodings lists one entry per output rendition. Each video rendition sets track_id, track_type, codec (h264 or h265), width, height, bitrate_mode, and bitrate. The audio rendition sets codec (aac), bitrate, language, and sources.

{ "track_id": "video1", "track_type": "video", "codec": "h264",
  "width": 1920, "height": 1080, "bitrate_mode": "cbr", "bitrate": 2500000 },
{ "track_id": "video2", "track_type": "video", "codec": "h264",
  "width": 1280, "height": 720, "bitrate_mode": "cbr", "bitrate": 1200000 },
{ "track_id": "audio1", "track_type": "audio", "codec": "aac",
  "bitrate_mode": "cbr", "bitrate": 128000, "language": "en",
  "sources": [{ "track": 0 }] }

Packaging, DRM, and watermarking

Set packaging.cmaf to true to package CMAF, which serves Widevine, PlayReady, and FairPlay from one set of segments. drm and forensic_watermarking only need { "enabled": true }. Other options are optional; see the TnP API guide.

A successful request returns data.job_id. Failed requests return an error_code and error_message.

4. Poll the job status

GET /api/job/{siteId}/{jobId}

Read job_status from the response. The codes you see on a normal run are:

Code State
TP010 Media info checked
TP100100 Transcoding
TP300100 Packaging
TP500 Complete

TP600 means the job failed. The full list is on the status and error codes page. A job like this one takes a few minutes.

5. Check the output

When the status is TP500, the output is in the output bucket under wm-contents/<path>/<content ID>/:

wm-contents/
└── <output.path>/
    └── <content ID>/
        ├── 0/cmaf/   (stream.mpd, master.m3u8, video/, audio/)
        └── 1/cmaf/

0 and 1 are the two watermark variants (A/B). You can cross-check the job in Transcoding & Packaging > Job History in Doverunner Console. Doverunner also sends a notification email when a job finishes or fails.

The video above is this kind of output: CMAF, DRM, and watermark variants, played through the Lab's Session URL API. The next step is watermark embedding.

Next steps

To run TnP jobs from your own system, see the TnP API guide for every endpoint and job option, storage management and job notifications, and the status and error codes.