public static void coverterVideo(String in, String out, Integer[] times) {
String prfix_ffmpeg = Contants.getRes("FFMPEG_PATH");
StringBuilder commond = new StringBuilder();
commond.append(prfix_ffmpeg);
commond.append(" -i ");
commond.append(in);
commond.append(" -vcodec copy -acodec copy -f mp4 ");
commond.append(out);
System.out.println(commond.toString());
Process pro = null;
Process pro1 = null;
try {
if(!new File(out).exists()){
System.out.println("***********coverter begin*********");
pro = Runtime.getRuntime().exec(commond.toString());
System.out.println("***********"
+ new SimpleDateFormat("yy-MM-dd HH:MM:ss")
.format(new Date()) + "***********");
doWaitFor(pro);
System.out.println("***********"
+ new SimpleDateFormat("yy-MM-dd HH:MM:ss")
.format(new Date()) + "***********");
System.out.println("**********coverter finished!!!*********");
}
// pro.destroy();
if(new File(out).exists()){
System.out.println("*********************截图开始***********************");
// for(Integer mm : videoTimes){ //videoTimes 时间数组
// StringBuilder commond1 = new StringBuilder();
// commond1.append(prfix_ffmpeg);
// commond1.append(" -i ");
// commond1.append(out);
// commond1.append(" -y -f image2 -ss ");
// commond1.append(mm);
// commond1.append(" -vframes 1 ");
// commond1.append("-s 350*240 ");
// commond1.append("D:/SOFT/ffmpeg/imgs/");
// commond1.append(mm);
// commond1.append(".jpg");
// pro1 = Runtime.getRuntime().exec(commond1.toString());
// doWaitFor(pro1);
// }
System.out.println("*********************截图结束***********************");
}
} catch (Exception e) {
e.printStackTrace();
try {
pro.getErrorStream().close();
pro.destroy();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}ffmpeg 视频转换、图片批量提取
最新推荐文章于 2025-09-05 09:50:49 发布
该博客介绍了一个使用Java调用ffmpeg命令行工具进行视频转换和批量提取图片的方法。通过指定输入视频路径、输出视频路径以及时间点,实现了视频格式转换;同时,根据时间数组,提取了相应帧数的图片并保存为指定尺寸的jpg格式。
920

被折叠的 条评论
为什么被折叠?



