// 1.初始化处理环境
[TUPEngine Init:nil];
// 2.创建Video Editor
let editor = TUPVEditor()
let config = TUPVEditor_Config()
config.width = 800
config.height = 800
editor.create(with: config)
// 3.创建Video Clip
let videoConfig = TUPConfig()
videoConfig.setString(videoPath, forKey: TUPVEFileClip_CONFIG_PATH)
let videoClip = TUPVEditorClip(editor.getContext(), withType: TUPVEFileClip_VIDEO_TYPE_NAME)
videoClip.setConfig(videoConfig)
// 4.创建Audio Clip
let audioConfig = TUPConfig()
audioConfig.setString(audioPath, forKey: TUPVEFileClip_CONFIG_PATH)
let audioClip = TUPVEditorClip(editor.getContext(), withType: TUPVEFileClip_AUDIO_TYPE_NAME)
audioClip.setConfig(audioConfig)
// 5.创建视频层
let videoLayer = TUPVEditorClipLayer(forVideo: editor.getContext())
val videoLayerConfig = Config()
videoLayer.setConfig(videoLayerConfig)
// 6.创建音频层
let audioLayer = TUPVEditorClipLayer(forAudio: editor.getContext())
val audioLayerConfig = Config()
audioLayer.setConfig(audioLayerConfig)
// 7.将Clip 添加到对应层内
videoLayer.add(videoClip, at: 100)
audioLayer.add(audioClip, at: 100)
// 8.将对应Layer加入到对应的Composition中
let videoComp = editor.videoComposition()
videoComp.add(videoLayer, at: 100)
let audioComp = editor.audioComposition()
audioComp.add(audioLayer, at: 100)
// 9.初始化播放器
let player = EditorAdapter().player
// 10.设置播放状态与进度回调
player.delegate = self
// 11.启动播放器
player.open()
// 12.初始化渲染View
let displayView = TUPDisplayView()
displayView.frame = CGRect(x: 0, y: 0, width: UIScreen.width(), height: UIScreen.width())
[displayView setup:nil];
// 13.绑定播放器
displayView.attach(player)
// 14.创建Effect
var filterEffectBuilder = TUPVETusdkFilterEffect_PropertyBuilder()
var filterVideoEffect = TUPVEditorEffect(editor.getContext(), withType: TUPVETusdkFilterEffect_TYPE_NAME)
let config = TUPConfig()
config.setString(code, forKey: TUPVETusdkFilterEffect_CONFIG_NAME)
filterVideoEffect.setConfig(config)
filterVideoEffect.setProperty(filterEffectBuilder.makeProperty(), forKey: TUPVETusdkFilterEffect_PROP_PARAM)
// 15.添加Effect
videoClip.effects().add(filterVideoEffect, at: 100)
Config
相关的属性为不可动态调节的属性,Config属性变动时,需要重新对VideoEditor进行重新构建
- (instancetype) init;
- (instancetype) initWithImpl:(void*)config;//pulse::Config
// Config*
- (BOOL) unwrap:(void*)config;
- (BOOL) setNumber:(NSNumber*)number forKey:(NSString*)key;
- (NSNumber*) getNumber:(NSString*)key;
- (BOOL) setIntNumber:(NSInteger)number forKey:(NSString*)key;
- (NSInteger) getIntNumber:(NSString*)key;
- (NSInteger) getIntNumber:(NSString*)key or:(NSInteger)val;
- (BOOL) setDoubleNumber:(double)number forKey:(NSString*)key;
- (double) getDoubleNumber:(NSString*)key;
- (double) getDoubleNumber:(NSString*)key or:(double)val;
- (BOOL) setString:(NSString*)str forKey:(NSString*)key;
- (NSString*) getString:(NSString*)key;
- (BOOL) setData:(NSData*)str forKey:(NSString*)key;
- (NSData*) getData:(NSString*)key;
Property
相关属性为可动态调节属性,Property属性变动时,会实时生效,不需要重新构建VideoEditor
SDK内各层级只可读属性同样通过Property输出,Property构造由各模块自行实现.用户无需手动构造Property。
Clip
作为SDK内的最小单元,负责图片,视频等实例的创建,Clip 类型分别包含 :
VideoClip
视频轨道AudioClip
音频轨道ImageClip
图片Text2DClip
文字SilenceClip
静音音频数据各类型Clip可以通过Config来设置相应的属性,加载对应资源.
TUPVEFileClip_VIDEO_TYPE_NAME
视频路径TUPVEFileClip_CONFIG_TRIM_START
素材开始位置TUPVEFileClip_CONFIG_TRIM_DURATION
素材持续时长TUPVEFileClip_AUDIO_TYPE_NAME
音频路径TUPVEFileClip_CONFIG_TRIM_START
素材开始位置TUPVEFileClip_CONFIG_TRIM_DURATION
素材持续时长TUPVEImageClip_CONFIG_PATH
图片路径TUPVEImageClip_CONFIG_BLOB
图片数据TUPVEImageClip_CONFIG_DURATION
图片持续时长TUPVEImageClip_CONFIG_MAX_SIDE
图片最大边长TUPVEText2DClip_CONFIG_DURATION
素材持续时长
@interface TUPVEText2DClip_InteractionInfo : NSObject {
}
/**位置*/
@property(nonatomic) double posX;
@property(nonatomic) double posY;
/**宽高*/
@property(nonatomic) int width;
@property(nonatomic) int height;
/**角度*/
@property(nonatomic) int rotation;
- (instancetype) init;
- (instancetype) init:(TUPProperty*) prop;
@end
/**文字位置*/
typedef NS_ENUM(NSInteger, TUPVEText2DClip_AlignmentType) {
TUPVEText2DClipAlignmentType_LEFT,
TUPVEText2DClipAlignmentType_CENTER,
TUPVEText2DClipAlignmentType_RIGHT
};
@interface TUPVEText2DClip_PropertyHolder : NSObject
/**字体路径*/
@property(nonatomic, copy) NSString* font;
/**文字*/
@property(nonatomic, copy) NSString* text;
@property(nonatomic) int underline;
@property(nonatomic) double posX;
@property(nonatomic) double posY;
/**缩放大小*/
@property(nonatomic) double fontScale;
/**旋转角度*/
@property(nonatomic) int rotation;
/**字间距*/
@property(nonatomic) double textScaleX;
/**行间距*/
@property(nonatomic) double textScaleY;
/**文字描边宽度*/
@property(nonatomic) double strokeWidth;
/**文字描边颜色*/
@property(nonatomic) UIColor* strokeColor;
/**文字颜色*/
@property(nonatomic) UIColor* fillColor;
/**背景颜色*/
@property(nonatomic) UIColor* bgColor;
/**对齐方式*/
@property(nonatomic) TUPVEText2DClip_AlignmentType alignment;
- (instancetype) init;
- (instancetype) initWithProperty:(TUPProperty*) prop;
@end
TUPVESilenceClip_AUDIO_TYPE_NAME
视频路径TUPVESilenceClip_CONFIG_DURATION
素材持续时长
@property(nonatomic, readonly) TUPVEditorCtx* context;
@property(nonatomic, readonly) NSString* mediaType;
// 构造默认Clip
- (instancetype) init NS_UNAVAILABLE;
// 根据传入的类型构造Clip
- (instancetype) init:(TUPVEditorCtx*) ctx withType:(NSString*) type;
// 根据传入的Model构造Clip
- (instancetype) init:(TUPVEditorCtx*) ctx withModel:(TUPVEditorModel*) model;
// 返回当前Effects列表
- (TUPVEditorEffects*) effects;
// 设置Config
- (BOOL) setConfig:(TUPConfig*) config;
// 获取Config
- (TUPConfig*) getConfig;
// 设置Property
- (BOOL) setProperty:(TUPProperty*) prop forKey:(NSString*) key;
// 获取Property
- (TUPProperty* _Nullable) getProperty:(NSString*) key;
// 获取Model
- (TUPVEditorModel*) getModel;
// 设置Model
- (BOOL) setModel:(TUPVEditorModel*) model;
// Clip预加载
- (BOOL) activate;
// Clip状态复原
- (void) deactivate;
// 获取轨道信息
- (TUPStreamInfo* _Nullable) getStreamInfo;
// 获取类型
- (NSString*) getType;
TUPVEditorLayer
用于包含Clip,Layer内部的播放顺序为线性的,Layer的长度取决于内部所有Clip的长度和转场信息.
@interface TUPVEditorLayer : TUPBase {
// 设置Config
- (BOOL) setConfig:(TUPConfig*) config;
// 获取Config
- (TUPConfig*) getConfig;
// 设置Property
- (BOOL) setProperty:(TUPProperty*) prop forKey:(NSString*) key;
// 获取Property
- (TUPProperty* _Nullable) getProperty:(NSString*) key;
// 获取Model
- (TUPVEditorModel*) getModel;
// 设置Model
- (BOOL) setModel:(TUPVEditorModel*) model;
// 获取当前轨道信息
- (TUPStreamInfo* _Nullable) getStreamInfo;
@end
用于添加Clip的Layer实现
@interface TUPVEditorClipLayer : TUPVEditorLayer {
//
}
/**音视频初始化*/
- (instancetype) initForAudio:(TUPVEditorCtx*) ctx;
- (instancetype) initForVideo:(TUPVEditorCtx*) ctx;
- (instancetype) init:(TUPVEditorCtx*) ctx forVideo:(BOOL) v;
/**从Model中创建ClipLayer*/
- (instancetype) init:(TUPVEditorCtx*) ctx withModel:(TUPVEditorModel*) model;
// 设置转场效果
// 1 --> 2 当前转场需添加在2上面
- (BOOL) setTransition:(TUPVEditorClipLayer_Transition*) transition at:(NSInteger) idx;
// 设置当前索引位置设置的转场效果
- (TUPVEditorClipLayer_Transition*) getTransition:(NSInteger) idx;
// 解除转场
- (BOOL) unsetTransition:(NSInteger) idx;
// 添加Clip
- (BOOL) addClip:(TUPVEditorClip*) clip at:(NSInteger) idx;
// 删除Clip
- (BOOL) deleteClip:(NSInteger) idx;
// 删除全部Clip
- (void) deleteAllClips;
// 交换Clip
- (BOOL) swapClips:(NSInteger) idx1 and:(NSInteger) idx2;
// 获取Clip
- (TUPVEditorClip* _Nullable) getClip:(NSInteger) idx;
// 获取全部Clip
- (NSDictionary<NSNumber*, TUPVEditorClip*>*) getAllClips;
- (TUPVEditorEffects*) effects;
@end
TUPVEditorLayer_CONFIG_START_POS
当前Layer开始位置
TUPVEditorLayer_CONFIG_BLEND_MODE
当前Layer混合模式
TUPVEditorLayer_PROP_OVERLAY
混合属性调节
TUPVEditorLayer_PROP_MIX
混音属性调节
用于调整多个Layer混合情况下,当前Layer的各混合属性
@interface TUPVEditorLayer_OverlayPropertyHolder : NSObject
// 不透明度
@property(nonatomic) float opacity;
// 混合强度
@property(nonatomic) float blendStrength;
// X 坐标 (0~1)
@property(nonatomic) float pzrPanX;
// Y 坐标 (0~1)
@property(nonatomic) float pzrPanY;
// 缩放比例
@property(nonatomic) float pzrZoom;
// 角度
@property(nonatomic) double pzrRotate;
- (instancetype) init;
- (instancetype) initWithProperty:(TUPProperty*) prop;
@end
@interface TUPVEditorLayer_OverlayPropertyBuilder : NSObject
@property(nonatomic) TUPVEditorLayer_OverlayPropertyHolder* holder;
- (instancetype) init;
- (instancetype) initWithHolder:(TUPVEditorLayer_OverlayPropertyHolder*) holder;
- (TUPProperty*) makeProperty;
@end
作用于AudioLayer
中,控制混音情况下,各层级混音强度
@interface TUPVEditorLayer_MixPropertyHolder : NSObject
/// Audio mix weight, range [0, +oo]
// 混音强度
@property(nonatomic) float weight;
- (instancetype) init;
- (instancetype) initWithProperty:(TUPProperty*) prop;
@end
@interface TUPVEditorLayer_MixPropertyBuilder : NSObject
@property(nonatomic) TUPVEditorLayer_MixPropertyHolder* holder;
- (instancetype) init;
- (instancetype) initWithHolder:(TUPVEditorLayer_MixPropertyHolder*) holder;
- (TUPProperty*) makeProperty;
@end
Effect
为特效单元,Effect
可作用于Clip
,Layer
,Composition
.
特效清单:
TUPVERepeatEffect
音视频重复TUPVERepeatEffectV2
时长内音频重复TUPVEStretchEffect
音频变速TUPVETrimEffect
音视频裁剪TUPVECanvasResizeEffect
背景调节TUPVEColorAdjustEffect
颜色调整TUPVECropEffect
画面裁剪TUPVETusdkFilterEffect
颜色滤镜TUPVETusdkMVEffect
MV特效TUPVETusdkParticleEffect
魔法特效TUPVETusdkSceneEffect
场景特效TUPVEStretchEffect
视频变速TUPVETransformEffect
视频画面变换TUPVERepeatEffect_CONFIG_BEGIN
重复开始位置TUPVERepeatEffect_CONFIG_END
重复结束位置TUPVERepeatEffect_CONFIG_REPEAT_COUNT
重复次数TUPVERepeatEffectV2_CONFIG_DURATION
重复时长TUPVEStretchEffect_CONFIG_STRETCH
速度系数TUPVEStretchEffect_CONFIG_BEGIN
速度调节开始位置TUPVEStretchEffect_CONFIG_END
速度调节结束位置TUPVETrimEffect_CONFIG_BEGIN
裁剪开始位置TUPVETrimEffect_CONFIG_END
裁剪结束位置
// 背景颜色类型
typedef NS_ENUM(NSInteger, TUPVECanvasResizeEffect_BackgroundType) {
TUPVECanvasResizeEffect_BackgroundType_Color, //颜色
TUPVECanvasResizeEffect_BackgroundType_Blur //模糊
};
@interface TUPVECanvasResizeEffect_PropertyHolder : NSObject
@property(nonatomic) TUPVECanvasResizeEffect_BackgroundType type;
@property(nonatomic) UIColor* color;
// 模糊强度
@property(nonatomic) double blurStrength;
@property(nonatomic) double panX;
@property(nonatomic) double panY;
// 缩放比例
@property(nonatomic) double zoom;
//角度
@property(nonatomic) double rotate;
- (instancetype) init;
- (instancetype) initWithProperty:(TUPProperty*) prop;
@end
@interface TUPVECanvasResizeEffect_PropertyBuilder : NSObject {
}
@property(nonatomic) TUPVECanvasResizeEffect_PropertyHolder* holder;
- (instancetype) init;
- (instancetype) initWithHolder:(TUPVECanvasResizeEffect_PropertyHolder*) holder;
- (TUPProperty*) makeProperty;
@end
// 白平衡
/// 0:temp:[-1, 1], 1:tint:[0, 1]
FOUNDATION_EXPORT NSString *const TUPVEColorAdjustEffect_PROP_TYPE_WhiteBalance;
// 圣光阴影
/// 0:highlight:[0, 1], 1:shadow:[0, 1]
FOUNDATION_EXPORT NSString *const TUPVEColorAdjustEffect_PROP_TYPE_HighlightShadow;
// 锐化
/// 0:[-1, 1]
FOUNDATION_EXPORT NSString *const TUPVEColorAdjustEffect_PROP_TYPE_Sharpen;
// 亮度
/// 0:[-1, 1]
FOUNDATION_EXPORT NSString *const TUPVEColorAdjustEffect_PROP_TYPE_Brightness;
// 对比度
/// 0:[0, 1]
FOUNDATION_EXPORT NSString *const TUPVEColorAdjustEffect_PROP_TYPE_Contrast;
// 饱和度
/// 0:[-1, 1]
FOUNDATION_EXPORT NSString *const TUPVEColorAdjustEffect_PROP_TYPE_Saturation;
// 曝光度
/// 0:[-1, 1]
FOUNDATION_EXPORT NSString *const TUPVEColorAdjustEffect_PROP_TYPE_Exposure;
@interface TUPVEColorAdjustEffect_PropertyItem : NSObject
@property(nonatomic, copy) NSString* name;
@property(nonatomic) NSArray<NSNumber*>* values;
- (instancetype) init:(NSString*) name with:(double) v;
- (instancetype) init:(NSString*) name with:(double) v0 and:(double) v1;
- (instancetype) init:(NSString*) name withArray:(NSArray<NSNumber*>*) arr;
@end
@interface TUPVEColorAdjustEffect_PropertyHolder : NSObject
@property(nonatomic) NSMutableArray<TUPVEColorAdjustEffect_PropertyItem*>* items;
- (instancetype) init;
- (instancetype) initWithProperty:(TUPProperty*) prop;
@end
@interface TUPVEColorAdjustEffect_PropertyBuilder : NSObject
@property(nonatomic) TUPVEColorAdjustEffect_PropertyHolder* holder;
- (instancetype) init;
- (instancetype) initWithHolder:(TUPVEColorAdjustEffect_PropertyHolder*) holder;
- (TUPProperty*) makeProperty;
@end
FOUNDATION_EXPORT NSString *const TUPVECropEffect_CONFIG_LEFT //左;
FOUNDATION_EXPORT NSString *const TUPVECropEffect_CONFIG_TOP; //上
FOUNDATION_EXPORT NSString *const TUPVECropEffect_CONFIG_RIGHT; //右
FOUNDATION_EXPORT NSString *const TUPVECropEffect_CONFIG_BOTTOM; //下
TUPVETusdkFilterEffect_CONFIG_NAME
滤镜代号@interface TUPVETusdkFilterEffect_PropertyHolder : NSObject
/**滤镜作用域起点*/
@property(nonatomic) int64_t begin;
/**滤镜作用域终点*/
@property(nonatomic) int64_t end;
/**滤镜强度(0~1)*/
@property(nonatomic) double strength;
- (instancetype) init;
- (instancetype) initWithProperty:(TUPProperty*) prop;
@end
@interface TUPVETusdkFilterEffect_PropertyBuilder : NSObject {
}
@property(nonatomic) TUPVETusdkFilterEffect_PropertyHolder* holder;
- (instancetype) init;
- (instancetype) initWithHolder:(TUPVETusdkFilterEffect_PropertyHolder*) holder;
- (TUPProperty*) makeProperty;
@end
TUPVETusdkMVEffect_CONFIG_CODE
MV贴纸ID
@interface TUPVETusdkMVEffect_PropertyHolder : NSObject
/**MV作用域起点*/
@property(nonatomic) int64_t begin;
/**MV作用域终点*/
@property(nonatomic) int64_t end;
- (instancetype) init;
- (instancetype) initWithProperty:(TUPProperty*) prop;
@end
@interface TUPVETusdkMVEffect_PropertyBuilder : NSObject {
}
@property(nonatomic) TUPVETusdkMVEffect_PropertyHolder* holder;
- (instancetype) init;
- (instancetype) initWithHolder:(TUPVETusdkMVEffect_PropertyHolder*) holder;
- (TUPProperty*) makeProperty;
@end
TUPVETusdkParticleEffect_CONFIG_NAME
魔法效果代号
@interface TUPVETusdkParticleEffect_PropertyHolder : NSObject
/**粒子特效开始时间,相对于视频时间轴*/
@property(nonatomic) int64_t begin;
/**粒子特效结束时间,相对于视频时间轴*/
@property(nonatomic) int64_t end;
/**粒子大小比例*/
@property(nonatomic) double scale;
/**粒子颜色*/
@property(nonatomic) UIColor* tint;
@property(nonatomic) NSArray<TUPVETusdkParticleEffect_PosInfo*>* trajectory;
- (instancetype) init;
- (instancetype) initWithProperty:(TUPProperty*) prop;
@end
@interface TUPVETusdkParticleEffect_PosInfo : NSObject {
}
@property(nonatomic) int64_t timestamp;
@property(nonatomic) double posX;
@property(nonatomic) double posY;
- (instancetype) init:(int64_t) ts withPosX:(double) x andY:(double) y;
@end
@interface TUPVETusdkParticleEffect_PropertyBuilder : NSObject {
}
@property(nonatomic) TUPVETusdkParticleEffect_PropertyHolder* holder;
- (instancetype) init;
- (instancetype) initWithHolder:(TUPVETusdkParticleEffect_PropertyHolder*) holder;
- (TUPProperty*) makeProperty;
@end
TUPVETusdkSceneEffect_CONFIG_NAME
场景特效代号
@interface TUPVETusdkSceneEffect_PropertyHolder : NSObject
@property(nonatomic) int64_t begin;
@property(nonatomic) int64_t end;
- (instancetype) init;
- (instancetype) initWithProperty:(TUPProperty*) prop;
@end
@interface TUPVETusdkSceneEffect_PropertyBuilder : NSObject {
}
@property(nonatomic) TUPVETusdkSceneEffect_PropertyHolder* holder;
- (instancetype) init;
- (instancetype) initWithHolder:(TUPVETusdkSceneEffect_PropertyHolder*) holder;
- (TUPProperty*) makeProperty;
TUPVEStretchEffect_CONFIG_STRETCH
视频速度系数
TUPVEStretchEffect_CONFIG_BEGIN
速度调节开始位置
TUPVEStretchEffect_CONFIG_END
速度调节结束位置
TUPVETransformEffect_CONFIG_MODE
视频变换模式TUPVETransformEffect_CONFIG_MODE
无变换TUPVETransformEffect_MODE_K90
顺时针旋转90度TUPVETransformEffect_MODE_K180
旋转180度TUPVETransformEffect_MODE_K270
顺时针旋转270度TUPVETransformEffect_MODE_VFlip
垂直翻转TUPVETransformEffect_MODE_HFlip
水平翻转
- (instancetype) init NS_UNAVAILABLE;
// 通过类型创建Effect
- (instancetype) init:(TUPVEditorCtx*) ctx withType:(NSString*) type;
// 通过Model创建Effect
- (instancetype) init:(TUPVEditorCtx*) ctx withModel:(TUPVEditorModel*) model;
// 设置Config
- (BOOL) setConfig:(TUPConfig*) config;
// 获取Config
- (TUPConfig*) getConfig;
// 设置Property
- (BOOL) setProperty:(TUPProperty*) prop forKey:(NSString*) key;
// 获取Property
- (TUPProperty* _Nullable) getProperty:(NSString*) key;
// 设置Model
- (TUPVEditorModel*) getModel;
// 获取Model
- (BOOL) setModel:(TUPVEditorModel*) model;
// 获取当前类型
- (NSString*) getType;
//获取config
- (TUPVEditor_Config*) getConfig;
// 创建config
- (BOOL) createWithConfig:(TUPVEditor_Config*) config;
// 通过Model恢复
- (BOOL) createWithModel:(TUPVEditorEditorModel*) model;
// 编辑器销毁
- (void) destroy;
// 更新编辑器设置
- (BOOL) updateWithConfig:(TUPVEditor_Config*) config;
// 创建Player
- (TUPPlayer*) newPlayer;
// 重置Producer
- (void) resetPlayer;
// 获取当前Producer
- (TUPProducer*) newProducer;
// 重置Producer
- (void) resetProducer;
- (TUPVEditorComposition*) videoComposition;
- (TUPVEditorComposition*) audioComposition;
// 构建Editor
- (BOOL) build;
//获取视频时长
- (NSInteger) getDuration;
// 返回草稿对象
- (TUPVEditorEditorModel*) getModel;
@property(nonatomic, weak) id<TUPPlayerDelegate> delegate;
// 关闭 Player
- (void) close;
// 设置Player参数
- (BOOL) setOutputConfig:(TUPPlayer_OutputConfig*)config;
// 开始播放
- (BOOL) play;
// 暂停播放
- (BOOL) pause;
// seek到指定位置(不更新画面)
- (BOOL) seekTo:(NSInteger)pts;
// seek到指定位置(同时更新画面)
- (BOOL) previewFrame:(NSInteger)pts;
// 获取当前总时长
- (NSInteger) getDuration;
//- (void) _signalEvent:(TUPPlayerState)state withTimestamp:(NSInteger)pts;
player.lock
[* setConfig:cfg]
editor.build
player.unlock
[player seek:ts]