public class TestVedio { public static boolean process(String resourcePath) { int type = checkContentType(resourcePath); boolean status = false; if (type == 0) { status = processFLV(resourcePath);// 直接将文件转为flv文件 } return status; }
private static int checkContentType(String resourcePath) { String type = resourcePath.substring(resourcePath.lastIndexOf(".") + 1, resourcePath.length()).toLowerCase(); // ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等) if (type.equals("avi")) { return 0; } else if (type.equals("mpg")) { return 0; } else if (type.equals("wmv")) { return 0; } else if (type.equals("3gp")) { return 0; } else if (type.equals("mov")) { return 0; } else if (type.equals("mp4")) { return 0; } else if (type.equals("asf")) { return 0; } else if (type.equals("asx")) { return 0; } else if (type.equals("flv")) { return 0; } else if (type.equals("mpeg")) { return 0; } else if (type.equals("mpe")) { return 0; } // 对ffmpeg无法解析的文件格式(wmv9,rm,rmvb等), // 可以先用别的工具(mencoder)转换为avi(ffmpeg能解析的)格式. else if (type.equals("wmv9")) { return 1; } else if (type.equals("rm")) { return 1; } else if (type.equals("rmvb")) { return 1; } return 9; }
private static boolean checkfile(String path) { File file = new File(path); if (!file.isFile()) { return false; } return true; }
public static void main(String[] args) { if (!checkfile("e:\\hibernate1.avi")) { System.out.println("" + " is not file"); return; } if (process("e:\\hibernate1.avi")) { System.out.println("ok"); } } }