tencent cloud

文档反馈

SimpleHlsClip

最后更新时间:2024-09-24 17:24:23

    1. API Description

    Domain name for API request: vod.tencentcloudapi.com.

    This API is used to cut a clip from an HLS video to generate a new video (in HLS format). You can either share the new video or save it.

    VOD supports two types of clipping:

    • Clipping for persistent storage: The video clip is saved as an independent video file with its own FileId.
    • Clipping for temporary sharing: The video clip shares FileId with the input file.

    Notes:

    • Clipping is based on the M3U8 file that contains a list of TS segments, so the smallest clipping unit is one TS segment instead of a second or less.

    Clipping for persistent storage

    In this mode, a video clip is saved as an independent video file with a FileId, and its lifecycle is not subject to the input video. Even if the source video is deleted, the video clip still exists. Moreover, the video clip can be transcoded, published on WeChat, and processed in other ways.

    Suppose you recorded a two-hour football match. You want to save the full video for only two months to save costs, but want to save the highlights for a longer time and perhaps transcode and publish the highlight clip to WeChat. In this case, you can choose clipping for persistent storage.

    The advantage of clipping for persistent storage is that the video clip has a lifecycle independent of the input video and can be managed independently and stored persistently.

    Notice: If solidification is specified during clipping, enable the reception of persistence completed event notifications through the ModifyEventConfig interface. After successful solidification, an event notification of type PersistenceComplete will be received. Before receiving this event notification, operations such as deletion or cooling down of live recording videos should not be performed, otherwise, abnormal playback may occur in the video generated by the clipping.

    Clipping for temporary sharing

    The video clip (an M3U8 file) shares the same TS segments with the input video instead of being an independent video. It only has a playback URL but has no FileId, and its validity period is the same as that of the input video. Once the input video is deleted, the video clip cannot be played back.

    Because the video clip is not an independent video, it's not displayed as a media asset in the VOD console, and cannot be transcoded or published to WeChat.

    Clipping for temporary sharing is lightweight and incurs no additional storage fees. However, the video clip has the same lifecycle as the source recording video and cannot be transcoded or processed in other ways.

    A maximum of 100 requests can be initiated per second for this API.

    We recommend you to use API Explorer
    Try it
    API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

    2. Input Parameters

    The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

    Parameter Name Required Type Description
    Action Yes String Common Params. The value used for this API: SimpleHlsClip.
    Version Yes String Common Params. The value used for this API: 2018-07-17.
    Region No String Common Params. This parameter is not required.
    Url Yes String URL of the HLS video in VOD that needs to be clipped.
    SubAppId No Integer The VOD application ID. For customers who activate VOD service from December 25, 2023, if they want to access resources in a VOD application (whether it's the default application or a newly created one), they must fill in this field with the application ID.
    StartTimeOffset No Float Start offset time of clipping in seconds. Default value: 0, which means to clip from the beginning of the video. A negative number indicates how many seconds from the end of the video clipping will start at. For example, -10 means that clipping will start at the 10th second from the end.
    EndTimeOffset No Float End offset time of clipping in seconds. Default value: 0, which means to clip till the end of the video. A negative number indicates how many seconds from the end of the video clipping will end. For example, -10 means that clipping will end at the 10th second from the end.
    IsPersistence No Integer Whether to store the video clip persistently. 0: no (default), 1: yes.
    ExpireTime No String The expiration time of the video clip that is to be saved, in ISO date format. 9999-12-31T23:59:59Z is the default value, which means the video clip will never expire. After expiration, the media file and its related resources (such as transcoding results and image sprites) will be permanently deleted. This parameter is valid only if IsPersistence is 1.
    Procedure No String The task flow to execute on the video clipped for persistent storage. For details, see Upload from Server. This parameter is valid only if IsPersistence is 1.
    ClassId No Integer The ID of the media file's category. You can use the CreateClass API to create a category and get the category ID.
  • The default value is 0, which means the "Other" category.

  • This parameter is valid only if IsPersistence is 1.
    SourceContext No String The source context, which is used to pass through user request information. The NewFileUpload callback will return the value of this parameter. It can contain up to 250 characters and is valid only if IsPersistence is 1.
    SessionContext No String The session context, which is used to pass through user request information. If the Procedure parameter is specified, the ProcedureStateChanged callback will return the value of this parameter. It can contain up to 1,000 characters and is valid only if IsPersistence is 1.
    Precision No String
    OutputMediaType No String
    ExtInfo No String

    3. Output Parameters

    Parameter Name Type Description
    Url String Address of clipped video.
    MetaData MediaMetaData Metadata of clipped video. Currently, Size, Rotate, VideoDuration, and AudioDuration fields use default value with no actual data.
    FileId String Unique ID of a video clip for persistent storage.
    TaskId String The ID of the task flow to execute on the video clipped for persistent storage.
    RequestId String The unique request ID, generated by the server, will be returned for every request (if the request fails to reach the server for other reasons, the request will not obtain a RequestId). RequestId is required for locating a problem.

    4. Example

    Example1 Clipping an HLS video (with negative offsets)

    This example shows you how to clip a video that starts at two seconds from the beginning of the original video and ends ten seconds from the end of the original video.

    Input Example

    POST / HTTP/1.1
    Host: vod.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: SimpleHlsClip
    <Common request parameters>
    
    {
        "Url": "http://xxxxx.vod2.myqcloud.com/xxxxx/aaaaaa/hhhh.m3u8",
        "StartTimeOffset": 2.0,
        "EndTimeOffset": 10.0
    }
    

    Output Example

    {
        "Response": {
            "Url": "http://xxxxx.vod2.myqcloud.com/xxxxx/aaaaaa/10_50.m3u8",
            "FileId": "",
            "TaskId": "",
            "MetaData": {
                "Size": 0,
                "Container": "hls",
                "Bitrate": 622014,
                "Height": 480,
                "Width": 640,
                "Duration": 48.0,
                "Rotate": 0,
                "VideoStreamSet": [
                    {
                        "Bitrate": 592385,
                        "Height": 480,
                        "Width": 640,
                        "Codec": "h264",
                        "Fps": 25,
                        "CodecTag": "",
                        "DynamicRangeInfo": {
                            "Type": "",
                            "HDRType": ""
                        }
                    }
                ],
                "AudioStreamSet": [
                    {
                        "Bitrate": 29629,
                        "SamplingRate": 44100,
                        "Codec": "aac"
                    }
                ],
                "VideoDuration": 0.0,
                "AudioDuration": 0.0,
                "Md5": "Md5"
            },
            "RequestId": "12ae8d8e-dce3-4151-9d4b-5594145287e1"
        }
    }
    

    Example2 Clipping an HLS video (with positive offsets)

    This example shows you how to clip a video from 00:02 to 00:10.

    Input Example

    POST / HTTP/1.1
    Host: vod.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: SimpleHlsClip
    <Common request parameters>
    
    {
        "Url": "http://xxxxx.vod2.myqcloud.com/xxxxx/aaaaaa/hhh.m3u8",
        "StartTimeOffset": 2.0,
        "EndTimeOffset": 10.0
    }
    

    Output Example

    {
        "Response": {
            "Url": "http://xxxxx.vod2.myqcloud.com/xxxxx/aaaaaa/10_50.m3u8",
            "FileId": "",
            "TaskId": "",
            "MetaData": {
                "Size": 0,
                "Container": "hls",
                "Bitrate": 622014,
                "Height": 480,
                "Width": 640,
                "Duration": 48.0,
                "Rotate": 0,
                "VideoStreamSet": [
                    {
                        "Bitrate": 592385,
                        "Height": 480,
                        "Width": 640,
                        "Codec": "h264",
                        "Fps": 25,
                        "CodecTag": "",
                        "DynamicRangeInfo": {
                            "Type": "",
                            "HDRType": ""
                        }
                    }
                ],
                "AudioStreamSet": [
                    {
                        "Bitrate": 29629,
                        "SamplingRate": 44100,
                        "Codec": "aac"
                    }
                ],
                "VideoDuration": 0.0,
                "AudioDuration": 0.0,
                "Md5": "Md5"
            },
            "RequestId": "12ae8d8e-dce3-4151-9d4b-5594145287e1"
        }
    }
    

    5. Developer Resources

    SDK

    TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

    Command Line Interface

    6. Error Code

    The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

    Error Code Description
    FailedOperation Operation failed.
    FailedOperation.InvalidVodUser The VOD service is not activated.
    InternalError Internal error.
    InvalidParameterValue Incorrect parameter value.
    InvalidParameterValue.EndTimeOffset Incorrect parameter: the end time is invalid.
    InvalidParameterValue.ExpireTime Incorrect parameter value: incorrect ExpireTime format.
    InvalidParameterValue.IsPersistence
    InvalidParameterValue.OutputMediaType
    InvalidParameterValue.Precision
    InvalidParameterValue.Procedure
    InvalidParameterValue.StartTimeOffset Incorrect parameter: the start time is invalid.
    InvalidParameterValue.Url Incorrect parameter: the URL is invalid.
    ResourceUnavailable.MasterPlaylist Incorrect parameter: M3U8 of MasterPlaylist is not supported.
    UnauthorizedOperation Unauthorized operation.