/** * 获取视频长度,生成缩略图 * */ public static int createThumb(String videoPath, String thumbPath) { //System.out.println(System.getProperty("java.home")); //FFMPEG_PATH = System.getProperty("user.dir")+"/WebRoot/WEB-INF/plugin/ffmpeg/ffmpeg.exe"; try { /** * 获取视频时长,不需要的话可以只留 Runtime.getRunti... 一句 * */ int time = Integer.valueOf(CtrlFtpFile.getMediaTime(videoPath)); if(time<=0) throw new IOException("长度过短"); Runtime.getRuntime().exec(getCmdStr(videoPath, thumbPath)); return time; } catch (IOException e) { e.printStackTrace(); return 0; } } public static void main(String[] args) throws Exception { System.out.println(createThumb("F:\\aaa.rmvb" , "F:\\b.jpg")); } /** * ffmpeg 地址 * */ private static String FFMPEG_PATH = "D:/ffmpeg/ffmpeg.exe"; /** * 生成 CMD 命令 * */ private static String getCmdStr(String videoPath ,String thumbPath) { return FFMPEG_PATH + " -i " + videoPath + " -ss 0.5 -vframes 1 -r 1 -ac 1 -ab 2 -s 160*120 -f image2 " + thumbPath; }
将下包里的 dll 放进 jre(jdk)/bin里,如果仅获取视频长度,可以不放。
注:该dll来自 http://jatula.javaeye.com/