tencent cloud

Last updated: 2025-04-01 17:14:08
iOS
Last updated: 2025-04-01 17:14:08
The TXVideoJoiner can merge multiple videos either by sequentially concatenating them or by combining their frames in a split-screen layout.

1. Basic Video Concatenation

To simply concatenate multiple video files sequentially, refer to the following code:
// Create TXVideoJoiner (nil for preview param indicates no preview needed)
TXVideoJoiner* _videoJoin = [[TXVideoJoiner alloc] initWithPreview:nil];

// Set video files to concatenate (_composeArray)
[_videoJoin setVideoPathList:_composeArray];

// Set delegate for progress/completion callbacks
_videoJoin.joinerDelegate = self;

// Start merging (540p compressed output)
[_videoJoin joinVideo:VIDEO_COMPRESSED_540P videoOutputPath:_outFilePath];

2. Preview Before Concatenation

To preview the concatenated videos before merging, use the following code:
// Configure preview view
TXPreviewParam *param = [[TXPreviewParam alloc] init];
param.videoView = _videoPreview.renderView;
param.renderMode = PREVIEW_RENDER_MODE_FILL_EDGE;

// Create TXVideoJoiner with preview
TXVideoJoiner* _videoJoin = [[TXVideoJoiner alloc] initWithPreview:param];
_videoJoin.previewDelegate = _videoPreview;

// Set video files
[_videoJoin setVideoPathList:_composeArray];

// Start preview playback
[_videoJoin startPlay];

Control playback with:

startPlay: Start preview
pausePlay: Pause preview
resumePlay: Resume preview

3. Split-Screen Video Merging

TXVideoJoiner also supports merging multiple videos into a split-screen layout. Example code:
TXVideoJoiner* _videoJoin = [[TXVideoJoiner alloc] initWithPreview:nil];
[_videoJoin setVideoPathList:_composeArray];
_videoJoin.joinerDelegate = self;

// Configure split-screen layout
TXSplitScreenParams* splitScreenParams = [[TXSplitScreenParams alloc] init];
splitScreenParams.canvasWidth = 720 * 2; // Total output width
splitScreenParams.canvasHeight = 1280; // Total output height

// Define positions for each video
splitScreenParams.rects = @[
[NSValue valueWithCGRect:CGRectMake(0, 0, splitScreenParams.canvasWidth/2, splitScreenParams.canvasHeight)],
[NSValue valueWithCGRect:CGRectMake(splitScreenParams.canvasWidth/2, 0, splitScreenParams.canvasWidth/2, splitScreenParams.canvasHeight)]
];

splitScreenParams.durationMode = ALIGNS_TO_LONGEST; // Duration matches longest input
[_videoJoiner setSplitScreenList:splitScreenParams];

// Set audio mix ratios (0: muted, 1: full volume)
[_videoJoiner setVideoVolumes:@[@0, @1]];

// Start merging
[_videoJoin joinVideo:VIDEO_COMPRESSED_540P videoOutputPath:_outFilePath];
When configuring split-screen layout parameters via setSplitScreenList and audio mixing ratios via setVideoVolumes, these settings apply to ​both the final video output (generated by splitJoinVideo) ​andthe live preview during editing.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback