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 eventsmTXVideoJoiner.setVideoJoinerListener(new TXVideoJoinerListener() {@Overridepublic void onJoinProgress(float progress) {}@Overridepublic 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 eventsmTXVideoJoiner.setTXVideoPreviewListener(new TXVideoPreviewListener() {@Overridepublic void onPreviewProgress(int time) {}@Overridepublic void onPreviewFinished() {}});// Prepare the preview ViewTXVideoEditConstants.TXPreviewParam param = new TXVideoEditConstants.TXPreviewParam();param.videoView = mVideoView;param.renderMode = TXVideoEditConstants.PREVIEW_RENDER_MODE_FILL_EDGE;mTXVideoJoiner.initWithPreview(param);// Start previewmTXVideoJoiner.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 eventsmTXVideoJoiner.setVideoJoinerListener(new TXVideoJoinerListener() {@Overridepublic void onJoinProgress(float progress) {}@Overridepublic void onJoinComplete(TXJoinerResult result) {}});// Set the visual parameters for the combined performanceSplitScreenParam splitScreenParam = new SplitScreenParam();splitScreenParam.canvasWidth = 720; // Width of the combined performance framesplitScreenParam.canvasHeight = 1280; // Height of the combined performance framesplitScreenParam.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 screenTXAbsoluteRect 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-performanceList<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.