zhanghenanjuly 发表于 2013-2-4 19:24:38

如何才能获取到Process

public class ConvertVideo {

private static String INPUT_PATH;   
    private static String OUTPUT_PATH;   
    private static String PROJECT_PATH;   
    private static HashMap<String, String> fileType;   
      
    static
    {   
      fileType = new HashMap<String, String>();   
      fileType.put("avi", "true");   
      fileType.put("mpg", "true");   
      fileType.put("wmv", "true");   
      fileType.put("3gp", "true");   
      fileType.put("mov", "true");   
      fileType.put("mp4", "true");   
      fileType.put("asf", "true");   
      fileType.put("asx", "true");   
       fileType.put("flv", "true");   
    }   
      
    public static void convertToFLV(String projectPath, String inputFile, String outputFile)   
    {   
      INPUT_PATH = inputFile;   
      OUTPUT_PATH = outputFile;   
      PROJECT_PATH = projectPath;   
      if (checkContentType())   
            processFLV();// 直接将文件转为flv文件   
    }   

    private static boolean checkContentType()   
    {   
      String type = INPUT_PATH.substring(INPUT_PATH.lastIndexOf(".") + 1, INPUT_PATH.length()).toLowerCase();   
      // ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)   
      return "true".equals(fileType.get(type));   
    }   

    private static void processFLV()   
   {   
      if (new File(INPUT_PATH).isFile())   
      {   
            try
            {   
                String cmd = "cmd /c start F:\\project\\abc\\ffmpeg.bat \"" + PROJECT_PATH + "\" \"" + INPUT_PATH + "\" \"" + OUTPUT_PATH +"\"";   
                System.out.println(cmd);
                Process process = Runtime.getRuntime().exec(cmd);
                InputStream is = process.getInputStream();
                BufferedInputStream bis = new BufferedInputStream(is);
                System.out.println(bis);
                int data;
                while((data=bis.read())!=-1){
                System.out.println(data);
                }
                if(data==-1){
                System.out.println("data==null");
                }
            }   
            catch (Exception e)   
            {   
               e.printStackTrace();   
            }   
      }   
    }
    public static void main(String[] args)   
    {   
      ConvertVideo.convertToFLV("F:\\project\\abc" ,"c:\\3.mpg", "f:\\03.mpg");   
    }

}

用ffmpeg为视频添加logo,但是始终获取不到process的值?转出来的文件确定是有logo的。
页: [1]
查看完整版本: 如何才能获取到Process