六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 11|回复: 0

如何才能获取到Process

[复制链接]

升级  30%

3

主题

3

主题

3

主题

童生

Rank: 1

积分
15
 楼主| 发表于 2013-2-4 19:24:38 | 显示全部楼层 |阅读模式
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的。
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表