Class | Description |
TXVideoInfoReader | Media information obtaining |
TXVideoEditer | Video editing |
/*** 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 framepublic 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 widthpublic int height; // Video heightpublic int audioSampleRate; // Audio bitrate}
//sourcePath Path of the video to editString sourcePath = Environment.getExternalStorageDirectory() + File.separator + "temp.mp4";TXVideoEditConstants.TXVideoInfo info = TXVideoInfoReader.getInstance().getVideoFileInfo(sourcePath);
/*** 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)
true to use this mode, under which thumbnails are generated relatively quickly, but they may not correspond exactly to video frames.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.mTXVideoEditer.getThumbnail(TCVideoEditerWrapper.mThumbnailCount, 100, 100, false, mThumbnailListener);private TXVideoEditer.TXThumbnailListener mThumbnailListener = new TXVideoEditer.TXThumbnailListener() {@Overridepublic void onThumbnail(int index, long timeMs, final Bitmap bitmap) {Log.i(TAG, "onThumbnail: index = " + index + ",timeMs:" + timeMs);// Insert the thumbnails into the image control}};
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);
public void initWithPreview(TXVideoEditConstants.TXPreviewParam param)public final static class TXPreviewParam {public FrameLayout videoView; // Video preview viewpublic 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;
public void previewAtTime(long timeMs);
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);
// Pause previewpublic void pausePlay();// Resume previewpublic void resumePlay();// Stop previewpublic void stopPlay();
void setFilter(Bitmap bmp)
void setSpecialRatio(float specialRatio)
void setFilter(Bitmap leftBitmap, float leftIntensity, Bitmap rightBitmap,float rightIntensity, float leftRatio)
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.TXVideoEditConstants.TXRect rect = new TXVideoEditConstants.TXRect();rect.x = 0.5f;rect.y = 0.5f;rect.width = 0.5f;mTXVideoEditer.setWaterMark(mWaterMarkLogo, rect);
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 secondsBitmap 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);
/*** 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);
// ...// Generate the final video filepublic void generateVideo(int videoCompressed, String videoOutputPath)
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)
/*** Set video cropping range.* @param startTime Start time (ms)* @param endTime End time (ms)*/public void setCutFromTime(long startTime, long endTime)
public void setVideoBitrate(int videoBitrate);
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);}
TXVideoEditer mTXVideoEditer = new TXVideoEditer(context);mTXVideoEditer.setVideoPath(path);// Set callback to monitor preprocessing progress and completionmTXVideoEditer.setVideoProcessListener(new TXVideoProcessListener() {@Overridepublic void onProcessProgress(float progress) {}@Overridepublic void onProcessComplete(TXGenerateResult result) {}});// Generate thumbnails during preprocessing (avoids fetching them separately later)TXVideoEditConstants.TXThumbnail thumbnail = new TXVideoEditConstants.TXThumbnail();thumbnail.count = 10; // Number of thumbnailsthumbnail.width = 100; // Thumbnail output widththumbnail.height = 100; // Thumbnail output heightmTXVideoEditer.setThumbnail(thumbnail);mTXVideoEditer.setThumbnailListener(mThumbnailListener);// Start preprocessingmTXVideoEditer.processVideo();// Post-preprocessing tasks (preview, add effects, generate final video, etc.)// ...
mTXVideoEditer object, be sure to call release() to release it.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback