tencent cloud

User Generated Short Video SDK

Android

Download
Focus Mode
Font Size
Last updated: 2026-05-15 17:33:55

Overview

Video editing supports clipping, time effects (slow motion, reverse, loop), filters (rock light, dark dream, soul out, screen split), filter styles (artistic, rosy, blues, etc.), music mixing, animated stickers, static stickers, bubble subtitles, etc.

Classes

Class
Description
TXVideoInfoReader
Media information obtaining
TXVideoEditer
Video editing

Basic Video Editing Workflow

1. Choose the video path
2. Import your video
3. Apply effects
4. Generate a file of the editing result
5. Listen for the callback for video generation
6. Release the resources

Getting Video Information

You can use getVideoFileInfo of TXVideoInfoReader to obtain some basic video information. Below is a request sample:
/**
* Acquire video information
* @param videoPath Video file path
* @return
*/
public TXVideoEditConstants.TXVideoInfo getVideoFileInfo(String videoPath);
TXVideoInfo is returned and is defined as follows:
public final static class TXVideoInfo {
public Bitmap coverImage; // First video frame
public long duration; // Video duration (ms)
public long fileSize; // Video file size (byte)
public float fps; // Video frame rate (fps)
public int bitrate; // Video bitrate (Kbps)
public int width; // Video width
public int height; // Video height
public int audioSampleRate; // Audio bitrate
}
Below is a complete sample:
//sourcePath Path of the video to edit
String sourcePath = Environment.getExternalStorageDirectory() + File.separator + "temp.mp4";
TXVideoEditConstants.TXVideoInfo info = TXVideoInfoReader.getInstance().getVideoFileInfo(sourcePath);

Getting Thumbnails

The thumbnail obtaining API is used to generate thumbnail preview during video editing or get the cover of a video.

1. Get thumbnails by evenly dividing the timeline based on count

Call the interface as follows:
/**
* Get the thumbnail list
* @param count Number of thumbnails to get
* @param width Thumbnail width
* @param height Thumbnail height
* @param fast Whether to get keyframes
* @param listener Callback API for thumbnail generation
*/
public void getThumbnail(int count, int width, int height, boolean fast, TXThumbnailListener listener)
The @param fast parameter supports two modes:
Quick generation: Pass in true to use this mode, under which thumbnails are generated relatively quickly, but they may not correspond exactly to video frames.
Precise generation: Pass in false to use this mode, under which the thumbnails generated correspond exactly to video frames, but the generation may be slow if the resolution is high.
Below is a complete sample:
mTXVideoEditer.getThumbnail(TCVideoEditerWrapper.mThumbnailCount, 100, 100, false, mThumbnailListener);

private TXVideoEditer.TXThumbnailListener mThumbnailListener = new TXVideoEditer.TXThumbnailListener() {
@Override
public void onThumbnail(int index, long timeMs, final Bitmap bitmap) {
Log.i(TAG, "onThumbnail: index = " + index + ",timeMs:" + timeMs);
// Insert the thumbnails into the image control
}
};

2. Get thumbnails according to the time list


List<Long> list = new ArrayList<>();
list.add(10000L);
list.add(12000L);
list.add(13000L);
list.add(14000L);
list.add(15000L);


mTXVideoEditer.getThumbnail(list, 100, 100, false, mThumbnailListener);

3. Obtain thumbnails during video preprocessing

If you need to support video effects like reverse playback, looping, or other event-based effects, video preprocessing may be required. During preprocessing, thumbnails can be captured directly without additional separate requests.
For details about video preprocessing, refer to the end of this document.
Note:
Timestamps in the list must not exceed the total video duration. For timestamps beyond the duration, the last frame will be returned.
Timestamps are specified in milliseconds (ms).

Preview

You can preview a video during editing in two modes. Time-point preview shows the frame of a certain time point, while time-range preview plays a video segment between two time points on loop (A<=>B). You need to bind the SDK with a UIView to display video images.

1. Configure preview layout

public void initWithPreview(TXVideoEditConstants.TXPreviewParam param)

public final static class TXPreviewParam {
public FrameLayout videoView; // Video preview view
public int renderMode; // Rendering mode
}

// Rendering mode: Completely fill the screen without black borders (may crop part of the video)
public final static int PREVIEW_RENDER_MODE_FILL_SCREEN = 1;

// Rendering mode: Fit the video within the screen (maintains full video but may show black borders)
public final static int PREVIEW_RENDER_MODE_FILL_EDGE = 2;

2. Time-point preview

Preprocessed videos allow precise preview of video frames at specific time points.
public void previewAtTime(long timeMs);

3. Time-range preview

You can use startPlayFromTime of TXVideoEditer to play a video segment between two time points (A<=>B).
// Play a segment of a video from `startTime` to `endTime`
public void startPlayFromTime(long startTime, long endTime);

4. Pause and resume preview

// Pause preview
public void pausePlay();
// Resume preview
public void resumePlay();
// Stop preview
public void stopPlay();

Beauty filter

You can apply filter effects to videos, such as whitening, romantic, fresh, and other filters. The demo provides 16 filter options, and you can also set custom filters.
The method to set a filter is as follows (where ​Bitmap represents the filter mapping bitmap; setting ​bitmap to ​null will clear the filter effect):
void setFilter(Bitmap bmp)
After adding a filter, you can set its intensity using ​specialRatio, which accepts values from ​0 to 9:
void setSpecialRatio(float specialRatio)
You can also set a combined filter, where different filters can be applied to the left and right sides:
leftBitmap is the left filter, leftIntensity is the intensity of the left filter.
rightBitmap is the right filter, rightIntensity is the intensity of the right filter.
leftRatio is the proportion occupied by the left filter, typically ranging from 0.0 to 1.0.
When leftBitmap or rightBitmap is null, the filter effect on that side is cleared.
void setFilter(Bitmap leftBitmap, float leftIntensity, Bitmap rightBitmap,
float rightIntensity, float leftRatio)

Watermark

1. Add a global watermark

You can add a watermark to a specified position of a video.
The method to add a watermark is as follows:
public void setWaterMark(Bitmap waterMark, TXVideoEditConstants.TXRect rect);
waterMark represents the watermark image. rect is the normalized frame of the watermark image in relation to the video image. The value range of x, y, width, and height is 0 to 1.
Demo:
TXVideoEditConstants.TXRect rect = new TXVideoEditConstants.TXRect();
rect.x = 0.5f;
rect.y = 0.5f;
rect.width = 0.5f;
mTXVideoEditer.setWaterMark(mWaterMarkLogo, rect);

2. Set a post-roll watermark

You can add a watermark to the end of a video at the specified location.
The method to add an ending watermark is as follows:
setTailWaterMark(Bitmap tailWaterMark, TXVideoEditConstants.TXRect txRect, int duration);
tailWterMark represents the watermark image. txRect is the normalized frame of the watermark image in relation to the video image, and the value range of x, y, and width in txRect is from 0 to 1. duration indicates for how long (s) the watermark is displayed. Demo: add an ending watermark to the center of a video and show the watermark for 3 seconds
Bitmap tailWaterMarkBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tcloud_logo);
TXVideoEditConstants.TXRect txRect = new TXVideoEditConstants.TXRect();
txRect.x = (mTXVideoInfo.width - tailWaterMarkBitmap.getWidth()) / (2f * mTXVideoInfo.width);
txRect.y = (mTXVideoInfo.height - tailWaterMarkBitmap.getHeight()) / (2f * mTXVideoInfo.height);
txRect.width = tailWaterMarkBitmap.getWidth() / (float) mTXVideoInfo.width;
mTXVideoEditer.setTailWaterMark(tailWaterMarkBitmap, txRect, 3);

Adding BGM During Editing

/**
* Set the BGM file path.
* Returns 0 on success; non-zero values indicate failure (e.g., unsupported audio format).
*/
public int setBGM(String path);

/**
* Set the start and end time of the BGM, in milliseconds.
*/
public void setBGMStartTime(long startTime, long endTime);

/**
* Enable/disable BGM looping:
* true = loop playback, false = play once.
*/
public void setBGMLoop(boolean looping);

/**
* Set the starting position in the video timeline where the BGM will begin playing.
*/
public void setBGMAtVideoTime(long videoStartTime);

/**
* Adjust the original video volume.
* @param volume Volume level (0.0–1.0):
* 0 = mute, 1 = original volume.
*/
public void setVideoVolume(float volume);

/**
* Adjust the BGM volume.
* @param volume Volume level (0.0–1.0):
* 0 = mute, 1 = original volume.
*/
public void setBGMVolume(float volume);


Compression and Clipping

1. Video Compression

To compress a video, use the following APIs:
// ...
// Generate the final video file
public void generateVideo(int videoCompressed, String videoOutputPath)
The ​videoCompressed parameter can be configured using optional constants defined in TXVideoEditConstants.
VIDEO_COMPRESSED_360P ——// Compress to 360p resolution(360*640)
VIDEO_COMPRESSED_480P ——// Compress to 480p(640*480)
VIDEO_COMPRESSED_540P ——// Compress to 540p (960*540)
VIDEO_COMPRESSED_720P ——// Compress to 720p (1280*720)
VIDEO_COMPRESSED_1080P ——// Compress to 1080p (1920*1080)
If the source video's resolution is ​lower than the selected constant, the original resolution is retained.
If the source video's resolution is ​higher, it is compressed to the target resolution.

2. Cropping Region Configuration

Specify a cropping region when calling generateVideo. If not set, the entire video is processed. Use setCutFromTime:
/**
* Set video cropping range.
* @param startTime Start time (ms)
* @param endTime End time (ms)
*/
public void setCutFromTime(long startTime, long endTime)

3. Video Bitrate Configuration

Customize the video bitrate (recommended range: ​600–12000 kbps). Avoid extremely high or low values:
High bitrate → Large file size.
Low bitrate → Blurry video.
Note: If not set, the SDK automatically calculates the bitrate based on the compression level.
public void setVideoBitrate(int videoBitrate);

4. Video Frame Rate Configuration

Use setVideoFramerate to set the frame rate:
public void setVideoFrameRate(VideoFrameRateLevel videoFrameRateLevel)

public enum VideoFrameRateLevel {
VIDEO_FPS_ORIGIN(0),
VIDEO_FPS_AUTO(-1),
VIDEO_FPS_15(15),
VIDEO_FPS_25(25),
VIDEO_FPS_30(30),
VIDEO_FPS_60(60);
}
VIDEO_FPS_ORIGIN - Utilizes the original video's frame rate. When the setVideoFrameRate interface is not called, the system defaults to using the video's original frame rate.
VIDEO_FPS_AUTO - Based on the user-generated video's resolution, bitrate, and the SDK's internal decisions, an appropriate frame rate will be determined.
VIDEO_FPS_15, VIDEO_FPS_25, VIDEO_FPS_30, VIDEO_FPS_60 - Specifies the frame rate as 15, 25, 30, or 60 fps.
Regardless of the parameters passed by the user, the final frame rate of the generated video will not exceed the original video's frame rate.
If the frame rate you set is too low, resulting in an excessively low frame rate for the generated video, it may cause the video to appear less smooth.

Video Preprocessing

If you need to support time effects (e.g., repetition, reverse playback) or enable fast and precise seeking to specific timestamps during preview, you should preprocess the video upon importing.
TXVideoEditer mTXVideoEditer = new TXVideoEditer(context);
mTXVideoEditer.setVideoPath(path);

// Set callback to monitor preprocessing progress and completion
mTXVideoEditer.setVideoProcessListener(new TXVideoProcessListener() {
@Override
public void onProcessProgress(float progress) {}

@Override
public void onProcessComplete(TXGenerateResult result) {}
});

// Generate thumbnails during preprocessing (avoids fetching them separately later)
TXVideoEditConstants.TXThumbnail thumbnail = new TXVideoEditConstants.TXThumbnail();
thumbnail.count = 10; // Number of thumbnails
thumbnail.width = 100; // Thumbnail output width
thumbnail.height = 100; // Thumbnail output height
mTXVideoEditer.setThumbnail(thumbnail);
mTXVideoEditer.setThumbnailListener(mThumbnailListener);

// Start preprocessing
mTXVideoEditer.processVideo();

// Post-preprocessing tasks (preview, add effects, generate final video, etc.)
// ...

Releasing Resources

When you no longer use the mTXVideoEditer object, be sure to call release() to release it.

Advanced Features

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback