public static void main(String[] args) {
ããString result = processFLV("E:\\test\\京è§ä¼ åª\\ä½è²ç±»\\xiao.flv");
ããPatternCompiler compiler =new Perl5Compiler();
ããtry {
ããString regexDuration ="Duration: (.*?), start: (.*?), bitrate: (\\d*) kb\\/s";
ããString regexVideo ="Video: (.*?), (.*?), (.*?)[,\\s]";
ããString regexAudio ="Audio: (\\w*), (\\d*) Hz";
ããPattern patternDuration = compiler.compile(regexDuration,Perl5Compiler.CASE_INSENSITIVE_MASK);
ããPatternMatcher matcherDuration = new Perl5Matcher();
ããif(matcherDuration.contains(result, patternDuration)){
ããMatchResult re = matcherDuration.getMatch();
ããSystem.out.println("æååºææ¾æ¶é´ ===" +re.group(1));
ããSystem.out.println("å¼å§æ¶é´ =====" +re.group(2));
ããSystem.out.println("bitrate ç ç åä½ kb==" +re.group(3));
ãã}
ããPattern patternVideo = compiler.compile(regexVideo,Perl5Compiler.CASE_INSENSITIVE_MASK);
ããPatternMatcher matcherVideo = new Perl5Matcher();
ããif(matcherVideo.contains(result, patternVideo)){
ããMatchResult re = matcherVideo.getMatch();
ããSystem.out.println("ç¼ç æ ¼å¼ ===" +re.group(1));
ããSystem.out.println("è§é¢æ ¼å¼ ===" +re.group(2));
ããSystem.out.println(" å辨ç == =" +re.group(3));
ãã}
ããPattern patternAudio = compiler.compile(regexAudio,Perl5Compiler.CASE_INSENSITIVE_MASK);
ããPatternMatcher matcherAudio = new Perl5Matcher();
ããif(matcherAudio.contains(result, patternAudio)){
ããMatchResult re = matcherAudio.getMatch();
ããSystem.out.println("é³é¢ç¼ç ===" +re.group(1));
ããSystem.out.println("é³é¢éæ ·é¢ç ===" +re.group(2));
ãã}
ãã} catch (MalformedPatternException e) {
ããe.printStackTrace();
ãã}
ãã}
ãã// ffmpegè½è§£æçæ ¼å¼ï¼ï¼asxï¼asfï¼mpgï¼wmvï¼3gpï¼mp4ï¼movï¼aviï¼flvçï¼
ããprivate static String processFLV(String inputPath) {
ãã/*
ããif (!checkfile(inputPath)){
ãã_log.warn(inputPath+" is not file");
ããreturn false;
ãã}
ãã*/
ããList<String> commend=new java.util.ArrayList<String>();
ãã// commend.add("e:\\videoconver\\ffmpeg\\ffmpeg ");//å¯ä»¥è®¾ç½®ç¯å¢åéä»èçå»è¿è¡
ããcommend.add("ffmpeg");
ããcommend.add("-i");
ããcommend.add(inputPath);
ããtry {
ããProcessBuilder builder = new ProcessBuilder();
ããbuilder.command(commend);
ããbuilder.redirectErrorStream(true);
ããProcess p= builder.start();
ãã//1. start
ããBufferedReader buf = null; // ä¿åffmpegçè¾åºç»ææµ
ããString line = null;
ãã//read the standard output
ããbuf = new BufferedReader(new InputStreamReader(p.getInputStream()));
ããStringBuffer sb= new StringBuffer();
ããwhile ((line = buf.readLine()) != null) {
ããSystem.out.println(line);
ããsb.append(line);
ããcontinue;
ãã}
ããint ret = p.waitFor();//è¿é线ç¨é»å¡ï¼å°çå¾
å¤é¨è½¬æ¢è¿ç¨è¿è¡æåè¿è¡ç»æåï¼æå¾ä¸æ§è¡
ãã//1. end
ããreturn sb.toString();
ãã} catch (Exception e) {
ãã// System.out.println(e);
ããreturn null;
ãã}
ãã}
温馨提示:答案为网友推荐,仅供参考