This topic describes how to merge multiple videos, split a video and retain the start, middle, or end part, and merge parts of multiple videos. Videos are split and merged based on timeline data.

Overview

You can call the ProduceEditingProjectVideo operation to merge videos. The timeline data is essential in video editing. For more information about video editing and merging, see Overview. You can configure the parameters of the timeline in different ways based on your requirements.

Merge videos

You can merge multiple videos in sequence without the need to specify the start or end time. Sample code:

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

Split a video and retain the start part

If you want to split a video and retain the start part of the video, specify only the end time. The following sample code provides an example on how to extract the first 5 seconds of a video:

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

Split a video and retain the end part

If you want to split a video and retain the end part of the video, specify only the start time. The following sample code provides an example on how to extract the last 10 seconds of a video:

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

Split a video and retain the middle part

If you want to split a video and retain the middle part of the video, specify the start time and end time. Sample code:

Important
  • In indicates the start time and Out indicates the end time. The end time must be later than the start time. Otherwise, an error occurs.
  • If the value of Out exceeds the video duration, the end time of the video is used as the Out value.
{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "MediaId": "4bcf9b4d7cf14dc7b83b0e801cbe****",
                    "In": 5,
                    "Out": 10
                }
            ]
        }
    ]
}

Split videos and merge multiple video parts

You can extract multiple parts from multiple videos and merge the extracted parts. The following sample code provides an example on how to merge two parts of 4bcf9b4d7cf14dc7b83b0e801cbe**** and one part of 789f9b4d7cf14dc7b83b0e801cbe**** based on the order of the array in sequence:

Note In indicates the start time and Out indicates the end time. The end time must be later than the start time. 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

You can add images to a video track and specify the points in time at which the images appear and disappear. This way, you can embed images in the video that you produce. Sample code:

{
    "VideoTracks": [
        {
            "VideoTrackClips": [
                {
                    "Type":"Image",
                    "MediaId": "f744464b37944244bf03f744c5ab****",
                    "TimelineIn":0,
                    "TimelineOut": "5.0000"
                },{
                    "MediaId": "0e809b4d7cf14dc7b83b0e801cbe****"
                },{
                    "Type":"Image",
                    "MediaId": "f744464b37944244bf03f744c5ab****",
                    "Duration":5
                }
            ]
        }
    ]
}
Note
  • If you want to add an image to a video track, specify Type="Image".
  • If you set TimelineIn to 0 and TimelineOut to 5.0000, the image appears at the beginning of the output video and disappears after 5 seconds.
  • If you set Duration to 5, the image is displayed for 5 seconds.