If you want to add start and end parts to a video, merge the clips of recorded live streams, or extract clips from a video, you can use the video merging and clipping features provided by ApsaraVideo Media Processing (MPS). The video merging feature allows you to merge multiple videos of different formats, encoding formats, and resolutions into a new video of a specific format, encoding format, and resolution. The video clipping feature allows you to extract a clip from a video and save the clip as a new video. This topic describes how to set merging and clipping in MPS.
Video merging
To merge videos, take note of the following parameters:
The start part to be merged and the Object Storage Service (OSS) bucket in which the start part is stored.
NoteThe Location parameter specifies the region in which the OSS bucket that stores the input file resides. The value of the Location parameter must match the region in which you activate MPS. For example, if the endpoint of your MPS service is mts.cn-hangzhou.aliyuncs.com, you must set the Location parameter to oss-cn-hangzhou.
Take note of the following parameters when you configure a job output:
Video
The information about the output file after video merging, such as the width, height, and bitrate. If the aspect ratios of the videos to be merged, including the start and end parts, differ from the output aspect ratio, the system automatically adds black bars to the images in the output video. We recommend that you prepare versions of different aspect ratios for the start and end parts to ensure that the output file meets your resolution requirements in different scenarios.
MergeList
The list of videos to be merged. The videos are merged in the same sequence as specified in the list. The last video in the list is the end part. You can specify up to five videos, including the start and end parts. To merge more than five videos, specify the
MergeConfigUrl
parameter.NoteYou can specify only one of the
MergeList
andMergeConfigUrl
parameters.Specify the following three parameters for each of the videos to be merged:
MergeURL
The OSS path of the video to be merged.
NoteAll videos to be merged into an output file must reside in the same OSS region as the start part. You cannot merge videos across regions.
Start
The start point in time of the video clip to be merged. Specify this parameter if you want to merge only part of the video into the output file. Default value: 0.
Duration
The length of the video clip to be merged. The length is relative to the start point in time specified by the Start parameter. Specify this parameter if you want to merge only part of the video into the output file. By default, the length is the period from the start point in time specified by the Start parameter to the end of the video.
MergeConfigUrl
The OSS path of the configuration file for the video merging job. The content in the configuration file is in the JSON format. The file content is the same as the value of the
MergeList
parameter.NoteThe videos are merged in the same sequence as specified in the configuration file. The last video specified in the configuration file is the end part. You can specify up to 100 videos, including the start and end parts.
Video clipping
To extract video clips, take note of the following parameters:
The video from which clips are extracted and the OSS bucket in which the video is stored.
NoteThe Location parameter specifies the region in which the OSS bucket that stores the input file resides. The value of the Location parameter must match the region in which you activate MPS. For example, if the endpoint of your MPS service is mts.cn-hangzhou.aliyuncs.com, you must set the Location parameter to oss-cn-hangzhou.
Take note of the following parameters when you configure a job output:
TimeSpan
The time span of the clip to be extracted from the original video. You can specify the start point in time and length of the video clip.
Specify the following three parameters for each of the time span:
Seek
The point in time at which the video clip starts.
Duration
The length of the video clip.
End
The length of the ending part of the original video to be cropped out.
NoteIf you specify this parameter, the Duration parameter becomes invalid.
ConfigToClipFirstPart
Specifies whether to crop the first part of the videos to be merged. A value of true indicates that the first part of the videos is cropped before the videos are merged. A value of false indicates that the videos are merged into an output file, which is then cropped. Default value: false.
Example
Add start and end parts whose resolution is 640 × 480 pixels to a video whose resolution is 1280 × 720 pixels to produce an MP4 video whose resolution is 1280 × 720 pixels. In the output video, black bars are added to the left and right of the start and end parts. The main part is normally displayed.
For information about the sample codes to set merging and clipping by using MPS SDKs for different programming languages, see the following topics: