Splitting and merging

更新时间:
复制 MD 格式

You can use ApsaraVideo VOD API to split and merge videos based on timeline configurations. Common scenarios include merging full videos, retaining the start, middle, or end part of a video, and merging parts from multiple videos.

Related API operations

Sample timeline configurations

Merge videos

To merge multiple videos in sequence, add them to the timeline without specifying the start or end time. Sample code:

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaId": "4bcf9b4d7cf14dc7b83b0e801cbe****"
                },
                {
                    "MediaId": "789f9b4d7cf14dc7b83b0e801cbe****"
                }
            ]
        }
    ]
}

Split a video and retain the start part

To retain the start part of a video, specify only the end time. The following example extracts the first 5 seconds of a video:

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaId": "4bcf9b4d7cf14dc7b83b0e801cbe****",
                    "Out": 5
                }
            ]
        }
    ]
}

Split a video and retain the end part

To retain the end part of a video, specify only the start time. The following example extracts the last 10 seconds of a video:

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaId": "4bcf9b4d7cf14dc7b83b0e801cbe****",
                    "In": 10
                }
            ]
        }
    ]
}

Split a video and retain the middle part

To retain the middle part of a video, specify both the start time and end time. Sample code:

Important
  • In specifies the start time and Out specifies the end time. The value of Out must be greater than In. Otherwise, an error occurs.

  • If Out exceeds the video duration, the actual end time of the video is used.

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaId": "4bcf9b4d7cf14dc7b83b0e801cbe****",
                    "In": 5,
                    "Out": 10
                }
            ]
        }
    ]
}

Split videos and merge multiple video parts

Extract and merge parts from multiple videos. The following example merges two parts of 4bcf9b4d7cf14dc7b83b0e801cbe**** and one part of 789f9b4d7cf14dc7b83b0e801cbe**** in the specified order:

Note

In specifies the start time and Out specifies the end time. The value of Out must be greater than In. Otherwise, an error occurs.

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaId": "4bcf9b4d7cf14dc7b83b0e801cbe****",
                    "In": 12,
                    "Out": 16
                },{
                    "MediaId": "4bcf9b4d7cf14dc7b83b0e801cbe****",
                    "In": 4,
                    "Out": 7
                },{
                    "MediaId": "789f9b4d7cf14dc7b83b0e801cbe****",
                    "In": 12,
                    "Out": 20
                }
            ]
        }
    ]
}

Edit images in the video track

Add images to a video track and control when they appear and disappear in the output video. Sample code:

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "Type":"Image",
                    "MediaId": "f744464b37944244bf03f744c5ab****",
                    "TimelineIn":0,
                    "TimelineOut": "5.0000"
                },{
                    "MediaId": "0e809b4d7cf14dc7b83b0e801cbe****"
                },{
                    "Type":"Image",
                    "MediaId": "f744464b37944244bf03f744c5ab****",
                    "Duration":5
                }
            ]
        }
    ]
}
Note
  • To add an image to a video track, set Type="Image".

  • Setting TimelineIn to 0 and TimelineOut to 5.0000 makes the image appear at the beginning of the output video and disappear after 5 seconds.

  • Setting Duration to 5 displays the image for 5 seconds.