ComposeMedia

Last updated: 2020-09-17 17:55:32

1. API Description

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

This API is used to compose a media file, including:

  1. Clipping a media file to generate a new media file;
  2. Clipping and splicing multiple media files to generate a new media file;
  3. Clipping and splicing the media streams of multiple media files to generate a new media file;

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 parameter. The value used for this API: ComposeMedia.
Version Yes String Common parameter. The value used for this API: 2018-07-17.
Region No String Common parameter. This parameter is not required for this API.
Tracks.N Yes Array of MediaTrack List of input media tracks, i.e., information of multiple tracks composed of video, audio, image, and other materials. Multiple input tracks are aligned with the output media file on the time axis. The materials of each track at the same time point on the time axis will be superimposed. Specifically, videos or images will be superimposed for video image by track order, where a material with a higher track order will be more on top, while audio materials will be mixed.
Output Yes ComposeMediaOutput Information of output media file.
Canvas No Canvas Canvas used for composing video file.
SessionContext No String This parameter is used to pass through user request information. ComposeMediaComplete callback will return the value of this field. It contains up to 1,000 characters.
SessionId No String This parameter is 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 null or an empty string, the above operation will not be performed.
SubAppId No Integer Subapplication ID in VOD. If you need to access a resource in a subapplication, enter the subapplication ID in this field; otherwise, leave it empty.

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 Clipping and splicing two video streams

This example shows you how to take the 2nd to 62nd seconds of 5285485487985271487 and the 6th to 81st seconds of 5285485487985271488 for splicing, set a fade-in/fade-out transition of 5 seconds in between, and paste image 5285485487985271489 with width and height of (100px, 100px) between the 3rd and 18th seconds of the video at the position of (20px, 20px).

Input Example

https://vod.tencentcloudapi.com/?Action=ComposeMedia
&Tracks.0.Type=Video
&Tracks.0.TrackItems.0.Type=Video
&Tracks.0.TrackItems.0.VideoItem.SourceMedia=5285485487985271487
&Tracks.0.TrackItems.0.VideoItem.SourceMediaStartTime=2
&Tracks.0.TrackItems.0.VideoItem.Duration=60
&Tracks.0.TrackItems.1.Type=Transition
&Tracks.0.TrackItems.1.TransitionItem.Duration=5
&Tracks.0.TrackItems.1.TransitionItem.TransitionOperations.0.Type=ImageFadeInFadeOut
&Tracks.0.TrackItems.2.Type=Video
&Tracks.0.TrackItems.2.VideoItem.SourceMedia=5285485487985271488
&Tracks.0.TrackItems.2.VideoItem.SourceMediaStartTime=6
&Tracks.0.TrackItems.2.VideoItem.Duration=75
&Tracks.1.Type=Sticker
&Tracks.1.TrackItems.0.Type=Sticker
&Tracks.1.TrackItems.0.StickerItem.SourceMedia=5285485487985271489
&Tracks.1.TrackItems.0.StickerItem.StartTime=3
&Tracks.1.TrackItems.0.StickerItem.Duration=15
&Tracks.1.TrackItems.0.StickerItem.CoordinateOrigin=TopLeft
&Tracks.1.TrackItems.0.StickerItem.XPos=20px
&Tracks.1.TrackItems.0.StickerItem.YPos=20px
&Tracks.1.TrackItems.0.StickerItem.Width=100px
&Tracks.1.TrackItems.0.StickerItem.Height=100px
&Output.FileName=test
&Output.Container=mp4
&<Common request parameters>

Output Example

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

Example2 Dubbing a VOD video

This example shows you how to remove the original audio from 5285485487985271487, dub it starting from the 5th second with 5285485487985271488, and dub it starting from the 20th second with the 2nd to 16th seconds of 5285485487985271489 to generate a new VOD video.

Input Example

https://vod.tencentcloudapi.com/?Action=ComposeMedia
&Tracks.0.Type=Video
&Tracks.0.TrackItems.0.Type=Video
&Tracks.0.TrackItems.0.VideoItem.SourceMedia=5285485487985271487
&Tracks.0.TrackItems.0.VideoItem.AudioOperations.0.Type=Volume
&Tracks.0.TrackItems.0.VideoItem.AudioOperations.0.VolumeParam.Mute=1
&Tracks.1.Type=Audio
&Tracks.1.TrackItems.0.Type=Empty
&Tracks.1.TrackItems.0.EmptyItem.Duration=5
&Tracks.1.TrackItems.1.Type=Audio
&Tracks.1.TrackItems.1.AudioItem.SourceMedia=5285485487985271488
&Tracks.1.TrackItems.1.AudioItem.Duratiion=15
&Tracks.1.TrackItems.2.Type=Audio
&Tracks.1.TrackItems.2.AudioItem.SourceMedia=5285485487985271489
&Tracks.1.TrackItems.2.AudioItem.SourceMediaStartTime=2
&Tracks.1.TrackItems.2.AudioItem.Duration=14
&Output.FileName=test
&Output.Container=mp4
&<Common request parameters>

Output Example

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

Example3 Playing two videos in picture-in-picture mode

This example shows you how to play the 5285485487985271487 video as the primary image and the 5285485487985271488 video as the small image in picture-in-picture mode. The small image is displayed in the lower right corner of the primary image with their centers offset by 25%, and the width of the small image is 30% of that of the primary image.

Input Example

https://vod.tencentcloudapi.com/?Action=ComposeMedia
&Tracks.0.Type=Video
&Tracks.0.TrackItems.0.Type=Video
&Tracks.0.TrackItems.0.VideoItem.SourceMedia=5285485487985271487
&Tracks.1.Type=Video
&Tracks.1.TrackItems.0.Type=Video
&Tracks.1.TrackItems.0.VideoItem.SourceMedia=5285485487985271488
&Tracks.1.TrackItems.0.VideoItem.CoordinateOrigin=Center
&Tracks.1.TrackItems.0.VideoItem.XPos=25%
&Tracks.1.TrackItems.0.VideoItem.YPos=25%
&Tracks.1.TrackItems.0.VideoItem.Width=30%
&Output.FileName=test
&Output.Container=mp4
&<Common request parameters>

Output Example

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

5. Developer Resources

API Explorer

This tool allows online call, signature authentication, SDK code generation and quick search of APIs to greatly improve the efficiency of using TencentCloud APIs.

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.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.
UnauthorizedOperation Unauthorized operation.

Was this page helpful?

Was this page helpful?

  • Not at all
  • Not very helpful
  • Somewhat helpful
  • Very helpful
  • Extremely helpful
Send Feedback
Help