Help Center/ Live/ Cloud Live API Reference/ Recording Management/ Creating a Video Recording Index
Updated on 2024-07-11 GMT+08:00

Creating a Video Recording Index

Function

A recording index is a TS file recorded in HLS video streams. A new M3U8 file is generated based on the specified time range.

Constraints

In the recording configuration, the recording format must contain HLS, and the record_ts_prefix parameter must be set to the default value {file_start_time_unix}{file_end_time_unix}{ts_sequence_number}. There must be streams that are successfully pushed in the requested time range. The recording files involved in the same request must be in the same OBS bucket. A recording index can be created only when its start time is within 30 days later than the current time. If the duration of the request time segment is shorter than the TS segment duration in the HLS recording configuration, the TS segment that overlaps the request time segment is returned and the TS file is not tailored. If the interval between the request time and the start time in the request is less than the duration of a TS segment, the request may fail because the TS segment recording is not complete.

Calling Method

For details, see Calling APIs.

URI

POST /v1/{project_id}/record/indexes

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

No

String

User token.

It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is a token.

Authorization

No

String

Authentication information. This parameter is mandatory for AK/SK authentication.

X-Sdk-Date

No

String

Time when the request is sent. This parameter is mandatory for AK/SK authentication.

X-Project-Id

No

String

Project ID. This parameter is mandatory for AK/SK authentication.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

publish_domain

Yes

String

Ingest domain name

app

Yes

String

App name

stream

Yes

String

Stream name

start_time

Yes

String

Start time. The format is YYYY-MM-DDTHH:mm:ssZ (UTC time). The maximum interval between the start time and end time is 12 hours. The start time cannot be later than the current time.

end_time

Yes

String

End time. The format is YYYY-MM-DDTHH:mm:ssZ (UTC time). The maximum interval between the start time and end time is 12 hours. The start time must be earlier than the end time.

object

No

String

Path for storing M3U8 files in an OBS bucket. The following strings can be escaped: - {publish_domain} - {app} - {stream} - {start_time} - {end_time} - {start_time_unix} - {end_time_unix}, where {start_time}, {end_time}, {start_time_unix}, and {end_time_unix} indicate the actual time when the result is returned. The default value is Index/{publish_domain}/{app}/{stream}/{stream}-{start_time}-{end_time}.

Response Parameters

Status code: 201

Table 4 Response header parameters

Parameter

Type

Description

X-request-id

String

Request ID for task tracing. Format: *request_id-timestamp-hostname*. (*request_id* is the UUID generated on the server. *timestamp* is the current timestamp, and *hostname* is the name of the server that processes the current request.)

Table 5 Response body parameters

Parameter

Type

Description

index_url

String

Index file address

publish_domain

String

Ingest domain name

app

String

App name

stream

String

Stream name

start_time

String

Start time. The format is yyyy-MM-ddTHH:mm:ssZ (UTC time). (Actual video start time)

end_time

String

End time. The format is yyyy-MM-ddTHH:mm:ssZ (UTC time). (Actual video end time)

duration

Integer

Recording duration

Unit: second

width

Integer

Video width.

height

Integer

Video height

location

String

ID of the region where the OBS bucket resides

bucket

String

Bucket name

object

String

M3U8 file path, which defaults to Index/{publish_domain}/{app}/{stream}-{start_time}-{end_time}

Status code: 400

Table 6 Response header parameters

Parameter

Type

Description

X-request-id

String

Request ID for task tracing. Format: *request_id-timestamp-hostname*. (*request_id* is the UUID generated on the server. *timestamp* is the current timestamp, and *hostname* is the name of the server that processes the current request.)

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Error Code

error_msg

String

Error description

Example Requests

Creates a video recording index.

POST https://{endpoint}/v1/{project_id}/record/indexes

{
  "publish_domain" : "push.example.com",
  "app" : "live",
  "stream" : "index",
  "start_time" : "2022-07-25T16:20:00+08:00",
  "end_time" : "2022-07-25T16:30:00+08:00",
  "object" : "Index/{publish_domain}/{app}/{stream}/{stream}-{start_time}-{end_time}"
}

Example Responses

Status code: 201

Creation of the video recording index succeeded.

{
  "index_url" : "http://obs***.com/push.test.com/live/stream01-20220901000000-20220901001000.m3u8",
  "duration" : 600,
  "height" : 1080,
  "width" : 720,
  "publish_domain" : "push.test.com",
  "app" : "live",
  "stream" : "stream01",
  "start_time" : "2022-09-01T00:00:00Z",
  "end_time" : "2022-09-01T00:10:00Z",
  "bucket" : "obs_bucket_name",
  "location" : "cn-north-5",
  "object" : "push.test.com/live/stream01-20220901000000-20220901001000.m3u8"
}

Status code: 400

Create a video recording index failed. Common errors:

  • illegal time range: The request time range is incorrect. Check the start_time and end_time.

  • no record info found: No recording task is found in the request time segment. The possible cause is that no livestream is successfully pushed in the time segment or command recording is not started under the command recording rule.

  • no ts info found: No TS file is found in the request time segment. The possible cause is that stream interruption occurs in the request time segment or the TS segment recording is not complete when the request is sent.

{
  "error_code" : "LIVE.100011001",
  "error_msg" : "Parameter verification failed."
}

SDK Sample Code

The SDK sample code is as follows.

Creates a video recording index.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.live.v1.region.LiveRegion;
import com.huaweicloud.sdk.live.v1.*;
import com.huaweicloud.sdk.live.v1.model.*;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;

public class CreateRecordIndexSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        LiveClient client = LiveClient.newBuilder()
                .withCredential(auth)
                .withRegion(LiveRegion.valueOf("<YOUR REGION>"))
                .build();
        CreateRecordIndexRequest request = new CreateRecordIndexRequest();
        RecordIndexRequestBody body = new RecordIndexRequestBody();
        body.withObject("Index/{publish_domain}/{app}/{stream}/{stream}-{start_time}-{end_time}");
        body.withEndTime(OffsetDateTime.parse("2022-07-25T16:30:00+08:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME));
        body.withStartTime(OffsetDateTime.parse("2022-07-25T16:20:00+08:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME));
        body.withStream("index");
        body.withApp("live");
        body.withPublishDomain("push.example.com");
        request.withBody(body);
        try {
            CreateRecordIndexResponse response = client.createRecordIndex(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Creates a video recording index.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdklive.v1.region.live_region import LiveRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdklive.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = LiveClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(LiveRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = CreateRecordIndexRequest()
        request.body = RecordIndexRequestBody(
            object="Index/{publish_domain}/{app}/{stream}/{stream}-{start_time}-{end_time}",
            end_time="2022-07-25T16:30:00+08:00",
            start_time="2022-07-25T16:20:00+08:00",
            stream="index",
            app="live",
            publish_domain="push.example.com"
        )
        response = client.create_record_index(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Creates a video recording index.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main

import (
	"fmt"
	"time"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/sdktime"
    live "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/live/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/live/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/live/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := live.NewLiveClient(
        live.LiveClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.CreateRecordIndexRequest{}
	objectRecordIndexRequestBody:= "Index/{publish_domain}/{app}/{stream}/{stream}-{start_time}-{end_time}"
	dateTimeEndTime, _ := time.ParseInLocation("2006-01-02T15:04:05Z", "2022-07-25T16:30:00+08:00", time.UTC)
	sdkTimeEndTime := sdktime.SdkTime(dateTimeEndTime)
	dateTimeStartTime, _ := time.ParseInLocation("2006-01-02T15:04:05Z", "2022-07-25T16:20:00+08:00", time.UTC)
	sdkTimeStartTime := sdktime.SdkTime(dateTimeStartTime)
	request.Body = &model.RecordIndexRequestBody{
		Object: &objectRecordIndexRequestBody,
		EndTime: &sdkTimeEndTime,
		StartTime: &sdkTimeStartTime,
		Stream: "index",
		App: "live",
		PublishDomain: "push.example.com",
	}
	response, err := client.CreateRecordIndex(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

201

Creation of the video recording index succeeded.

400

Create a video recording index failed. Common errors:

  • illegal time range: The request time range is incorrect. Check the start_time and end_time.

  • no record info found: No recording task is found in the request time segment. The possible cause is that no livestream is successfully pushed in the time segment or command recording is not started under the command recording rule.

  • no ts info found: No TS file is found in the request time segment. The possible cause is that stream interruption occurs in the request time segment or the TS segment recording is not complete when the request is sent.

Error Codes

See Error Codes.