The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.
Help & Documentation>User Generated Short Video SDK

Android

Last updated: 2025-03-17 17:50:37

If there are multiple videos to be spliced into one video, TXVideoJoiner can be used. Multiple videos can be spliced into one video one after another, or spliced by overlaying multiple video screens.

Basic Splicing Feature

If you just want to simply splice multiple video files into one video file one after another, please refer to the following code:

mTXVideoJoiner = new TXVideoJoiner(mContext);

// Set the video source. A return value < 0 indicates errors present in the raw file or unsupported format.
if (mTXVideoJoiner.setVideoPathList(videoSourceList) < 0) {
return
}

// Set callback to listen for merge progress and merge completion events
mTXVideoJoiner.setVideoJoinerListener(new TXVideoJoinerListener() {
@Override
public void onJoinProgress(float progress) {}

@Override
public void onJoinComplete(TXJoinerResult result) {}
});

// Start merging. Parameter passing includes the resolution of the merged video and the output path.
// If the file formats and resolutions of multiple merged videos are consistent, the video merge can be quickly completed. If they are inconsistent, re-encoding is required and the merge speed will be slower.
mTXVideoJoiner.joinVideo(TXVideoEditConstants.VIDEO_COMPRESSED_540P, mOutputPath);

2. Preview the Spliced File

If you want to preview the videos to be merged before merging them, you can refer to the following code:
mTXVideoJoiner = new TXVideoJoiner(mContext);

// Set the video source. A return value < 0 indicates errors present in the raw file or unsupported format.
if (mTXVideoJoiner.setVideoPathList(videoSourceList) < 0) {
return
}

// Set callback to listen for preview progress and preview completion events
mTXVideoJoiner.setTXVideoPreviewListener(new TXVideoPreviewListener() {
@Override
public void onPreviewProgress(int time) {}

@Override
public void onPreviewFinished() {}
});

// Prepare the preview View
TXVideoEditConstants.TXPreviewParam param = new TXVideoEditConstants.TXPreviewParam();
param.videoView = mVideoView;
param.renderMode = TXVideoEditConstants.PREVIEW_RENDER_MODE_FILL_EDGE;
mTXVideoJoiner.initWithPreview(param);

// Start preview
mTXVideoJoiner.startPlay();
The synthesis module provides a group of APIs for video play preview:
startPlay: indicates the playback start of the video.
pausePlay: indicates the video play pause.
resumePlay: indicates the video playback recovery.

3. Video Co - Performance

TXVideoJoiner not only supports splicing multiple videos one after another, but also supports splicing by combining multiple video frames. Please refer to the following code:

mTXVideoJoiner = new TXVideoJoiner(mContext);

// Set the video source. A return value < 0 indicates errors present in the raw file or unsupported format.
if (mTXVideoJoiner.setVideoPathList(videoSourceList) < 0) {
return
}

// Set callback to listen for merge progress and merge completion events
mTXVideoJoiner.setVideoJoinerListener(new TXVideoJoinerListener() {
@Override
public void onJoinProgress(float progress) {}

@Override
public void onJoinComplete(TXJoinerResult result) {}
});

// Set the visual parameters for the combined performance
SplitScreenParam splitScreenParam = new SplitScreenParam();
splitScreenParam.canvasWidth = 720; // Width of the combined performance frame
splitScreenParam.canvasHeight = 1280; // Height of the combined performance frame
splitScreenParam.durationControlMode = DurationControlMode.ALIGNS_TO_LONGEST; // Align the length of the combined video with the longest video
// Used to specify the location and sizes of each video on the screen
TXAbsoluteRect rect1 = new TXAbsoluteRect();
TXAbsoluteRect rect2 = new TXAbsoluteRect();
splitScreenParam.rects.add(rect1);
splitScreenParam.rects.add(rect2);
mTXVideoJoiner.setSplitScreenList(splitScreenParam);

// Set the proportion of each video and audio when mixing in co-performance
List<Float> volumes = new LinkedList<>();
volumes.add(1.0f);
volumes.add(0.0f);
mTXVideoJoiner.setVideoVolumes(volumes);

// Start merging. Parameter passing includes the resolution of the merged video and the output path.
// If the file formats and resolutions of multiple merged videos are consistent, the video merge can be quickly completed. If they are inconsistent, re-encoding is required and the merge speed will be slower.
mTXVideoJoiner.splitJoinVideo(TXVideoEditConstants.VIDEO_COMPRESSED_540P, mOutputPath);
After we set the visual parameters and audio mixing volume for co-performance by calling setSplitScreenList and setVideoVolumes, it takes effect not only on generating videos by calling splitJoinVideo, but also on video preview.