java 解析mediainfo获得的视频参数
public static LinkedHashMap<String,String> getVideoPrifilesMap(String filePath) {String enter = "\n\n";String separator = " : ";String allParams = getVideoProfilesByParams(filePath); LinkedHashMap<String, String> resultsMap = new LinkedHashMap<String, String>(); if(allParams.equals("") == false ){String[] results = allParams.split(enter);for (String part : results) {int index = part.indexOf("\n");String prefix = part.substring(0, index);String fragment = part.substring(index);String[] fragmentArray = fragment.split("\n");for (String subFragment : fragmentArray) {String[] stringArray = subFragment.split(separator);if (stringArray.length > 1) {resultsMap.put(prefix + StringPool.UNDERLINE+stringArray[0].trim(), stringArray[1].trim());}}}}return resultsMap;} private static String getVideoProfilesByParams(String inputPath) { List<String> commend=new java.util.ArrayList<String>(); // mediainfo --Inform="Video;%Duration%" 20110530.mp4 commend.add("mediainfo"); commend.add(inputPath); try {// _log.debug("commend=="+commend.toString()); ProcessBuilder builder = new ProcessBuilder(); builder.command(commend); builder.redirectErrorStream(true); Process p= builder.start(); //1. start BufferedReader buf = null; String line = null; //read the standard output buf = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder sbu = new StringBuilder(); while ((line = buf.readLine()) != null) { sbu.append(line); sbu.append("\n"); } p.waitFor(); return sbu.toString(); } catch (Exception e) { _log.error(e); } return ""; }
?
?
?