TAVEditor editor = TAVEditorFactory.createEditor();TAVEditorConstants.PreviewParam param = new TAVEditorConstants.PreviewParam();param.videoView = frameLayout; // Preview container; null for off-screen renderingparam.loopPlay = true; // Loop playbackparam.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 pageparam.scene = TAVEditorConstants.SCENE_PLAY;editor.initWithPreview(param);
// Set template pathint ret = editor.setTemplateDir("template_path");// Get template configurationTAVTemplateConfig config = editor.getTemplateConfig("template_folder_path");// Compatible media formats: VIDEO, PHOTO, MULTITAVMediaType mediaType = config.mediaType;// Fillable quantity limitTAVClipPlaceHolder[] clipHolders = config.clipPlaceHolders;// Playback duration for each segmentclipHolders[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 sourceeditor.addVideoClip("video_file_path");// Set play range; duration must match TAVClipPlaceHolder durationeditor.setClipRange(0, 0, clipHolders[0].contentDuration);// Add image as media sourceeditor.addImageClip("image_file_path", clipHolders[1].contentDuration);// Flush current frame to apply resourceseditor.flushImmediately();
// Add video resourceeditor.addVideoClip("video_path");// Add 3s image resourceeditor.addImageClip("image_path", 3000000);// Flush current frame to apply resourceseditor.flushImmediately();
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);
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();
/*** 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() to destroy the editor and release editing 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 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);
// Start playbackvoid startPlay();// Pause playbackvoid pausePlay();// Resume playbackvoid resumePlay();// Check playback statusboolean isPlaying();
// Get total duration (microseconds)long getTotalDuration();// Seek to positionvoid seekToTime(long timeUs, boolean isInAccurate);// Set play rangevoid setPlayTimeRange(long startTime, long endTime);
// Export level constantsTAVEditorConstants.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});
TAVEditorGenerateConfig config = new TAVEditorGenerateConfig();// Video configurationconfig.videoConfig.width = 1280;config.videoConfig.height = 720;config.videoConfig.frameRate = 30;// Audio configurationconfig.audioConfig.sampleRate = 44100;config.audioConfig.audioBitRate = 192000;editor.generateVideo(config, outputPath, listener);
// 1. Initialize previewTAVEditor editor = TAVEditorFactory.createEditor();editor.initWithPreview(previewParam);// 2. Add resourcesint videoIndex = editor.addVideoClip("/sdcard/video.mp4");int imageIndex = editor.addImageClip("/sdcard/image.jpg", 3_000_000);// 3. Configure resourcesTAVVideoInfo info = editor.getVideoInfo("/sdcard/video.mp4");editor.setClipRange(videoIndex, 0, info.duration);editor.setVideoClipVolume(videoIndex, 0.8f);// 4. Playback controleditor.startPlay();editor.seekToTime(5_000_000, false);// 5. Export videoeditor.generateVideo(TAVEditorConstants.VIDEO_LEVEL_720P, "/sdcard/output.mp4", listener);// 6. Release resourceseditor.release();
フィードバック