tencent cloud

文档反馈

ComposeMedia

最后更新时间:2022-08-23 16:02:40

1. API Description

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

This API is used to compose a media file. You can use it to do the following:

  1. Rotation/Flipping: Rotate a video or image by a specific angle or flip a video or image.
  2. Audio control: Increase/Lower the volume of an audio/video file or mute an audio/video file.
  3. Overlaying: Overlay videos/images in a specified sequence to achieve the picture-in-picture effect.
  4. Audio mixing: Mix the audios of audio/video files.
    5 Audio extraction: Extract audio from a video.
  5. Clipping: Clip segments from audio/video files according to a specified start and end time.
  6. Splicing: Splice videos/audios/images in a specified sequence.
  7. Transition: Add transition effects between video segments or images that are spliced together.

The output file is in MP4 or MP3 format. In the callback for media composition, the event type is ComposeMediaComplete.

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: ComposeMedia.
Version Yes String Common Params. The value used for this API: 2018-07-17.
Region No String Common Params. This parameter is not required for this API.
Tracks.N Yes Array of MediaTrack List of input media tracks, including video, audio, and image tracks.
  • Input tracks are synced to the output media file.
  • Input tracks are synced to each other. Videos and images in higher tracks are superimposed over those in lower tracks. Audio tracks are mixed.
  • There can be up to 10 tracks for video, audio, and images each.
  • The total number of clips in all tracks cannot exceed 500.
  • Output Yes ComposeMediaOutput Information of output media file.
    SubAppId No Integer The VOD subapplication ID. If you need to access a resource in a subapplication, set this parameter to the subapplication ID; otherwise, leave it empty.
    Canvas No Canvas Canvas used for composing video file.
    SessionContext No String Used to pass through user request information. ComposeMediaComplete callback will return the value of this parameter. It contains up to 1,000 characters.
    SessionId No String Used to identify duplicate requests. After you send a request, if any request with the same SessionId has already been sent in the last three days (72 hours), an error message will be returned. SessionId contains up to 50 characters. If this parameter is not carried or is an empty string, no deduplication will be performed.

    3. Output Parameters

    Parameter Name Type Description
    TaskId String Media file composing task ID, which can be used to query the status of composing task (with task type being MakeMedia).
    RequestId String The unique request ID, which is returned for each request. RequestId is required for locating a problem.

    4. Example

    Example1 Dubbing a VOD video

    This example shows you how to remove the original audio from the video track 5285485487985271487 and dub the video with two other audio tracks, generating a new VOD file. The video starting from 00:05 is dubbed with the audio track 5285485487985271488. The video starting from second 00:20 is dubbed with the audio from 00:02 to 00:16 of the audio track 5285485487985271489.

    Input Example

    POST / HTTP/1.1
    Host: vod.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: ComposeMedia
    <Common request parameters>
    
    {
        "Output": {
            "Container": "mp4",
            "FileName": "test"
        },
        "Tracks": [
            {
                "TrackItems": [
                    {
                        "AudioItem": {
                            "SourceMedia": "5285485487985271488"
                        },
                        "Type": "Audio"
                    },
                    {
                        "Type": "Empty",
                        "EmptyItem": {
                            "Duration": "5"
                        }
                    },
                    {
                        "AudioItem": {
                            "Duration": "14",
                            "SourceMedia": "5285485487985271489",
                            "SourceMediaStartTime": "2"
                        },
                        "Type": "Audio"
                    }
                ],
                "Type": "Audio"
            },
            {
                "TrackItems": [
                    {
                        "Type": "Video",
                        "VideoItem": {
                            "SourceMedia": "5285485487985271487",
                            "AudioOperations": [
                                {
                                    "VolumeParam": {
                                        "Mute": "1"
                                    },
                                    "Type": "Volume"
                                }
                            ]
                        }
                    }
                ],
                "Type": "Video"
            }
        ]
    }
    

    Output Example

    {
        "Response": {
            "RequestId": "6ca31e3a-6b8e-4b4e-9256-fdc700064ef3",
            "TaskId": "125xxx65-ComposeMedia-bffb15f07530b57bc1aabb01fac74bca"
        }
    }
    

    Example2 Clipping segments from two videos and splicing them

    This example shows you how to splice two videos together. A section of the video 5285485487985271487 from 00:02 to 01:02 is spliced together with a section of the video 5285485487985271488 from 00:06 to 01:21, with a fade-in/fade-out transition of 5 seconds between the video sections. The image 5285485487985271489 is added to the video from 00:03 to 00:18 at the position of (20 px, 20 px). The width and height of the image displayed on the video are (100 px, 100 px).

    Input Example

    POST / HTTP/1.1
    Host: vod.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: ComposeMedia
    <Common request parameters>
    
    {
        "Output": {
            "Container": "mp4",
            "FileName": "test"
        },
        "Tracks": [
            {
                "TrackItems": [
                    {
                        "StickerItem": {
                            "CoordinateOrigin": "TopLeft",
                            "XPos": "20px",
                            "YPos": "20px",
                            "Height": "100px",
                            "Width": "100px",
                            "StartTime": "3",
                            "Duration": "15",
                            "SourceMedia": "5285485487985271489"
                        },
                        "Type": "Sticker"
                    }
                ],
                "Type": "Sticker"
            },
            {
                "TrackItems": [
                    {
                        "TransitionItem": {
                            "Duration": "5"
                        },
                        "Type": "Transition"
                    },
                    {
                        "Type": "Video",
                        "VideoItem": {
                            "Duration": "60",
                            "SourceMedia": "5285485487985271487",
                            "SourceMediaStartTime": "2"
                        }
                    },
                    {
                        "Type": "Video",
                        "VideoItem": {
                            "Duration": "75",
                            "SourceMedia": "5285485487985271488",
                            "SourceMediaStartTime": "6"
                        }
                    }
                ],
                "Type": "Video"
            }
        ]
    }
    

    Output Example

    {
        "Response": {
            "RequestId": "6ca31e3a-6b8e-4b4e-9256-fdc700064ef3",
            "TaskId": "125xxx65-ComposeMedia-bffb15f07530b57bc1aabb01fac74bc2"
        }
    }
    

    Example3 Playing two videos in picture-in-picture mode

    This example shows you how to display two videos in picture-in-picture mode. The video 5285485487985271487 is used as the primary video, and the video 5285485487985271488 is used as the subvideo. The centers of the videos are offset by 25% (i.e., the subvideo is displayed in the bottom-right corner of the primary video), and the width of the subvideo image is set to 30% of the primary video image.

    Input Example

    POST / HTTP/1.1
    Host: vod.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: ComposeMedia
    <Common request parameters>
    
    {
        "Output": {
            "Container": "mp4",
            "FileName": "test"
        },
        "Tracks": [
            {
                "TrackItems": [
                    {
                        "Type": "Video",
                        "VideoItem": {
                            "CoordinateOrigin": "Center",
                            "Width": "30%",
                            "SourceMedia": "5285485487985271488",
                            "XPos": "25%",
                            "YPos": "25%"
                        }
                    }
                ],
                "Type": "Video"
            },
            {
                "TrackItems": [
                    {
                        "Type": "Video",
                        "VideoItem": {
                            "SourceMedia": "5285485487985271487"
                        }
                    }
                ],
                "Type": "Video"
            }
        ]
    }
    

    Output Example

    {
        "Response": {
            "RequestId": "6ca31e3a-6b8e-4b4e-9256-fdc700064ef3",
            "TaskId": "125xxx65-ComposeMedia-bffb15f07530b57bc1aabb01fac74bca"
        }
    }
    

    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.
    FailedOperation.UploadCosFail Operation failed: failed to upload file to COS.
    InternalError Internal error.
    InternalError.GetFileInfoError Internal error: an error occurred while getting media file information.
    InternalError.GetMediaListError Internal error: an error occurred while getting the media list.
    InvalidParameter Invalid parameter.
    InvalidParameterValue.ClipDuration Incorrect parameter value: the clipping duration is too long.
    InvalidParameterValue.SessionContextTooLong SessionContext is too long.
    InvalidParameterValue.SessionId The deduplication ID already exists. The request is removed due to duplication.
    UnauthorizedOperation Unauthorized operation.
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持