话不多说,上代码
Scanner scanner = new Scanner(System.in);
System.out.println("请输入图片位置:");
String charImagePath = scanner.nextLine();
// 需要原视频配合,负责生成出来的视频和原视频画面对不上
System.out.println("请输入参考视频地址位置:");
String sourceVideolUrl = scanner.nextLine();
System.out.println("请输入新视频存储位置:");
String targetVideoUrl = scanner.nextLine();
// 图片生成视频
//读取所有图片
File file = new File(charImagePath);
File[] charImageFiles = file.listFiles();
Map<Integer, File> imgMap = new HashMap<Integer, File>();
for (File imgFile : charImageFiles) {
String imageName = imgFile.getName();
int num = Integer.parseInt( imageName.substring(0, imageName.lastIndexOf(".")));
imgMap.put(num, imgFile);
}
try {
Util.imageTovideo(sourceVideolUrl,targetVideoUrl,imgMap);
} catch (FFmpegFrameRecorder.Exception e) {
e.printStackTrace();
}
资源下载
Java将图片转为视频
懒得下载或网络不好的,直接可去下方下载maven依赖包,放到本地的maven仓库即可
下载maven