截取指定时间的缩微图
ffmpeg -i test.avi -y -f image2 -ss 8 -t 0.001 -s 350x240 test.jpg
-ss后跟的时间单位为秒
http://fackyou200.iteye.com/blog/1295316
http://www.toplee.com/blog/303.html
import java.io.File;
import java.util.List;
public class TestFFmpeg {
public static String ffmpegpath = "F:\\test\\ffmpeg\\ffmpeg.exe"; // ffmpeg.exe的目录
public static String filepath = "F:\\test\\ffmpeg\\test.avi";
public static void main(String args[]) {
processImg(ffmpegpath, filepath);
}
// 将filepath 100处截取成图片
// <%=ffmpegPath%> -i <%=filepath> -y -f image2 -ss 100 -t 0.001 -s 320x240 <%=desFileName>.jpg
// ffmpeg -i test.avi -y -f image2 -ss 8 -t 0.001 -s 350x240 test.jpg
// 截图 filepath 从开始 截取2分钟的视频转换成图片 -ss 开始时间 -t结束时间 -vcodec 指定采用的编码器
// ffmpeg -i test.avi 1m%04d.jpg -vcodec mjpeg -ss 0:0:0 -t 0:2:0
// 将一段视频输出为图片序列
// ffmpeg -i 1.avi cat%d.png -vcodec png
// 参考http://os.51cto.com/art/201109/289496.htm
public static boolean processImg(String ffmpegPath, String filePath) {
File file = new File(filePath);
String desFileName = file.getPath().substring(0,
file.getPath().lastIndexOf("."));
List<String> commend = new java.util.ArrayList<String>();
commend.add(ffmpegPath);
commend.add("-i");
commend.add(filePath);
commend.add("-y");
commend.add("-f");
commend.add("image2");
commend.add("-ss");
commend.add("100");
commend.add("-t");
commend.add("0.001");
commend.add("-s");
commend.add("320x240");
commend.add(desFileName + ".jpg");
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
builder.start();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}