rt

解决方案 »

  1.   

    package com.lgh.struts.util;import java.io.BufferedReader;
    import java.io.File;
    import java.io.InputStream;
    import java.io.InputStreamReader;public class ConvertVideo {
     
     public static boolean process(String PATH,String filename) {       
      int type = checkContentType(PATH);
            boolean status = false;
            if (type==0) {
                status = processFLV(PATH,filename);// 直接将文件转为flv文件           
            } else if (type==1) {
                String avifilepath = processAVI(type,PATH,filename);
                if (avifilepath == null)
                     return false;// avi文件没有得到
                status = processFLV(avifilepath,filename);// 将avi转为flv
            }
            return status;
        }
        private static int checkContentType(String PATH) {
            String type = PATH.substring(PATH.lastIndexOf(".") + 1,
              PATH.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;
            }
            //对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;
        }
    //  对ffmpeg无法解析的文件格式(wmv9,rm,rmvb等), 可以先用别的工具(mencoder)转换为avi(ffmpeg能解析的)格式.
        private static String processAVI(int type,String PATH,String filename) {
         long lasting = System.currentTimeMillis();
         String pathto = Community.webpath.replace("/", "\\")+"vedioavi\\"+filename+".avi";
         String pathfrom = PATH.replace("/", "\\");
        
            String patht = Community.webpath.replace("/", "\\")+"jmq\\WisMencoder\\mencoder.exe ";
          String commend=null;
            commend= patht+" -noodml "+pathfrom+" -subcp cp936 -font simhei.ttf -subfont-text-scale 4 -o "+pathto+" -ofps 20.000 -vf-add scale=640:-2 -ovc xvid -xvidencopts bitrate=500 -srate 44100 -oac mp3lame -lameopts vbr=0 -lameopts br=128 -lameopts vol=0 -lameopts mode=0 -lameopts aq=7 -lameopts padding=3 -af volnorm -xvidencopts max_bframes=0:nogmc:noqpel  ";
           
       
            try{
               Runtime   rt   =   Runtime.getRuntime();   
               Process   proc = rt.exec(commend);
                new process(proc.getInputStream(),"INFO").start();
          
          new process(proc.getErrorStream(),"ERROR").start();
          
          int status = proc.waitFor();
          
          if (status == 0)
           System.out.println("执行完毕");
          else
           System.out.println("执行失败");
                  
               
                System.out.println("转换avi运行时间:" + (System.currentTimeMillis() - lasting)
         + "毫秒");
                return pathto;
            }catch(Exception e){
             e.printStackTrace();
             return null;
            }
        }
    //  ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
        private static boolean processFLV(String oldfilepath,String filename) {
         long lasting = System.currentTimeMillis();
         String path = Community.webpath.replace("/", "\\")+"vedioflv\\";
            String commend="";
            commend+=Community.webpath.replace("/", "\\")+"jmq\\Libs\\ffmpeg.exe ";
            commend+="-i ";
            commend+=oldfilepath;
            commend+=" -ar ";
            commend+="22050 ";
            commend+="-ab ";
            commend+="56 ";
            commend+="-f ";
            commend+="flv -qscale 6 ";
            commend+="-y ";
            commend+="-b ";
            commend+="320x240 ";
            commend+=" "+path+filename+".flv";
            try {
               Runtime   rt   =   Runtime.getRuntime();   
             Process   proc = rt.exec(commend);
             new process(proc.getInputStream(),"INFO").start();
       
       new process(proc.getErrorStream(),"ERROR").start();
       
       int status = proc.waitFor();
       
       if (status == 0)
        System.out.println("执行完毕");
       else
        System.out.println("执行失败");   
                System.out.println("转换flv运行时间:" + (System.currentTimeMillis() - lasting)
         + "毫秒");
              /*  ProcessBuilder builder = new ProcessBuilder();
                builder.command(commend);
                builder.start();*/
                
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }
     
    }
      

  2.   

    你的去下载个转换器。
    String patht = Community.webpath.replace("/", "\\")+"jmq\\WisMencoder\\mencoder.exe ";
      

  3.   

    http://www.onlinedown.net/soft/96317.htm
    下载一个flv视频转换器就可以了。