ffmpeg视频转换及截图
视频转码:
List<String> commend = new java.util.ArrayList<String>();
commend.add(ffmpeg硬盘路径);
commend.add("-i");
commend.add(转码文件硬盘路径);
commend.add("-y");
commend.add("-ar");
commend.add("22050");
commend.add("-s");
commend.add("480*360"); //转换后的视频大小
commend.add("-b");
commend.add("1000");
commend.add("-qscale");
commend.add("4");
commend.add("-ab");//音质设置,越大音质越好,但文件也会变大
commend.add("56");
commend.add(输出文件路径);
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
builder.redirectErrorStream(true);
System.out.println("视频转码开始...");
// builder.start();
Process process = builder.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
System.out.print("正在进行转码,请稍候");
while (in.read(re) != -1) {
System.out.print(".");
}
System.out.println("");
in.close();
System.out.println("视频转码完成...");
} catch (Exception e) {
e.printStackTrace();
System.out.println("视频转码失败!");
}
视频截图:
List<String> commend = new java.util.ArrayList<String>();
commend.add(ffmpeg文件硬盘路径);
commend.add("-i");
commend.add(待截图文件硬盘路径);
commend.add("-y");
commend.add("-f");
commend.add("image2");
commend.add("-ss");
commend.add("8"); //在视频的某个插入时间截图,例子为8秒后
commend.add("-t");
commend.add("0.001");
commend.add("-ab");//音质设置,越大音质越好,但文件也会变大
commend.add("56");
commend.add("-s");
commend.add("350*240"); //截图后的图片大小
commend.add(截图的图片保存路径);
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
builder.redirectErrorStream(true);
System.out.println("视频截图开始...");
// builder.start();
Process process = builder.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
System.out.print("正在进行截图,请稍候");
while (in.read(re) != -1) {
System.out.print(".");
}
System.out.println("");
in.close();
System.out.println("视频截图完成...");
} catch (Exception e) {
e.printStackTrace();
System.out.println("视频截图失败!");
}
windows下用ffmpeg.exe下载路径http://ffmpeg.zeranoe.com/builds/ 自己选择32位或64位