... | ... | @@ -305,4 +305,127 @@ ShortVideoHelper.changeVideoSize(context, srcVideoPath, destPath, videoWidth, vi |
|
|
|
|
|
}
|
|
|
});
|
|
|
``` |
|
|
\ No newline at end of file |
|
|
```
|
|
|
|
|
|
## 4.9 图片合成视频
|
|
|
|
|
|
为图片设置展示时长。
|
|
|
```
|
|
|
//单位:毫秒
|
|
|
image.setImageTime(int time);
|
|
|
```
|
|
|
|
|
|
为图片设置动画效果。
|
|
|
```
|
|
|
//animType=0:无动画效果,animType=1:放大 ,animType=2:缩小,animType=3:左滑,animType=4:右滑
|
|
|
image.setImageAnimType(int animType);
|
|
|
```
|
|
|
|
|
|
设置转场效果。
|
|
|
```
|
|
|
//transitionType=0:无转场,transitionType=1:重叠,transitionType=2:闪黑,transitionType=3:闪白,transitionType=4:圆形
|
|
|
image.setTransitionType(int transitionType);
|
|
|
```
|
|
|
|
|
|
设置转场时长。
|
|
|
```
|
|
|
//单位:毫秒
|
|
|
image.setTransitionTime(int time);
|
|
|
```
|
|
|
|
|
|
生成预览视频。
|
|
|
```
|
|
|
/**
|
|
|
* @param context 上下文
|
|
|
* @param selectedImages 图片集合
|
|
|
*/
|
|
|
ImagesVideo imagesVideo = ImagesToVideoHelper.makeImagesVideo(activity, selectedImages);
|
|
|
```
|
|
|
|
|
|
//播放预览视频
|
|
|
```
|
|
|
SurfaceImagesVideoRenderer surfaceImagesVideoRenderer = new TextureImagesVideoRender(ivTextureView);
|
|
|
ImagesVideoPlayer imagesVideoPlayer = new ImagesVideoPlayer(activity);
|
|
|
imagesVideoPlayer.setImagesVideoRenderer(surfaceImagesVideoRenderer);
|
|
|
imagesVideoPlayer.setImagesVideoListener(this);
|
|
|
imagesVideoPlayer.setLoop(true);
|
|
|
imagesVideoPlayer.setDataSource(imagesVideo);
|
|
|
imagesVideoPlayer.prepare();
|
|
|
imagesVideoPlayer.setOnPreparedListener(new ImagesVideoPlayer.OnPreparedListener() {
|
|
|
@Override
|
|
|
public void onPreparing(ImagesVideoPlayer imagesPlayer, float progress) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onPrepared(ImagesVideoPlayer imagesPlayer, int prepared, int total) {
|
|
|
activity.runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
isPrepared = true;
|
|
|
imagesVideoPlayer.start();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(ImagesVideoPlayer imagesPlayer) {
|
|
|
|
|
|
}
|
|
|
});
|
|
|
|
|
|
```
|
|
|
|
|
|
控制播放器暂停、播放、滑动。
|
|
|
```
|
|
|
//播放
|
|
|
imagesVideoPlayer.start();
|
|
|
|
|
|
//暂停
|
|
|
imagesVideoPlayer.pause();
|
|
|
|
|
|
//滑动
|
|
|
imagesVideoPlayer.seekTo(int pos);
|
|
|
```
|
|
|
|
|
|
播放界面销毁时,销毁播放器。
|
|
|
```
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
if (imagesVideoPlayer != null) {
|
|
|
imagesVideoPlayer.destroy();
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
|
|
|
将图片合成视频。
|
|
|
```
|
|
|
ImagesVideoMaker imagesVideoMaker = new ImagesVideoMaker(activity);
|
|
|
/**
|
|
|
* @param width 视频宽度
|
|
|
* @param height 视频高度
|
|
|
* @param frameRate 帧率
|
|
|
* @param bitRate 比特率
|
|
|
* @param iFrameInterval 关键帧间隔
|
|
|
* @param outputPath 输出路径
|
|
|
*/
|
|
|
imagesVideoMaker.setConfig(int width, int height, int frameRate, int bitRate, int iFrameInterval, String outputPath);
|
|
|
ImagesVideo newImagesVideo = ImagesToVideoHelper.makeImagesVideo(activity, selectedImages);
|
|
|
SurfaceImagesVideoRenderer videoRenderer = new SurfaceImagesVideoRenderer(surfaceImagesVideoRenderer);
|
|
|
videoRenderer.setImagesVideo(newImagesVideo);
|
|
|
imagesVideoMaker.setDataSource(videoRenderer);
|
|
|
imagesVideoMaker.startMake(new ImagesVideoMaker.OnMakeListener() {
|
|
|
@Override
|
|
|
public void onMakeFinish(boolean success) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onMakeProgress(int makedDuration, int totalDuration) {
|
|
|
|
|
|
}
|
|
|
});
|
|
|
|
|
|
```
|
|
|
|