The short video SDK provides the video merging class AliyunIMixComposer. You can call this class to merge multiple videos into a single one offline. The merged video can be arranged in a specified layout, such as picture-in-picture, nine-square grid, left-right split-screen, or up-down split-screen. Multiple video tracks can be added for video merging. This topic describes how to use the short video SDK for iOS to merge videos. This topic also provides sample code for video merging.
Supported editions
Edition | Supported |
---|---|
Professional | Yes |
Standard | Yes |
Basic | No |
Related classes
Class | Description |
---|---|
AliyunMixComposer | The core class for merging. You can implement this class to merge multiple videos on the same screen in different layouts such as left-right split-screen, picture-in-picture, and nine-square grid. You can also implement this class to join the playback of two involved videos on the same screen. |
AliyunMixTrack | The class that defines tracks for video merging. A video track for video merging can be created by using the AliyunMixComposer class. You can add video streams to video tracks. |
AliyunMixStream | The class that is used to merge video streams and add the output to the video track. |
AliyunPureColorBorderInfo | The class that defines the border information of the track stream. |
Merging process
Configuration | Step | Description | Sample code |
---|---|---|---|
Basic | 1 | Create a merging instance and configure callbacks. | Initialization |
2 | Create multiple tracks and video streams, and then add the video streams to the tracks separately. | Create tracks | |
3 | Configure parameters such as the output path, and the width and height of the merged video. | Configure output parameters | |
4 | Configure callbacks and start merging. | Start merging | |
Advanced | 5 | Configure the cancel, pause, and continue features as needed. | Control of video merging |
Initialization
Create a merging instance and configure callbacks. For more information about the parameters that are used in the code, see Related classes.
// Create an AliyunMixComposer object.
AliyunMixComposer *mixComposer = [[AliyunMixComposer alloc] init];
// Configure callbacks.
mixComposer.delegate = self;
Create tracks
Create multiple tracks and video streams, and then add the video streams to the tracks separately. For more information about the parameters that are used in the code, see Related classes.
// Add a track on the left.
AliyunMixTrack *recordTrack = [mixComposer createTrack:CGRectMake(0,0,360,720)];
// Add a track on the right.
AliyunMixTrack *playerTrack = [mixComposer createTrack:CGRectMake(360,0,360,720)];
// Configure track parameters.
// Specify the track of the audio output.
recordTrack.outputAudioReferenceTrack = YES;
// Specify the proportion of the audio output.
recordTrack.outputAudioWeight = 100;
// Specify the duration of the track as the output video.
recordTrack.outputDurationReferenceTrack = YES;
// Set the border of the track.
AliyunPureColorBorderInfo *info = [[AliyunPureColorBorderInfo alloc] init];
info.width = 10.f;
info.cornerRadius = 10.f;
info.color = [UIColor redColor];
recordTrack.borderInfo = info;
// Add a video stream to the left track.
AliyunMixStream *recordStream = [[AliyunMixStream alloc] init];
recordStream.filePath = videoPath;
recordStream.mode = AlivcContentModeScaleAspectFit;
[recordTrack addStream:recordStream];
// Add a video stream to the right track.
AliyunMixStream *playerStream = [[AliyunMixStream alloc] init];
playerStream.filePath = mixVideoFilePath;
playerStream.mode = AlivcContentModeScaleAspectFit;
[playerTrack addStream:playerStream];
Configure output parameters
Configure parameters such as the output path, and the width and height of the merged video. For more information about the parameters that are used in the code, see Related classes.
// Specify the output path.
mixComposer.outputPath = self.outputPath;
// Specify the output resolution.
mixComposer.outputSize = CGSizeMake(720,720);
// Specify the output frame rate.
mixComposer.fps = 30;
// Specify the keyframe interval.
mixComposer.gop = 90;
// Specify the video quality.
mixComposer.videoQuality = AliyunVideoQualityHight;
Start merging
Start merging videos and configure callbacks. For more information about the parameters that are used in the code, see Related classes.
// Start merging.
[mixComposer start];
// Configure callbacks.
// Merging progress
- (void)mixComposerOnProgress:(float)progress {
}
// The merging is complete.
- (void)mixComposerDidComplete {
}
// An error occurred during merging.
- (void)mixComposerDidError:(int)error {
}
Control of video merging
Configure the cancel, pause, and continue features as needed. For more information about the parameters that are used in the code, see Related classes.
// Pause the merging.
[mixComposer pause];
// Continue the merging.
[mixComposer resume];
// Cancel the merging.
[mixComposer cancel];