... | @@ -429,3 +429,127 @@ imagesVideoMaker.startMake(new ImagesVideoMaker.OnMakeListener() { |
... | @@ -429,3 +429,127 @@ imagesVideoMaker.startMake(new ImagesVideoMaker.OnMakeListener() { |
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
## 4.10 视频特效
|
|
|
|
|
|
|
|
视频特效预览,完整代码请参考Demo。
|
|
|
|
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
* @param startTime 开始时间(单位毫秒)
|
|
|
|
* @param endTime 结束时间(单位毫秒)
|
|
|
|
* @param baseEffect 特效
|
|
|
|
*/
|
|
|
|
public EffectPeriod addEffect(long startTime, long endTime, BaseEffect baseEffect) {
|
|
|
|
EffectPeriod period = new EffectPeriod(startTimeMs, endTimeMs, baseEffect);
|
|
|
|
effectList.putEffect(period);
|
|
|
|
return period;
|
|
|
|
}
|
|
|
|
|
|
|
|
//添加抖动特效
|
|
|
|
addEffect(startTime, endTime, new ShakeEffect(context));
|
|
|
|
//添加闪屏特效
|
|
|
|
addEffect(startTime, endTime, new FlashEffect(context));
|
|
|
|
//添加幻觉特效
|
|
|
|
addEffect(startTime, endTime, new IllusionEffect(context));
|
|
|
|
//添加毛刺特效
|
|
|
|
addEffect(startTime, endTime, new BurrEffect(context));
|
|
|
|
//添加缩放特效
|
|
|
|
addEffect(startTime, endTime, new ScaleEffect(context));
|
|
|
|
|
|
|
|
//预览特效
|
|
|
|
Thread thread = new Thread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
encoderSurface = new EncoderSurface(new Surface(surfaceTexture));
|
|
|
|
encoderSurface.makeCurrent();
|
|
|
|
decoderSurface = new DecoderOutputSurface(new BaseEffect(), effectList);
|
|
|
|
decoderSurface.setOutputResolution(new Resolution(textureViewWidth, textureViewHeight));
|
|
|
|
decoderSurface.setInputResolution(new Resolution(textureViewWidth, textureViewHeight));
|
|
|
|
decoderSurface.setupAll();
|
|
|
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
while (decoderSurface.getSurface() == null) {
|
|
|
|
try {
|
|
|
|
Thread.sleep(30);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Surface surface = decoderSurface.getSurface();
|
|
|
|
mediaPlayer.setSurface(surface);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
poll();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
thread.start();
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
生成特效视频,完整代码请参考Demo。
|
|
|
|
|
|
|
|
```
|
|
|
|
//添加抖动特效
|
|
|
|
effectConfigList.add(new EffectConfig(EffectType.SHAKE, effectPeriod.startTime, effectPeriod.endTime));
|
|
|
|
//添加闪屏特效
|
|
|
|
effectConfigList.add(new EffectConfig(EffectType.FLASH, effectPeriod.startTime, effectPeriod.endTime));
|
|
|
|
//添加幻觉特效
|
|
|
|
effectConfigList.add(new EffectConfig(EffectType.ILLUSION, effectPeriod.startTime, effectPeriod.endTime));
|
|
|
|
//添加毛刺特效
|
|
|
|
effectConfigList.add(new EffectConfig(EffectType.BURR, effectPeriod.startTime, effectPeriod.endTime));
|
|
|
|
//添加缩放特效
|
|
|
|
effectConfigList.add(new EffectConfig(EffectType.SCALE, effectPeriod.startTime, effectPeriod.endTime));
|
|
|
|
|
|
|
|
//生成视频
|
|
|
|
private void applyEffect() {
|
|
|
|
EffectList outPutEffectList = new EffectList();
|
|
|
|
for (EffectConfig effectConfig: effectConfigList) {
|
|
|
|
outPutEffectList.putEffect(new EffectPeriod(effectConfig.startTime, effectConfig.endTime,
|
|
|
|
EffectType.createEffect(effectConfig.effectType, null, this)));
|
|
|
|
}
|
|
|
|
CustomProgressDialog handleProgressDialog = new CustomProgressDialog(activity);
|
|
|
|
handleProgressDialog.show();
|
|
|
|
//videoPath:原视频路径 outPath:输出视频路径
|
|
|
|
new Mp4Composer(videoPath, outPath)
|
|
|
|
.frameRate(30)
|
|
|
|
.effectList(outPutEffectList)
|
|
|
|
.listener(
|
|
|
|
new Mp4Composer.Listener() {
|
|
|
|
@Override
|
|
|
|
public void onProgress(double progress) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCompleted() {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
handleProgressDialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCanceled() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailed(Exception exception) {
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
handleProgressDialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|