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);TXVideoEditer txVideoEditer = new TXVideoEditer(TCVideoPreviewActivity.this);txVideoEditer.setVideoPath(mVideoPath);txVideoEditer.setThumbnailListener(new TXVideoEditer.TXThumbnailListener() {@Overridepublic void onThumbnail(int index, long timeMs, Bitmap bitmap) {Log.i(TAG, "bitmap:" + bitmap + ",timeMs:" + timeMs);saveBitmap(bitmap, timeMs);}});txVideoEditer.getThumbnailList(list, 200, 200);
/*** Configure the thumbnails generated during pre-processing*/public void setThumbnail(TXVideoEditConstants.TXThumbnail thumbnail)
/*** Configure the callback for thumbnail generation during pre-processing* @param listener*/public void setThumbnailListener(TXThumbnailListener listener)
/*** Configure the callback for video pre-processing* @param listener*/public void setVideoProcessListener(TXVideoProcessListener listener)
public void processVideo();
int thumbnailCount = 10; //Number of thumbnails to generateTXVideoEditConstants.TXThumbnail thumbnail = new TXVideoEditConstants.TXThumbnail();thumbnail.count = thumbnailCount;thumbnail.width = 100; // Thumbnail widththumbnail.height = 100; // Thumbnail heightmTXVideoEditer.setThumbnail(thumbnail); // Configure the thumbnails generated during pre-processingmTXVideoEditer.setThumbnailListener(mThumbnailListener); // Configure the callback for thumbnail generationmTXVideoEditer.setVideoProcessListener(this); // Configure the callback of video pre-processing progressmTXVideoEditer.processVideo(); // Pre-process videos
public void initWithPreview(TXVideoEditConstants.TXPreviewParam param)
TXVideoEditConstants
.public final static int PREVIEW_RENDER_MODE_FILL_SCREEN = 1; // Aspect fill. The image is stretched to fill the entire screen, and the excess parts are cropped.public final static int PREVIEW_RENDER_MODE_FILL_EDGE = 2; // Aspect fit. The image is kept intact, and there may be black bars if the aspect ratio does not match.
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)
bmp
to null means to remove the filter effect.void setSpecialRatio(float specialRatio)
void setFilter(Bitmap leftBitmap, float leftIntensity, Bitmap rightBitmap, float rightIntensity, float leftRatio)
leftBitmap
represents the left filter and leftIntensity
the strength of the left filter. rightBitmap
represents the right filter and rightIntensity
the strength of the right filter. leftRatio
indicates the ratio (0.0-1.0) of the image section the left filter is applied to. If leftBitmap
or rightBitmap
is set to null, the filter effect for the corresponding section will be removed.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);
public void setVideoBitrate(int videoBitrate);
/*** Specify the time range for video clipping* @param startTime Start time (ms) for clipping* @param endTime End time (ms) for clipping*/public void setCutFromTime(long startTime, long endTime)// ...// Generate the video filepublic void generateVideo(int videoCompressed, String videoOutputPath)
videoCompressed
in TXVideoEditConstants
are as follows:VIDEO_COMPRESSED_360P – Compress to 360p (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)
mTXVideoEditer
object, be sure to call release() to release it.
Was this page helpful?