静态贴纸
- (void) setPasterList:(NSArray *)pasterList;// TXPaster 的参数如下:@interface TXPaster: NSObject@property (nonatomic, strong) UIImage* pasterImage; //贴纸图片@property (nonatomic, assign) CGRect frame; //贴纸 frame(注意这里的 frame 坐标是相对于渲染 view 的坐标)@property (nonatomic, assign) CGFloat startTime; //贴纸起始时间(s)@property (nonatomic, assign) CGFloat endTime; //贴纸结束时间(s)@end
动态贴纸
- (void) setAnimatedPasterList:(NSArray *)animatedPasterList;// TXAnimatedPaster 的参数如下:@interface TXAnimatedPaster: NSObject@property (nonatomic, strong) NSString* animatedPasterpath; //动图文件路径@property (nonatomic, assign) CGRect frame; //动图的 frame(注意这里的 frame 坐标是相对于渲染 view 的坐标)@property (nonatomic, assign) CGFloat rotateAngle; //动图旋转角度 (0 ~ 360)@property (nonatomic, assign) CGFloat startTime; //动图起始时间(s)@property (nonatomic, assign) CGFloat endTime; //动图结束时间(s)@end
Demo 示例:
- (void)setVideoPasters:(NSArray*)videoPasterInfos{NSMutableArray* animatePasters = [NSMutableArray new];NSMutableArray* staticPasters = [NSMutableArray new];for (VideoPasterInfo* pasterInfo in videoPasterInfos) {if (pasterInfo.pasterInfoType == PasterInfoType_Animate) {TXAnimatedPaster* paster = [TXAnimatedPaster new];paster.startTime = pasterInfo.startTime;paster.endTime = pasterInfo.endTime;paster.frame = [pasterInfo.pasterView pasterFrameOnView:_videoPreview];paster.rotateAngle = pasterInfo.pasterView.rotateAngle * 180 / M_PI;paster.animatedPasterpath = pasterInfo.path;[animatePasters addObject:paster];}else if (pasterInfo.pasterInfoType == PasterInfoType_static){TXPaster *paster = [TXPaster new];paster.startTime = pasterInfo.startTime;paster.endTime = pasterInfo.endTime;paster.frame = [pasterInfo.pasterView pasterFrameOnView:_videoPreview];paster.pasterImage = pasterInfo.pasterView.staticImage;[staticPasters addObject:paster];}}[_ugcEditer setAnimatedPasterList:animatePasters];[_ugcEditer setPasterList:staticPasters];}
添加字幕
气泡字幕
您可以为视频添加字幕,我们支持对每一帧视频添加字幕,每个字幕您也可以设置视频作用的起始时间和结束时间。所有的字幕组成了一个字幕列表, 您可以把字幕列表传给 SDK 内部,SDK 会自动在合适的时间对视频和字幕做叠加。
设置字幕的方法为:
- (void) setSubtitleList:(NSArray *)subtitleList;TXSubtitle 的参数如下:@interface TXSubtitle: NSObject@property (nonatomic, strong) UIImage* titleImage; //字幕图片 (这里需要客户把承载文字的控件转成 image 图片)@property (nonatomic, assign) CGRect frame; //字幕的 frame(注意这里的 frame 坐标是相对于渲染 view 的坐标)@property (nonatomic, assign) CGFloat startTime; //字幕起始时间(s)@property (nonatomic, assign) CGFloat endTime; //字幕结束时间(s)@end
titleImage:表示字幕图片,如果上层使用的是 UILabel 之类的控件,请先把控件转成 UIImage,具体方法可以参照 demo 的示例代码。
frame:表示字幕的 frame,注意这个 frame 是相对于渲染 view(initWithPreview 时候传入的 view)的 frame,具体可以参照 demo 的示例代码。
startTime:字幕作用的起始时间。
endTime:字幕作用的结束时间。
因为字幕这一块的 UI 逻辑比较复杂,我们已经在 demo 层有一整套的实现方法,推荐客户直接参见 demo 实现, 可以大大降低您的接入成本。
Demo 示例:
@interface VideoTextInfo : NSObject@property (nonatomic, strong) VideoTextFiled* textField;@property (nonatomic, assign) CGFloat startTime; //in seconds@property (nonatomic, assign) CGFloat endTime;@endvideoTextInfos = @[VideoTextInfo1, VideoTextInfo2 ...];for (VideoTextInfo* textInfo in videoTextInfos) {TXSubtitle* subtitle = [TXSubtitle new];subtitle.titleImage = textInfo.textField.textImage; //UILabel(UIView) -> UIImagesubtitle.frame = [textInfo.textField textFrameOnView:_videoPreview]; //计算相对于渲染 view 的坐标subtitle.startTime = textInfo.startTime; //字幕起始时间subtitle.endTime = textInfo.endTime; //字幕结束时间[subtitles addObject:subtitle]; //添加字幕列表}[_ugcEditer setSubtitleList:subtitles]; //设置字幕列表