// 1.初始化处理环境
val mEngine = Engine.getInstance()
mEngine.init(null)
// 2.创建Video Editor
var editor: VideoEditor = VideoEditor()
val openConfig: VideoEditor.OpenConfig = VideoEditor.OpenConfig()
openConfig.width = 800
openConfig.height = 800
editor.create(openConfig)
// 3.创建Video Clip
val videoConfig = Config()
videoConfig.setString(VideoFileClip.CONFIG_PATH, path)
val videoClip = Clip(editor.context, VideoFileClip.TYPE_NAME)
videoClip.setConfig(videoConfig)
// 4.创建Audio Clip
val audioConfig = Config()
audioConfig.setString(AudioFileClip.CONFIG_PATH, path)
var audioClip = Clip(editor.context, AudioFileClip.TYPE_NAME)
audioClip.setConfig(audioConfig)
// 5.创建视频层
var videoLayer = ClipLayer(editor.context, true)
val videoLayerConfig = Config()
videoLayerConfig.setNumber(Layer.CONFIG_MAIN_LAYER, 1)
videoLayer.setConfig(videoLayerConfig)
// 6.创建音频层
var audioLayer = ClipLayer(mEditor!!.context, false)
val audioLayerConfig = Config()
audioLayerConfig.setNumber(Layer.CONFIG_MAIN_LAYER, 1)
audioLayer.setConfig(audioLayerConfig)
// 7.将Clip 添加到对应层内
videoLayer.addClip(100, videoClip)
audioLayer.addClip(100, audioClip)
// 8.将对应Layer加入到对应的Composition中
mEditor!!.videoComposition().addLayer(11, videoLayer)
mEditor!!.audioComposition().addLayer(11, audioLayer)
// 9.初始化播放器
var mPlayer: VideoEditor.Player = mEditor.newPlayer()
// 10.设置播放状态与进度回调
mPlayer.setListener(Listener() {})
// 11.启动播放器
mPlayer.open()
// 12.初始化渲染View
val displayView : DisplayView = DisplayView()
displayView.init(Engine.getInstance().mainGLContext)
// 13.绑定播放器
displayView.attachPlayer(mPlayer)
// 14.创建Effect
var mFilterProperty: TusdkFilterEffect.PropertyBuilder = TusdkFilterEffect.PropertyBuilder()
var mFilterEffect: Effect = Effect(mEditor!!.context, TusdkFilterEffect.TYPE_NAME)
mFilterEffect.setConfig(mFilterConfig)
mFilterEffect.setProperty(TusdkFilterEffect.PROP_PARAM, mFilterProperty.makeProperty())
// 15.添加Effect
videoClip.effects().add(120, mFilterEffect)
Config
相关的属性为不可动态调节的属性,Config属性变动时,需要重新对VideoEditor进行重新构建
public Config();
public Config(Config o);
public boolean setNumber(String key, double v);
public boolean setNumber(String key, long v);
public boolean setBoolean(String key, boolean v);
public boolean setString(String key, String str);
public boolean setBuffer(String key, byte[] buf);
public boolean setBlob(String key, Blob blob);
public String getString(String key);
public double getNumber(String key);
public long getIntNumber(String key);
public boolean getBoolean(String key);
public String getStringOr(String key, String v);
public long getIntNumberOr(String key, long v);
public double getNumberOr(String key, double v);
public byte[] getBuffer(String key)
Property
相关属性为可动态调节属性,Property属性变动时,会实时生效,不需要重新构建VideoEditor
SDK内各层级只可读属性同样通过Property输出,Property构造由各模块自行实现.用户无需手动构造Property.
Clip
作为SDK内的最小单元,负责图片,视频等实例的创建,Clip 类型分别包含 :
VideoFileClip
视频轨道AudioFileClip
音频轨道ImageClip
图片Text2DClip
文字VideoReverseFileClip
视频轨道倒放SilenceClip
静音音频数据各类型Clip可以通过Config来设置相应的属性,加载对应资源.
CONFIG_PATH
视频路径CONFIG_TRIM_START
素材开始位置CONFIG_TRIM_DURATION
素材持续时长CONFIG_PATH
音频路径CONFIG_TRIM_START
素材开始位置CONFIG_TRIM_DURATION
素材持续时长CONFIG_PATH
图片路径CONFIG_DURATION
图片持续时长CONFIG_MAX_SIDE
图片最大边长CONFIG_DURATION
素材持续时长/**
* 文字显示位置信息
*/
public static class InteractionInfo {
/**
* 角度
*/
public double rotation = 0;
public double posX = 0;
public double posY = 0;
/**
* 宽度
*/
public int width = 0;
/**
* 高度
*/
public int height = 0;
public InteractionInfo(Property prop);
}
/**
* 文字对齐位置
*/
public static enum Alignment {
LEFT, CENTER, RIGHT;
}
public static class Style {
// 正常
public static final int NORMAL = 0;
// 下划线
public static final int UNDERLINE = 1 << 0;
}
// Text Clip 可动态调节参数
public static class PropertyHolder {
public PropertyHolder();
public PropertyHolder(Property prop);
// default values
/**
* 字体路径
*/
public String font = "";
/**
* 文字
*/
public String text = "";
public double posX = 0.5;
public double posY = 0.5;
/**
* 文字缩放大小
*/
public double fontScale = 1.0;
/**
* 旋转角度
*/
public double rotate = 0;
/**
* 字间距
*/
public double textScaleX = 1.0;
/**
* 行间距
*/
public double textScaleY = 1.0;
/**
* 文字描边宽度
*/
public double strokeWidth = 0.1;
/**
* 文字描边颜色
*/
public int strokeColor = Color.BLACK;
/**
* 文字颜色
*/
public int fillColor = Color.WHITE;
/**
* 背景颜色
*/
public int bgColor = Color.TRANSPARENT;
/**
* 文字对齐方式
*/
public Alignment alignment = Alignment.CENTER;
/**
* 文字样式
*/
public int style = Style.NORMAL;
}
public static class PropertyBuilder {
public PropertyHolder holder = new PropertyHolder();
public PropertyBuilder();
public PropertyBuilder(PropertyHolder p);
}
CONFIG_PATH
视频路径CONFIG_TRIM_START
素材开始位置CONFIG_TRIM_DURATION
素材持续时长CONFIG_DURATION
静音数据持续时长// 构造默认Clip
public Clip(EditorContext ctx);
// 根据传入的类型构造Clip
public Clip(EditorContext ctx, String type);
// 根据传入的Model构造Clip
public Clip(EditorContext ctx, Model model);
// 获取类型
public String getType();
// 设置Config
public boolean setConfig(Config config);
// 获取Config
public Config getConfig();
// 设置Model
public boolean setModel(Model m);
// 获取Model
public Model getModel();
// 设置Property
public boolean setProperty(String key, Property prop);
// 获取Property
public Property getProperty(String key);
// Clip预加载
public boolean activate();
// Clip状态复原
public void deactivate();
// 获取轨道信息
public StreamInfo getStreamInfo();
// 返回当前Effects列表
public Effects effects();
Layer
用于包含Clip,Layer内部的播放顺序为线性的,Layer的长度取决于内部所有Clip的长度和转场信息.
// 设置Config
public boolean setConfig(Config config);
// 设置对应Key值的Property
public boolean setProperty(String key, Property prop);
// 获取当前轨道信息
public StreamInfo getStreamInfo()
用于添加Clip的Layer实现
/**
* @param ctx 上下文对象
* @param bVideo 视频/音频
*/
public ClipLayer(EditorContext ctx, boolean bVideo);
// 从Model中创建ClipLayer
public ClipLayer(EditorContext ctx, Model model);
// 设置转场效果
// 1 --> 2 当前转场需添加在2上面
public boolean setTransition(int idx, Transition trans);
// 设置当前索引位置设置的转场效果
public Transition getTransition(int idx);
// 解除转场
public boolean unsetTransition(int idx);
// 添加Clip
public boolean addClip(int idx, Clip clip);
// 删除Clip
public boolean deleteClip(int idx);
// 交换Clip
public boolean swapClips(int idx1, int idx2);
// 移动Clip
public boolean moveClip(int fromIdx, int toIdx);
// 获取Clip
public Clip getClip(int idx);
// 获取全部Clip
public HashMap<Integer, Clip> getAllClips();
CONFIG_MAIN_LAYER
是否为基础层(最下面的layer)
CONFIG_START_POS
当前Layer开始位置
CONFIG_BLEND_MODE
当前Layer混合模式
PROP_OVERLAY
混合属性调节
PROP_MIX
混音属性调节
用于调整多个Layer混合情况下,当前Layer的各混合属性
public static class OverlayPropertyHolder {
public OverlayPropertyHolder();
public OverlayPropertyHolder(Property prop);
// default values
// 混合强度
public double blend_strength = 0.5;
// 不透明度
public double opacity = 1.0;
// X 坐标 (0~1)
public double pzr_pan_x = 0.5;
// Y 坐标 (0~1)
public double pzr_pan_y = 0.5;
// 缩放比例
public double pzr_zoom = 1.0;
// 角度
public double pzr_rotate = 0;
}
public static class OverlayPropertyBuilder {
public OverlayPropertyHolder holder = new OverlayPropertyHolder();
public OverlayPropertyBuilder() {
}
public OverlayPropertyBuilder(OverlayPropertyHolder p);
public Property makeProperty();
}
作用于AudioLayer
中,控制混音情况下,各层级混音强度
public static class AudioMixPropertyHolder {
public AudioMixPropertyHolder();
public AudioMixPropertyHolder(Property prop);
// default values
// 混音强度
public double weight = 1.0;
}
public static class AudioMixPropertyBuilder {
public AudioMixPropertyHolder holder = new AudioMixPropertyHolder();
public AudioMixPropertyBuilder() {
}
public AudioMixPropertyBuilder(AudioMixPropertyHolder p);
public Property makeProperty();
}
Effect
为特效单元,Effect
可作用于Clip
,Layer
,Composition
.
特效清单:
AudioPitchEffect
变声变调AudioRepeatEffect
音频重复AudioRepeatEffectV2
时长内音频重复AudioStretchEffect
音频变速AudioTrimEffect
音频裁剪CanvasResizeEffect
背景调节ColorAdjustEffect
颜色调整CropEffect
画面裁剪TusdkFilterEffect
颜色滤镜TusdkMVEffect
MV特效TusdkParticleEffect
魔法特效TusdkSceneEffect
场景特效VideoRepeatEffect
视频重复VideoStretchEffect
视频变速VideoTransformEffect
视频画面变换VideoTrimEffect
视频裁剪public static class PropertyBuilder {
/**
* 强度(-60~60)
*/
public double pitch = 0.5;
public Property makeProperty();
}
CONFIG_BEGIN
重复开始位置CONFIG_END
重复结束位置CONFIG_REPEAT_COUNT
重复次数CONFIG_DURATION
重复时长CONFIG_STRETCH
速度系数CONFIG_BEGIN
速度调节开始位置CONFIG_END
速度调节结束位置CONFIG_BEGIN
裁剪开始位置CONFIG_END
裁剪结束位置CONFIG_WIDTH
目标宽度CONFIG_HEIGHT
目标高度// 位置信息
public static class InteractionInfo {
// 角度
public double rotation = 0;
public double posX = 0;
public double posY = 0;
// 宽度
public int width = 0;
// 高度
public int height = 0;
public InteractionInfo(Property prop);
}
// 背景颜色类型
public static enum BackgroundType {
// 颜色
COLOR,
// 模糊
BLUR,
}
public static class PropertyHolder {
public BackgroundType type = BackgroundType.COLOR;
public int color = Color.BLACK;
// 模糊强度
public double blurStrength = 0.5;//[0, 1]
public double panX = 0.5;
public double panY = 0.5;
// 缩放比例
public double zoom = 1;
//角度
public double rotate = 0;
public PropertyHolder();
public PropertyHolder(Property prop);
}
public static class PropertyBuilder {
public PropertyHolder holder = new PropertyHolder();
public PropertyBuilder();
public PropertyBuilder(PropertyHolder p);
public Property makeProperty();
}
// 白平衡
/// 0:temp:[-1, 1], 1:tint:[0, 1]
public static final String PROP_TYPE_WhiteBalance = "white-balance";
// 圣光阴影
/// 0:highlight:[0, 1], 1:shadow:[0, 1]
public static final String PROP_TYPE_HighlightShadow = "highlight-shadow";
// 锐化
/// 0:[-1, 1]
public static final String PROP_TYPE_Sharpen = "sharpen";
// 亮度
/// 0:[-1, 1]
public static final String PROP_TYPE_Brightness = "brightness";
// 对比度
/// 0:[0, 1]
public static final String PROP_TYPE_Contrast = "contrast";
// 饱和度
/// 0:[-1, 1]
public static final String PROP_TYPE_Saturation = "saturation";
// 曝光度
/// 0:[-1, 1]
public static final String PROP_TYPE_Exposure = "exposure";
public static class PropertyItem {
public String name;
public double[] values;
public PropertyItem(String key, double v);
public PropertyItem(String key, double v1, double v2);
}
public static class PropertyHolder {
public List<PropertyItem> items = new ArrayList<PropertyItem>();
public PropertyHolder();
public PropertyHolder(Property prop);
}
public static class PropertyBuilder {
public PropertyHolder holder = new PropertyHolder();
public PropertyBuilder();
public PropertyBuilder(PropertyHolder p);
public Property makeProperty();
}
CONFIG_LEFT
左CONFIG_TOP
上CONFIG_RIGHT
右CONFIG_BOTTOM
下CONFIG_CODE
滤镜代号 /**
* 可调节参数
*/
public static final String PROP_PARAM = "parameters";
public static class PropertyHolder {
/**
* 滤镜作用域起点
*/
public long begin = 0;
/**
* 滤镜作用域终点
*/
public long end = 0;
/**
* 滤镜强度(0~1)
*/
public double strength = 0.5;
public PropertyHolder();
public PropertyHolder(Property prop);
}
public static class PropertyBuilder {
public PropertyHolder holder = new PropertyHolder();
public PropertyBuilder();
public PropertyBuilder(PropertyHolder p);
public Property makeProperty();
}
CONFIG_ID
MV贴纸ID /**
* 可调节参数
*/
public static final String PROP_PARAM = "parameters";
public static class PropertyHolder {
/**
* 滤镜作用域起点
*/
public long begin = 0;
/**
* 滤镜作用域终点
*/
public long end = 0;
public PropertyHolder();
public PropertyHolder(Property prop);
}
public static class PropertyBuilder {
public PropertyHolder holder = new PropertyHolder();
public PropertyBuilder();
public PropertyBuilder(PropertyHolder p);
public Property makeProperty();
}
CONFIG_NAME
魔法效果代号 /**
* 当前新增粒子坐标
*/
public static final String PROP_PARTICLE_POS = "particle-pos";
/**
* 全部可调节参数
*/
public static final String PROP_PARAM = "parameters";
public static class ParticlePosPropertyBuilder {
/// range: [0, 1]
public double posX = 0;
public double posY = 0;
/**
* 粒子缩放大小
*/
public double scale = 0.5;
/**
* 粒子颜色
*/
public int tint = Color.TRANSPARENT;
public Property makeProperty();
}
public static class PropertyHolder {
/**
* 粒子特效开始时间,相对于视频时间轴
*/
public long begin = 0;
/**
* 粒子特效结束时间,相对于视频时间轴
*/
public long end = 0;
/**
* 粒子大小比例
*/
public double scale = 0.5;
/**
* 粒子颜色
*/
public int tint = Color.TRANSPARENT;//use default color from config;
public static class PosInfo {
/**
* @param t 当前粒子时间
* @param x
* @param y
*/
public PosInfo(long t, double x, double y);
public long timestamp = 0;//msec
public double x = 0;
public double y = 0;
}
/**
* 全部粒子信息
*/
public ArrayList<PosInfo> trajectory = new ArrayList<>();
public PropertyHolder();
public PropertyHolder(Property prop);
}
public static class PropertyBuilder {
public PropertyHolder holder = new PropertyHolder();
public PropertyBuilder();
public PropertyBuilder(PropertyHolder p);
public Property makeProperty();
}
CONFIG_NAME
场景特效代号 /**
* 可调节参数
*/
public static final String PROP_PARAM = "parameters";
public static class PropertyHolder {
/**
* 滤镜作用域起点
*/
public long begin = 0;
/**
* 滤镜作用域终点
*/
public long end = 0;
public PropertyHolder();
public PropertyHolder(Property prop);
}
public static class PropertyBuilder {
public PropertyHolder holder = new PropertyHolder();
public PropertyBuilder();
public PropertyBuilder(PropertyHolder p);
public Property makeProperty();
}
CONFIG_BEGIN
重复开始位置CONFIG_END
重复结束位置CONFIG_REPEAT_COUNT
重复次数CONFIG_STRETCH
视频速度系数CONFIG_BEGIN
速度调节开始位置CONFIG_END
速度调节结束位置CONFIG_MODE
视频变换模式MODE_None
无变换MODE_k90
顺时针旋转90度MODE_k270
顺时针旋转270度MODE_K180
旋转180度MODE_VFlip
垂直翻转MODE_HFlip
水平翻转CONFIG_BEGIN
裁剪开始位置CONFIG_END
裁剪结束位置// 通过类型创建Effect
public Effect(EditorContext ctx, String type);
// 通过Model创建Effect
public Effect(EditorContext ctx, Model model);
// 获取当前类型
public String getType();
// 设置Config
public boolean setConfig(Config config);
// 获取Config
public Config getConfig();
// 设置Model
public boolean setModel(Model m);
// 获取Model
public Model getModel();
// 设置Property
public boolean setProperty(String key, Property prop);
// 获取Property
public Property getProperty(String key);
// 通过Model恢复
public boolean create(EditorModel model);
// 通过设置创建
public boolean create(OpenConfig config);
// 更新编辑器设置
public boolean update(OpenConfig config);
// 创建Player
public VideoEditor.Player newPlayer();
// 重置Player
public void resetPlayer();
// 创建Producer
public VideoEditor.Producer newProducer();
// 重置Producer
public void resetProducer();
// 获取当前Player
public VideoEditor.Player getPlayer();
// 获取当前Producer
public VideoEditor.Producer getProducer();
// 获取当前上下文对象
public EditorContext getContext();
// 构建Editor
public boolean build();
// 返回Video Composition
public Composition videoComposition();
// 返回Audio Composition
public Composition audioComposition();
// 返回草稿对象
public EditorModel getModel();
// 启动 Player
public boolean open();
// 关闭 Player
public void close();
// 锁定结构
public void lock();
// 解锁结构
public void unlock();
// 设置进度与状态监听
public void setListener(Listener l);
// 设置Player参数
public boolean setOutputConfig(OutputConfig config);
// 获取当前总时长
public long getDuration();
// 开始播放
public boolean play();
// 暂停播放
public boolean pause();
// seek到指定位置(不更新画面)
public boolean seekTo(long ts);
// seek到指定位置(同时更新画面)
public boolean previewFrame(long ts);
// 初始化 Producer
public boolean init(String output);
// 释放 Producer
public void release();
// 设置进度与状态监听
public void setListener(Listener l);
// 设置输出文件属性
public boolean setOutputConfig(OutputConfig config);
// 启动 Producer
public boolean start();
// 终止 Producer
public void cancel();
// 获取输出文件时长
public long getDuration();
player.lock()
*.setConfig(cfg)
editor.build()
player.unlock()
player.seek(ts)