Android

最近更新时间:2024-12-09 17:10:22

我的收藏

静态贴纸

设置静态贴纸的方法:
public void setPasterList(List pasterList);

// TXPaster 的参数如下:
public final static class TXPaster {
public Bitmap pasterImage; // 贴纸图片
public TXRect frame; // 贴纸的 frame(注意这里的 frame 坐标是相对于渲染 view 的坐标)
public long startTime; // 贴纸起始时间(ms)
public long endTime; // 贴纸结束时间(ms)
}


动态贴纸

设置动态贴纸的方法:
public void setAnimatedPasterList(List animatedPasterList);

// TXAnimatedPaster 的参数如下:
public final static class TXAnimatedPaster {
public String animatedPasterPathFolder; // 动态贴纸图片地址
public TXRect frame; // 动态贴纸 frame (注意这里的 frame 坐标是相对于渲染 view 的坐标)
public long startTime; // 动态贴纸起始时间(ms)
public long endTime; // 动态贴纸结束时间(ms)
public float rotation;
}

Demo示例:
List animatedPasterList = new ArrayList<>();
List pasterList = new ArrayList<>();
for (int i = 0; i < mTCLayerViewGroup.getChildCount(); i++) {
PasterOperationView view = (PasterOperationView) mTCLayerViewGroup.getOperationView(i);
TXVideoEditConstants.TXRect rect = new TXVideoEditConstants.TXRect();
rect.x = view.getImageX();
rect.y = view.getImageY();
rect.width = view.getImageWidth();
TXCLog.i(TAG, "addPasterListVideo, adjustPasterRect, paster x y = " + rect.x + "," + rect.y);

int childType = view.getChildType();
if (childType == PasterOperationView.TYPE_CHILD_VIEW_ANIMATED_PASTER) {
TXVideoEditConstants.TXAnimatedPaster txAnimatedPaster = new TXVideoEditConstants.TXAnimatedPaster();

txAnimatedPaster.animatedPasterPathFolder = mAnimatedPasterSDcardFolder + view.getPasterName() + File.separator;
txAnimatedPaster.startTime = view.getStartTime();
txAnimatedPaster.endTime = view.getEndTime();
txAnimatedPaster.frame = rect;
txAnimatedPaster.rotation = view.getImageRotate();

animatedPasterList.add(txAnimatedPaster);
TXCLog.i(TAG, "addPasterListVideo, txAnimatedPaster startTimeMs, endTime is : " + txAnimatedPaster.startTime + ", " + txAnimatedPaster.endTime);
} else if (childType == PasterOperationView.TYPE_CHILD_VIEW_PASTER) {
TXVideoEditConstants.TXPaster txPaster = new TXVideoEditConstants.TXPaster();

txPaster.pasterImage = view.getRotateBitmap();
txPaster.startTime = view.getStartTime();
txPaster.endTime = view.getEndTime();
txPaster.frame = rect;

pasterList.add(txPaster);
TXCLog.i(TAG, "addPasterListVideo, txPaster startTimeMs, endTime is : " + txPaster.startTime + ", " + txPaster.endTime);
}
}

mTXVideoEditer.setAnimatedPasterList(animatedPasterList); //设置动态贴纸
mTXVideoEditer.setPasterList(pasterList); //设置静态贴纸

添加字幕

气泡字幕

您可以为视频设置气泡字幕,我们支持对每一帧视频添加字幕,每个字幕您也可以设置视频作用的起始时间和结束时间。所有的字幕组成了一个字幕列表, 您可以把字幕列表传给 SDK 内部,SDK 会自动在合适的时间对视频和字幕做叠加。
设置气泡字幕的方法为:
public void setSubtitleList(List subtitleList);

//TXSubtitle 的参数如下:
public final static class TXSubtitle {
public Bitmap titleImage; // 字幕图片
public TXRect frame; // 字幕的 frame
public long startTime; // 字幕起始时间(ms)
public long endTime; // 字幕结束时间(ms)
}

public final static class TXRect {
public float x;
public float y;
public float width;
}

titleImage:表示字幕图片,如果上层使用的是 TextView 之类的控件,请先把控件转成 Bitmap,具体方法可以参照 demo 的示例代码。
frame:表示字幕的 frame,注意这个 frame 是相对于渲染 view(initWithPreview 时候传入的 view)的 frame,具体可以参照 demo 的示例代码。
startTime:字幕作用的起始时间。
endTime:字幕作用的结束时间。
因为字幕的 UI 逻辑比较复杂,我们已经在 demo 层有一整套的实现方法,推荐客户直接参见 demo 实现, 可以大大降低您的接入成本。
Demo 示例:
mSubtitleList.clear();
for (int i = 0; i < mWordInfoList.size(); i++) {
TCWordOperationView view = mOperationViewGroup.getOperationView(i);
TXVideoEditConstants.TXSubtitle subTitle = new TXVideoEditConstants.TXSubtitle();
subTitle.titleImage = view.getRotateBitmap(); //获取Bitmap
TXVideoEditConstants.TXRect rect = new TXVideoEditConstants.TXRect();
rect.x = view.getImageX(); // 获取相对 parent view 的 x 坐标
rect.y = view.getImageY(); // 获取相对 parent view 的 y 坐标
rect.width = view.getImageWidth(); // 图片宽度
subTitle.frame = rect;
subTitle.startTime = mWordInfoList.get(i).getStartTime(); // 设置开始时间
subTitle.endTime = mWordInfoList.get(i).getEndTime(); // 设置结束时间
mSubtitleList.add(subTitle);
}
mTXVideoEditer.setSubtitleList(mSubtitleList); // 设置字幕列表