Help Center/ Live/ Cloud Live API Reference/ Examples/ Example 1: Creating a Transcoding Template
Updated on 2024-09-27 GMT+08:00

Example 1: Creating a Transcoding Template

This section describes how to call Live APIs to create a transcoding template.

Involved APIs

To use token-based authentication, obtain a user token and add X-Auth-Token to the request header of the service API when making an API request.

Procedure

  1. 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 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

  2. Select the POST request method and enter the request URI.

    POST https://live.cn-north-4.myhuaweicloud.com/v1/{project_id}/template/transcodings
    live.cn-north-4.myhuaweicloud.com is the endpoint of Live. You can obtain the endpoint from Endpoints.

    The region where an IAM API is called must be the same as the region where a Live API is called. For example, the user token obtained when you call an IAM API in the CN North-Beijing4 region can only be used to authenticate the requests for calling Live APIs in the CN North-Beijing4 region.

  3. In the request header, add X-Auth-Token and set its value to be the token obtained in 1.
  4. Add the following parameters to the request message body. For more information about the parameters, see the API for creating a transcoding template.

    {
      "domain": "play.example.com",
      "app_name": "live",
      "quality_info":
      [
        {
          "templateName": "",
          "quality": "lsd",
          "hdlb": "off",
          "PVC": "off",
          "codec": "H264",
          "width": 854,
          "height": 480,
          "bitrate": 600,
          "video_frame_rate": 0,
          "protocol": "HLS",
          "iFrameInterval": 0
        }
      ]
    }

    If the request succeeds, only a status code 201 Created is returned.

    If the request fails, the following error code and error description are returned along with a status code 400 Bad Request:

    "error_code": "LIVE.100011001",
    "error_msg": "Failed to verify template settings."