|
|
|
## 4.1 录制视频
|
|
|
|
|
|
|
|
开始录制
|
|
|
|
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
* 开始录制
|
|
|
|
*
|
|
|
|
* @param width
|
|
|
|
* @param height
|
|
|
|
* @param outPutPath
|
|
|
|
*/
|
|
|
|
public void startRecord(int width, int height, String outPutPath) {
|
|
|
|
PreviewRecorder.getInstance()
|
|
|
|
.setRecordType(PreviewRecorder.RecordType.Video)
|
|
|
|
.setOutputPath(outPutPath)
|
|
|
|
.enableAudio(true)
|
|
|
|
.setRecordSize(width, height)
|
|
|
|
.setOnRecordListener(this)
|
|
|
|
.startRecord();
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
停止录制
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
* 停止录制
|
|
|
|
*/
|
|
|
|
public void stopRecord() {
|
|
|
|
PreviewRecorder.getInstance().stopRecord();
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
合并视频
|
|
|
|
```
|
|
|
|
PreviewRecorder.getInstance().combineVideo(videoPath, mCombineListener);
|
|
|
|
|
|
|
|
// 合成监听器
|
|
|
|
private VideoCombiner.CombineListener mCombineListener = new VideoCombiner.CombineListener() {
|
|
|
|
@Override
|
|
|
|
public void onCombineStart() {
|
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
MultiUtils.showToast(activity, "正在合成视频,请稍候");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCombineProcessing(final int current, final int sum) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCombineFinished(final boolean success) {
|
|
|
|
startEdit();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
## 4.2 摄像头切换
|
|
|
|
|
|
|
|
```
|
|
|
|
public void switchCamera() {
|
|
|
|
PreviewRenderer.getInstance().switchCamera();
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 4.3 视频美颜
|
|
|
|
|
|
|
|
```
|
|
|
|
//添加磨皮
|
|
|
|
VideoClipper addBeautySkin = new VideoClipper();
|
|
|
|
addBeautySkin.setInputVideoPath(videoPath);
|
|
|
|
String outputPath = MultiUtils.getOutPutVideoPath();
|
|
|
|
BeautySkinAdjust beautySkinAdjust = new BeautySkinAdjust(beautySkinValue);
|
|
|
|
addBeautySkin.setBeautySkinAdjust(beautySkinAdjust);
|
|
|
|
addBeautySkin.setOutputVideoPath(outputPath);
|
|
|
|
try {
|
|
|
|
addBeautySkin.clipVideo(0, videoDuration * 1000);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
addBeautySkin.setOnVideoCutFinishListener(new VideoClipper.OnVideoCutFinishListener() {
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//添加美白
|
|
|
|
VideoClipper addBeautyWhite = new VideoClipper();
|
|
|
|
addBeautyWhite.setInputVideoPath(videoPath);
|
|
|
|
String outputPath = MultiUtils.getOutPutVideoPath();
|
|
|
|
BeautyWhiteAdjust beautyWhiteAdjust = new BeautyWhiteAdjust(beautyWhiteValue);
|
|
|
|
addBeautyWhite.setBeautyWhiteAdjust(beautyWhiteAdjust);
|
|
|
|
addBeautyWhite.setOutputVideoPath(outputPath);
|
|
|
|
try {
|
|
|
|
addBeautyWhite.clipVideo(0, videoDuration * 1000);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
addBeautyWhite.setOnVideoCutFinishListener(new VideoClipper.OnVideoCutFinishListener() {
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
## 4.4 视频滤镜
|
|
|
|
|
|
|
|
```
|
|
|
|
VideoClipper addFilter = new VideoClipper();
|
|
|
|
addFilter.setInputVideoPath(videoPath);
|
|
|
|
String outputFilterPath = MultiUtils.getOutPutVideoPath();
|
|
|
|
addFilter.setFilterType(filterType);
|
|
|
|
addFilter.setOutputVideoPath(outputFilterPath);
|
|
|
|
try {
|
|
|
|
addFilter.clipVideo(0, videoDuration * 1000);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
addFilter.setOnVideoCutFinishListener(new VideoClipper.OnVideoCutFinishListener() {
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
## 4.5 视频剪辑
|
|
|
|
|
|
|
|
支持剪辑视频画面大小和时长。
|
|
|
|
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
* @param context 上下文
|
|
|
|
* @param srcVideoPath 输入视频路径
|
|
|
|
* @param destPath 输出视频路径
|
|
|
|
* @param startPosition 开始裁剪的位置 单位:毫秒
|
|
|
|
* @param endPosition 结束裁剪的位置 单位:毫秒
|
|
|
|
* @param width 输出的视频宽度
|
|
|
|
* @param height 输出的视频高度
|
|
|
|
* @param x X轴偏移位置
|
|
|
|
* @param y y轴偏移位置
|
|
|
|
* @param listener 处理过程回调
|
|
|
|
*/
|
|
|
|
ShortVideoHelper.cutVideo(context, srcVideoPath, destPath, startPosition, endPosition, width, height, x, y, new HandleProcessListener() {
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFail(int errorCode, String msg) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
## 4.6 视频变速
|
|
|
|
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
* @param context 上下文
|
|
|
|
* @param srcVideoPath 输入视频路径
|
|
|
|
* @param destPath 输出视频路径
|
|
|
|
* @param speed 变速倍率 取值0.5f~2.0f
|
|
|
|
* @param listener 处理过程回调
|
|
|
|
*/
|
|
|
|
ShortVideoHelper.changeVideoSpeed(context, srcVideoPath, destPath, speed, new HandleProcessListener() {
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFail(int errorCode, String msg) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 4.7 添加音乐、贴纸和气泡文字
|
|
|
|
添加音乐时要先通过MusicSet类进行音乐设置。
|
|
|
|
```
|
|
|
|
MusicSet musicSet = null;
|
|
|
|
if (isAddMusic) {
|
|
|
|
musicSet = new MusicSet();
|
|
|
|
int startMusicPos = startCutMusicPosition / 1000;
|
|
|
|
//设置音乐路径
|
|
|
|
musicSet.setMusicPath(bacMusicPath);
|
|
|
|
//设置音乐开始的位置,单位:秒
|
|
|
|
musicSet.setStartMusicPos(startMusicPos);
|
|
|
|
//原声大小 0.0~1.0f
|
|
|
|
musicSet.setOriginVolume(originVolume);
|
|
|
|
//音乐大小 0.0~1.0f
|
|
|
|
musicSet.setMusicVolume(musicVolume);
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
添加贴纸和气泡文字时,通过StickerSet进行贴纸和气泡文字设置。
|
|
|
|
```
|
|
|
|
List<StickerSet> stickerSets = new ArrayList<>();
|
|
|
|
StickerSet stickerSet = new StickerSet();
|
|
|
|
//设置贴纸和气泡文字开始显示的时间,单位:秒
|
|
|
|
stickerSet.setStartShowTime(sticker.getStartShowTime());
|
|
|
|
//设置贴纸和气泡文字结束显示的时间,单位:秒
|
|
|
|
stickerSet.setEndShowTime(sticker.getEndShowTime());
|
|
|
|
//设置X轴偏移位置
|
|
|
|
stickerSet.setxOffSet(xOffSet);
|
|
|
|
//设置y轴偏移位置
|
|
|
|
stickerSet.setyOffSet(yOffSet);
|
|
|
|
//设置贴纸和气泡文字路径
|
|
|
|
stickerSet.setStickerPath(stickerPath);
|
|
|
|
stickerSets.add(stickerSet);
|
|
|
|
```
|
|
|
|
只添加音乐时,传入参数musicSet,stickerSets传入参数null。只添加贴纸和气泡文字时,传入参数stickerSets,musicSet传入参数null。同时添加音乐、贴纸和气泡文字时,传入参数stickerSets和musicSet。
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
* @param context 上下文
|
|
|
|
* @param srcVideoPath 输入视频路径
|
|
|
|
* @param destPath 输出视频路径
|
|
|
|
* @param musicSet 音乐设置
|
|
|
|
* @param stickerSets 贴纸和气泡设置
|
|
|
|
* @param listener 处理监听器
|
|
|
|
*/
|
|
|
|
ShortVideoHelper.AddMusicAndSticker(context, srcVideoPath, destPath, musicSet, null, new HandleProcessListener() {
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFail(int errorCode, String msg) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 4.8 为视频添加黑边合成新视频
|
|
|
|
```
|
|
|
|
/**
|
|
|
|
* @param context 上下文
|
|
|
|
* @param srcVideoPath 输入视频路径
|
|
|
|
* @param destPath 输出视频路径
|
|
|
|
* @param videoWidth 输入视频宽度
|
|
|
|
* @param videoHeight 输入视频高度
|
|
|
|
* @param destVideoWidth 输出视频宽度
|
|
|
|
* @param destVideoHeight 输出视频高度
|
|
|
|
* @param listener 处理监听器
|
|
|
|
*/
|
|
|
|
|
|
|
|
ShortVideoHelper.changeVideoSize(context, srcVideoPath, destPath, videoWidth, videoHeight, 720, 1280, new HandleProcessListener() {
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFail(int errorCode, String msg) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
``` |
|
|
|
\ No newline at end of file |