tencent cloud

Video on Demand

DocumentationVideo on Demand

Playing Encrypted Videos (Commercial-Grade)

Download
Focus Mode
Font Size
Last updated: 2022-12-01 15:59:30

Introduction

This document shows you how to use a third-party player to play encrypted (Widevine, FairPlay) videos of VOD.

Overview

To decrypt and play an encrypted video using a third-party player, you need to obtain the playback information.
You will need the following playback information:
Widevine
DrmToken (which is used to get the playback license)
The URL of the video content
The URL of the playback license
FairPlay
DrmToken (which is used to get the playback license)
The URL of the video content
The URL of the playback license
The URL of the certificate

Workflow

Commercial-grade DRM (Widevine and FairPlay)




Get the playback information and signature After successful authentication, your application server sends the playback information and signature (DrmToken) to the client.
Download the video and certificate and request a license
When the player tries to play the video, a request for the license and certificate will be sent automatically.
Decrypt and play the video
The player uses the license obtained to decrypt and play the video.

Generating DrmToken

DrmToken is essentially a variant of JSON Web Token (JWT). It also consists of three parts: the header, the payload, and the signature. However, unlike JWT, VOD connects the three parts with ~.
The header is in JSON format and indicates the algorithm information used by JWT. Its content is fixed as follows:
{
"alg": "HS256",
"typ": "JWT"
}

Payload

The payload is in JSON format and includes the player signature parameters. Below is an example:
{
"type": "DrmToken",
"appId": 1500014561,
"fileId": "387702307091793695",
"currentTimeStamp": 1650964374,
"expireTimeStamp": 2147483647,
"random": 4220003655,
"issuer": "client"
}

Payload parameters

Parameter
Type
Required
Description
type
string
Yes
The signature type, which should be set to DrmToken.
appId
int64
Yes
The AppId.
fileId
string
Yes
The file ID.
issuer
string
Yes
The issuer, which should be set to client.
currentTimeStamp
int64
Yes
The current time (Unix timestamp).
expireTimeStamp
int64
No
The expiration time (Unix timestamp). If you do not specify this, the signature will not expire.
random
int64
No
A random number.

Signature

Calculation method

Signature = HMACSHA256(base64UrlEncode(Header) + "." + base64UrlEncode(Payload), pkey)
Note:
For more information about the HMACSHA256 algorithm, see RFC 4868 - Using HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512 with IPsec. For more information about base64UrlEncode, see Base 64 Encoding with URL and Filename Safe Alphabet.
You can view the playback key (pkey) in the VOD console:
Select Distribution and Playback > Default Distribution Domain on the left sidebar.


DrmToken example

Header:
{
"alg": "HS256",
"typ": "JWT"
}
Encoded (base64UrlEncode): eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
Payload:
{
"type": "DrmToken",
"appId": 1500014561,
"fileId": "387702307091793695",
"currentTimeStamp": 1650964374,
"expireTimeStamp": 2147483647,
"random": 4220003655,
"issuer": "client"
}
Encoded (base64UrlEncode): eyJ0eXBlIjoiRHJtVG9rZW4iLCJhcHBJZCI6MTUwMDAxNDU2MSwiZmlsZUlkIjoiMzg3NzAyMzA3MDkxNzkzNjk1IiwiY3Vyc
mVudFRpbWVTdGFtcCI6MTY1MDk2NDM3NCwiZXhwaXJlVGltZVN0YW1wIjoyMTQ3NDgzNjQ3LCJyYW5kb20iOjQyMjAwMDM2NTUsImlzc3VlciI6ImNsaWVudCJ9
Signature: muHWnxX9dXsUAkCzw4uXGcvwKDoA19BkR-hCJVrXyvY. It is generated using pkey (whose value is JduzsUuRvGVPRHvIYwLv).

Connect the header, payload, and signature with ~ and you will get the DrmToken, which is eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9~eyJ0eXBlIj
oiRHJtVG9rZW4iLCJhcHBJZCI6MTUwMDAxNDU2MSwiZmlsZUlkIjoiMzg3NzAyMzA3MDkxNzkzNjk1IiwiY3VycmVudFRpbWVTdGFtcCI6MTY1MDk2NDM3NCwiZXh
waXJlVGltZVN0YW1wIjoyMTQ3NDgzNjQ3LCJyYW5kb20iOjQyMjAwMDM2NTUsImlzc3VlciI6ImNsaWVudCJ9~NN_EBW7VxGK69v-w9Q7Dw-sm8Uryfe_NdRUe3R
ZZ4wY.

Generating a Playback URL

Call DescribeMediaInfos to get the URL of the video content (the value of MediaInfoSet.AdaptiveDynamicStreamingInfo.AdaptiveDynamicStreamingSet.Url).
If you have enabled key hotlink protection, refer to Key Hotlink Protection to generate a URL that includes the hotlink protection signature.

Generating a License URL

In case of commercial-grade DRM, a license is needed for a player to play encrypted videos.

Request

Request URL:
Widevine: https://widevine.drm.vod-qcloud.com/widevine/getlicense/v2
FairPlay: https://fairplay.drm.vod-qcloud.com/fairplay/getlicense/v2
Request method: POST
Request parameters:
Parameter
Description
drmToken
The authentication token.
Note:
Include in the request body the license request data generated by the DRM client module.

Response

If the request is successful, the status code will be 200, and the binary data of the license will be returned.
If the request fails, the status code will be a value other than 200.

Status codes

Status Code
Description
200
Request successful.
400
Parameter error.
403
Authentication failed.
500
Internal error.

License request example

A license request URL for Widevine: https://widevine.drm.vod-qcloud.com/widevine/getlicense/v2?drmToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9~eyJ0eXBlIjoiRHJtVG9r
ZW4iLCJhcHBJZCI6MTUwMDAxNDU2MSwiZmlsZUlkIjoiMzg3NzAyMzA3MDkxNzkzNjk1IiwiY3VycmVudFRpbWVTdGFtcCI6MTY1MDk2NDM3NCwiZXhwaXJlVGltZ
VN0YW1wIjoyMTQ3NDgzNjQ3LCJyYW5kb20iOjQyMjAwMDM2NTUsImlzc3VlciI6ImNsaWVudCJ9~NN_EBW7VxGK69v-w9Q7Dw-sm8Uryfe_NdRUe3RZZ4wY

Getting the License URL

To play a FairPlay-encrypted video, you need to apply for a FairPlay certificate and submit the certificate information to VOD. License URLs are not required for Widevine.
After submitting the information, you can view the license URL in the VOD console. Each subapplication has only one license URL.

Playing the Video Using a Third-Party Player

Once you have the playback URL, license URL, and certificate URL, you can use a third-party player to play the DRM-encrypted video.

Summary

Now, you should know how to play encrypted videos of VOD using a third-party player.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback