Help Center> Live> API Reference> Examples> Example 2: Create a Recording Template

Example 2: Create a Recording Template

Scenario

If you want to record a live stream and store the recordings in VOD, you can call an API to configure a recording template.

This section describes how to configure a recording template by calling an API.

Prerequisites

  • You have determined the region where the streaming domain name for which the recording template needs to be configured is located and obtained the endpoint of the region from Regions and Endpoints.
  • You have obtained the project ID of the region where the streaming domain name is located. For details, see Obtaining a Project ID.

Procedure

  1. Log in to the Live console and obtain the target streaming domain name.
  2. Obtain a user token and use it to authenticate the calling of Live APIs.

    For details, see Making an API Request. CN North-Beijing4 is used as an example. If you need to call a Live API in another region, replace the endpoint with the IAM endpoint of the corresponding region.

    POST https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens
    Content-Type: application/json
    {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "username", 
              "password": "password", 
              "domain": {
                "name": "domainname" 
              }
            }
          }
        },
        "scope": {
          "project": {
             "name": "projectname"      
     }
        }
      }
    }
    As shown in Figure 1, information in the red box indicates the user token.
    Figure 1 Obtaining the user token

  3. Call the API for creating a recording template to configure recording parameters.

    1. Select the POST request method and enter the request URI.
      https://{endpoint}/v1/{project_id}/record/config
    2. In the request header, add X-Auth-Token and set its value to be the token obtained in 2.
    3. Specify the following parameters in the request body:
      {
         "domain" : "play.example.huawei.com",
         "app_name" : "live",
         "record_duration" : 900,
         "record_format" : "flv",
         "record_location" : "vod",
         "record_prefix" : "{DomainName}/{AppName}/{StreamName}/{StartTime}-{EndTime}" 
      }
    4. If the request succeeds, only a status code 201 Created is returned.

  4. Start recording the live stream and store the recording in VOD. For details about how to obtain recording files, see Managing Recordings.