tencent cloud

User Generated Short Video SDK

Android

ダウンロード
フォーカスモード
フォントサイズ
最終更新日: 2026-05-11 17:46:57

Feature Overview

The TAVEditor SDK provides video editing capabilities, supporting preview, template editing, short video editing, and more. You can add video/image resources and set parameters such as play range, volume, and speed. It supports playback control, canvas size adjustment, and resource management. Export supports both quick and custom configurations, including resolution and frame rate settings.

Preview Feature

Initialize Preview

TAVEditor editor = TAVEditorFactory.createEditor();
TAVEditorConstants.PreviewParam param = new TAVEditorConstants.PreviewParam();
param.videoView = frameLayout; // Preview container; null for off-screen rendering
param.loopPlay = true; // Loop playback
param.autoPlay = true; // Auto playback
// Usage scenarios:
// SCENE_EXPORT retains only editing info without creating a render chain, and cannot preview; typically used with the fork interface to leave the editing page for export logic, such as exporting and uploading from TikTok's publish page
// SCENE_PLAY creates a render chain for normal on-screen preview; typically used on the editing page
param.scene = TAVEditorConstants.SCENE_PLAY;
editor.initWithPreview(param);

Template Editing Preview

If this feature is not needed, skip this step and proceed directly to short video editing preview.
// Set template path
int ret = editor.setTemplateDir("template_path");
// Get template configuration
TAVTemplateConfig config = editor.getTemplateConfig("template_folder_path");
// Compatible media formats: VIDEO, PHOTO, MULTI
TAVMediaType mediaType = config.mediaType;
// Fillable quantity limit
TAVClipPlaceHolder[] clipHolders = config.clipPlaceHolders;
// Playback duration for each segment
clipHolders[0].contentDuration;
// In template editing mode, the selected video source duration must be >= the corresponding TAVClipPlaceHolder duration
// Add one or more media sources based on template requirements
// Add video as media source
editor.addVideoClip("video_file_path");
// Set play range; duration must match TAVClipPlaceHolder duration
editor.setClipRange(0, 0, clipHolders[0].contentDuration);
// Add image as media source
editor.addImageClip("image_file_path", clipHolders[1].contentDuration);
// Flush current frame to apply resources
editor.flushImmediately();

Short Video Editing Preview

// Add video resource
editor.addVideoClip("video_path");
// Add 3s image resource
editor.addImageClip("image_path", 3000000);
// Flush current frame to apply resources
editor.flushImmediately();

Basic Preview Operations

Refresh Mechanism

To apply your resource settings, call flushImmediately to flush the current frame and display the effect on screen.
/**
* Flush immediately
*/
void flushImmediately();

/**
* Flush immediately
*
* @param tag Tag for this flush operation
* @param callback Task to execute after flush
*/
void flushImmediately(@Nullable String tag, @Nullable TAVConsumer<String> callback);

Set Canvas Size

Through the setRenderSizeRatio interface to set the width/height ratio. The SDK will automatically calculate the actual resolution based on the device level's maximum supported resolution and the aspect ratio set via the interface.
/**
* Set canvas size properties. The width and height passed here are actually aspect ratios; the SDK will not directly use them as the final canvas dimensions
*
* @param width Canvas ratio width
* @param height Canvas ratio height
*/
void setRenderSizeRatio(int width, int height);

/**
* Get the current render size used for preview
*
* @return Render size
*/
Size getRenderSize();

Copy a Render Instance

/**
* Create an instance from the current editing object
*
* @param param param.videoView = null Create an editable off-screen instance (with render chain)
* param.videoView != null Create an editable on-screen instance (with render chain)
* param = null Create an editable default off-screen instance (with render chain)
* param != null Choose whether to create render chain based on param.scene
* @return TAVEditor
*/
TAVEditor fork(@Nullable TAVEditorConstants.PreviewParam param);

Release Resources

When leaving the editing page, call release() to destroy the editor and release editing resources.

Resource Management

Add and Remove Media Resources

/**
* Append a video resource to the end
*
* @param path Video path
* @return Index after successful addition
*/
int addVideoClip(String path);

/**
* Add an editing video at a specified position
*
* @param clipIndex Position to add
* @param paths Editing video source paths
* @return Index after successful addition
*/
int addVideoClip(int clipIndex, List<String> paths);

/**
* Append an image resource to the end
*
* @param path Editing image source path
* @param duration Duration; if <= 0, defaults to 3s
* @return Index after successful addition
*/
int addImageClip(String path, long duration);

/**
* Add image resources at a specified position
*
* @param clipIndex Position to add
* @param paths Editing image source paths
* @param duration Duration; if <= 0, defaults to 3s
* @return Index after successful addition
*/
int addImageClip(int clipIndex, List<String> paths, long duration);

/**
* Get the number of resources currently being edited
*
* @return Resource count
*/
int getClipCount();

/**
* Remove the video or image resource at a specified position
*
* @param clipIndex Resource index
*/
void removeClip(int clipIndex);

Modify Media Resources

/**
* Modify the duration of a specified resource
* For video resources, startTime and endTime will extract a play range from the video itself
*
* @param clipIndex Resource index
* @param startTimeUs Resource playback start time
* @param endTimeUs Resource playback end time
*/
void setClipRange(int clipIndex, long startTimeUs, long endTimeUs);

/**
* Set background volume for a specified resource
*
* @param clipIndex Resource index
* @param volume Volume, recommended 0-3f, 1 is original volume
*/
void setVideoClipVolume(int clipIndex, float volume);

/**
* Set background volume for all resources
*
* @param volume Volume, recommended 0-3f, 1 is original volume
*/
void setAllClipsVolume(float volume);

/**
* Get volume by resource index
*
* @param clipIndex Resource index
* @return Volume
*/
float getVideoClipVolume(int clipIndex);

/**
* Adjust video playback speed
*
* @param clipIndex Video index
* @param speed Playback speed
*/
void setVideoClipSpeed(int clipIndex, float speed);

/**
* Get playback speed by resource index
*
* @param clipIndex Resource index
* @return Playback speed
*/
float getVideoClipSpeed(int clipIndex);

/**
* Adjust resource index
*
* @param oldClipIndex Index before adjustment
* @param newClipIndex Index after adjustment
* @return Adjustment result
*/
boolean updateClipIndex(int oldClipIndex, int newClipIndex);

/**
* Set crop region
*
* @param clipIndex Video index
* @param rectF Normalized crop region relative to render size
*/
void setClipRect(int clipIndex, RectF rectF);

/**
* Set rotation angle (clockwise)
*
* @param clipIndex Video index
* @param degrees Rotation angle
*/
void setClipRotation(int clipIndex, @FloatRange(from = 0, to = 360f) float degrees);

Player Controls

Playback State Management

// Start playback
void startPlay();

// Pause playback
void pausePlay();

// Resume playback
void resumePlay();

// Check playback status
boolean isPlaying();

Playback Progress Control

// Get total duration (microseconds)
long getTotalDuration();

// Seek to position
void seekToTime(long timeUs, boolean isInAccurate);

// Set play range
void setPlayTimeRange(long startTime, long endTime);

Export Operations

Quick Export

// Export level constants
TAVEditorConstants.VIDEO_LEVEL_480P; // Compress to 480P resolution (640*480)
TAVEditorConstants.VIDEO_LEVEL_540P; // Compress to 540P resolution (960*540)
TAVEditorConstants.VIDEO_LEVEL_720P; // Compress to 720P resolution (1280*720)
TAVEditorConstants.VIDEO_LEVEL_1080P; // Compress to 1080P resolution (1920*1080)

editor.generateVideo(VIDEO_LEVEL_720P, outputPath, new TAVEditorGenerateListener() {
// Handle export progress and result
});

Custom Export

TAVEditorGenerateConfig config = new TAVEditorGenerateConfig();

// Video configuration
config.videoConfig.width = 1280;
config.videoConfig.height = 720;
config.videoConfig.frameRate = 30;

// Audio configuration
config.audioConfig.sampleRate = 44100;
config.audioConfig.audioBitRate = 192000;

editor.generateVideo(config, outputPath, listener);

Usage Example

// 1. Initialize preview
TAVEditor editor = TAVEditorFactory.createEditor();
editor.initWithPreview(previewParam);

// 2. Add resources
int videoIndex = editor.addVideoClip("/sdcard/video.mp4");
int imageIndex = editor.addImageClip("/sdcard/image.jpg", 3_000_000);

// 3. Configure resources
TAVVideoInfo info = editor.getVideoInfo("/sdcard/video.mp4");
editor.setClipRange(videoIndex, 0, info.duration);
editor.setVideoClipVolume(videoIndex, 0.8f);

// 4. Playback control
editor.startPlay();
editor.seekToTime(5_000_000, false);

// 5. Export video
editor.generateVideo(TAVEditorConstants.VIDEO_LEVEL_720P, "/sdcard/output.mp4", listener);

// 6. Release resources
editor.release();


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック