tencent cloud

Feedback

Playing DRM-Encrypted Videos

Last updated: 2022-04-27 11:32:57

    Overview

    This document shows you how to encrypt videos using DRM solutions and use player to play the encrypted videos.

    Prerequisites

    Before you start, do the following:

    Activate VOD

    Follow the steps below to activate VOD:

    1. Sign up for a Tencent Cloud account and complete identity verification.
    2. Purchase VOD services. For details, see Billing Overview.
    3. Go to the VOD console.

    At this point, you have activated VOD.

    Apply for a FairPlay certificate and submit the certificate information

    For detailed directions, see Applying for FairPlay Certificate and Submitting Certificate Information. After submitting the information, view and note the certificate URL in the console for later use.

    The example below shows how to enable key hotlink protection for the default distribution domain under your account:

    Note:

    We do not recommend enabling hotlink protection for a domain name already in use, because it may result in playback failure.

    1. Log in to the VOD console, select Distribution and Playback > Domain Name, find the default distribution domain, and click Set on the right.

    2. Click Access Control and toggle Key Hotlink Protection on. In the pop-up window, click Generate to generate a random key (testtest). Copy the key, which is needed to generate superplayer signature, and click Confirm to save the configuration.

      image-KEY

    Step 2. Encrypt a video

    1. In the VOD console, select Media Assets > Video Management, select the target video (file ID: 387702299667618135), and click Process Video.

      image-20220426211316803

    2. On the video processing page:

    • Select Task Flow as the Processing Type.

    • Select WidevineFairPlayPreset as the Task Flow Template.

      image-20220425192205432

    Note:

    • WidevineFairPlayPreset is a preset task flow. It uses the adaptive bitrate streaming template 11 or 13, the time point screenshot template 10 (for thumbnail generation), and the image sprite template 10.
    • The adaptive bitrate streaming template 11 generates multi-bitrate streams encrypted by FairPlay, and the adaptive bitrate streaming template 13 generates multi-bitrate streams encrypted by Widevine.
    1. Click Confirm and wait until the Video Status changes from "Processing" to "Normal", which indicates that video processing is completed.
    1. Click Manage in the Operation column of the video to enter the management page:
    • Click the Basic Info tab to view the generated thumbnail and outputs of adaptive bitrate streaming (template ID: 11/13).

      image-20220426201159056

    • Click the Screenshot Info tab to view the generated image sprite (template ID: 10).

      image-20220426201309975

    Step 3. Gernaerate the superplayer signature

    The superplayer signature is used to get playback information.For how to generate it, see Superplayer Signature. The payload of the superplayer signature is as follows:

    {
    "appId": 1500012416,
    "fileId": "387702299667618135",
    "currentTimeStamp": 1650886156,
    "expireTimeStamp": 1966435200,
    "urlAccessInfo": {
      "t": "75356B80",
      "us": "72d4cd1101"
    },
    "pcfg":"advanceDrmPreset"
    }
    

    the key is testtest. The superplayer signature(psign) generated is as follows:

    eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MTUwMDAxMjQxNiwiZmlsZUlkIjoiMzg3NzAyMjk5NjY3NjE4MTM1IiwiY3VycmVudFRpbWVTdGFtcCI6MTY1MDg4NjE1NiwiZXhwaXJlVGltZVN0YW1wIjoxOTY2NDM1MjAwLCJ1cmxBY2Nlc3NJbmZvIjp7InQiOiI3NTM1NkI4MCIsInVzIjoiNzJkNGNkMTEwMSJ9LCJwY2ZnIjoiYWR2YW5jZURybVByZXNldCJ9.kkyOyscuV3WIlFV0IFPsPPWomZEcuNGclaBzpEO8DEg

    Step 4. Get the playback information

    The following example shows how to get the playback information from the URL.

    The HTTP GET request method is used, and the URL is https://playvideo.qcloud.com/getplayinfo/v4/{appId}/{fileId}?psign={psign}.

    Here, the {appId} attribute is the application ID (if you use a subapplication, pass in the subapplication ID). The {fileId} attribute is the ID of the media file, and the {psign} attribute is created in Step 3.

    The request URL is as follows:

    https://playvideo.qcloud.com/getplayinfo/v4/1500012416/387702299667618135?psign=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MTUwMDAxMjQxNiwiZmlsZUlkIjoiMzg3NzAyMjk5NjY3NjE4MTM1IiwiY3VycmVudFRpbWVTdGFtcCI6MTY1MDg4NjE1NiwiZXhwaXJlVGltZVN0YW1wIjoxOTY2NDM1MjAwLCJ1cmxBY2Nlc3NJbmZvIjp7InQiOiI3NTM1NkI4MCIsInVzIjoiNzJkNGNkMTEwMSJ9LCJwY2ZnIjoiYWR2YW5jZURybVByZXNldCJ9.kkyOyscuV3WIlFV0IFPsPPWomZEcuNGclaBzpEO8DEg
    

    The response will be:

    {
    "code": 0,
    "message": "",
    "requestId": "9c7fab8704994c6b96375393e6544b5c",
    ...
    "media": {
    ...
      "streamingInfo": {
        "drmOutput": [
          {
            "type": "FairPlay",
            "url": "http://1500012416.vod2.myqcloud.com/4394a0devodtranscq1500012416/d811753f387702299667618135/adp.11.m3u8?t=75356B80&us=72d4cd1101&sign=73558bdac4a3ea43913806201ba0315b",
            ...
          },
          {
            "type": "Widevine",
            "url": "http://1500012416.vod2.myqcloud.com/4394a0devodtranscq1500012416/d811753f387702299667618135/adp.13.m3u8?t=75356B80&us=72d4cd1101&sign=73558bdac4a3ea43913806201ba0315b",
            ...
          }
        ],
        "drmToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9~eyJ0eXBlIjoiRHJtVG9rZW4iLCJhcHBJZCI6MTUwMDAxMjQxNiwiZmlsZUlkIjoiMzg3NzAyMjk5NjY3NjE4MTM1IiwiY3VycmVudFRpbWVTdGFtcCI6MTY1MDk2NDM3NCwiZXhwaXJlVGltZVN0YW1wIjoyMTQ3NDgzNjQ3LCJyYW5kb20iOjQyMjAwMDM2NTUsIm92ZXJsYXlLZXkiOiIiLCJvdmVybGF5SXYiOiIiLCJjaXBoZXJlZE92ZXJsYXlLZXkiOiIiLCJjaXBoZXJlZE92ZXJsYXlJdiI6IiIsImtleUlkIjowLCJzdHJpY3RNb2RlIjowfQ~VfpyAFQL59xD-TJkr8kSAiXTZpd-dQdvmPkzw1PVIa8",
        "widevineLicenseUrl": "https://widevine.drm.vod-qcloud.com/widevine/getlicense/v2",
        "fairplayLicenseUrl": "https://fairplay.drm.vod-qcloud.com/fairplay/getlicense/v2"
      },
      ...
    }
    }
    

    From the above response, you can get the following playback information:

    1. The URL of the DRM-encrypted video.

    2. The license server URL :

      • The license server URL for Widevine encryption is spliced using drmToken and widevineLicenseUrl.

      • The license server URL for FairPlay encryption is spliced using drmToken and fairplayLicenseUrl.

    Below is the playback information obtained from the above sample:

    Widevine encryption:

    • URL of the encrypted video: https://1500012416.vod2.myqcloud.com/4394a0devodtranscq1500012416/d811753f387702299667618135/adp.13.m3u8?t=75356B80&us=72d4cd1101&sign=73558bdac4a3ea43913806201ba0315b
    • License server URL: https://widevine.drm.vod-qcloud.com/widevine/getlicense/v2?drmToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9~eyJ0eXBlIjoiRHJtVG9rZW4iLCJhcHBJZCI6MTUwMDAxMjQxNiwiZmlsZUlkIjoiMzg3NzAyMjk5NjY3NjE4MTM1IiwiY3VycmVudFRpbWVTdGFtcCI6MTY1MDk2NDM3NCwiZXhwaXJlVGltZVN0YW1wIjoyMTQ3NDgzNjQ3LCJyYW5kb20iOjQyMjAwMDM2NTUsIm92ZXJsYXlLZXkiOiIiLCJvdmVybGF5SXYiOiIiLCJjaXBoZXJlZE92ZXJsYXlLZXkiOiIiLCJjaXBoZXJlZE92ZXJsYXlJdiI6IiIsImtleUlkIjowLCJzdHJpY3RNb2RlIjowfQ~VfpyAFQL59xD-TJkr8kSAiXTZpd-dQdvmPkzw1PVIa8

    FairPlay encryption:

    • URL of the encrypted video: https://1500012416.vod2.myqcloud.com/4394a0devodtranscq1500012416/d811753f387702299667618135/adp.11.m3u8?t=75356B80&us=72d4cd1101&sign=73558bdac4a3ea43913806201ba0315b
    • License server URL: https://fairplay.drm.vod-qcloud.com/fairplay/getlicense/v2?drmToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9~eyJ0eXBlIjoiRHJtVG9rZW4iLCJhcHBJZCI6MTUwMDAxMjQxNiwiZmlsZUlkIjoiMzg3NzAyMjk5NjY3NjE4MTM1IiwiY3VycmVudFRpbWVTdGFtcCI6MTY1MDk2NDM3NCwiZXhwaXJlVGltZVN0YW1wIjoyMTQ3NDgzNjQ3LCJyYW5kb20iOjQyMjAwMDM2NTUsIm92ZXJsYXlLZXkiOiIiLCJvdmVybGF5SXYiOiIiLCJjaXBoZXJlZE92ZXJsYXlLZXkiOiIiLCJjaXBoZXJlZE92ZXJsYXlJdiI6IiIsImtleUlkIjowLCJzdHJpY3RNb2RlIjowfQ~VfpyAFQL59xD-TJkr8kSAiXTZpd-dQdvmPkzw1PVIa8

    Step 5. Play the DRM-encrypted video in a player

    The examples below show you how to play videos encrypted using Widevine and FairPlay respectively.

    Play videos encrypted using Widevine

    Go to the Shaka Player Demo page via Chrome.

    image-20220426163418989

    Click the + icon, and enter the URL of the encrypted video obtained in Step 4 for Manifest URL. Pass in Widevine for Name.

    image-20220426163853470

    Enter the license server URL for Widevine obtained in Step 4 and click Save.

    image-20220426163939777

    The Widevine playback options will appear in the page.

    image-20220426164129657

    Click Play to play the encrypted video.

    Play videos encrypted using FairPlay

    Go to the Shaka Player Demo page via Safari.

    image-20220426163418989

    Click the + icon, and enter the URL of the encrypted video obtained in Step 4 for Manifest URL. Pass in FairPlay for Name.

    image-20220426164907499

    Enter the license server URL for FairPlay obtained in Step 4 for Custom License Server URL. Enter the FairPlay certificate (you can get the certificate in the VOD console) for Custom License Certificate URL and click Save.

    image-20220426164950762

    The FairPlay playback options will appear in the page.

    image-20220426165137520

    Click Play to play the encrypted video.

    Summary

    Now, you have learned how to encrypt videos using DRM solutions and play the encrypted videos in a player.

    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support