abc01230123abc的gravatar头像
abc01230123abc 2015-03-03 11:45:41

java使用mencoder转码视频为什么失败?

在linux中敲入命令

mencoder 1.rmvb -o 2.avi -vf scale=320:240 -oac pcm -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=500

能够转码成功

这是java代码

  String toAvi = "mencoder "
    + originPath
    + "-o "
    + aviPath
    + "-vf scale=320:240 -oac pcm -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=500";
  try {
   // Process p = Runtime.getRuntime().exec(toAvi);
   Runtime rt = Runtime.getRuntime();
   Process proc = rt.exec(toAvi);
   InputStream is = proc.getInputStream();
   final BufferedReader stdout = new BufferedReader(
     new InputStreamReader(is));
   is = proc.getErrorStream();
   final BufferedReader stderr = new BufferedReader(
     new InputStreamReader(is));
   final Vector outputLines = new Vector();
   // this deals with the output from the process in it's own thread
   Thread stdoutThread = new Thread() {
    public void run() {
     try {
      PrintWriter writer = new PrintWriter(new FileWriter(
        "log.txt"));
      int l;
      String line;
      for (l = 0; (line = stdout.readLine()) != null;) {
       if (line.length() > 0) {
        l++;
        outputLines.appendElement(line);
        // if (line.matches("Starting playback..."))
       }

      }
      System.out.println("\nRead " + l
        + " lines from stdout.");
      stdout.close();
      writer.close();
     } catch (IOException ie) {
      System.out.println("IO exception on stdout: " + ie);
     }
    }
   };
   stdoutThread.start();

   Thread stderrThread = new Thread() {
    public void run() {
     try {
      int l;
      String line;
      for (l = 0; (line = stderr.readLine()) != null;) {
       if (line.length() > 0)
        l++;
       System.out.print(",");
      }
      System.out.println("\nRead " + l
        + " lines from stderr.");
      stderr.close();
     } catch (IOException ie) {
      System.out.println("IO exception on stderr: " + ie);
     }
    }
   };
   stderrThread.start();

   System.out.println("About to waitfor");
   try {
    int exitVal = proc.waitFor();
   } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   System.out.println("Done.");

  } catch (IOException e) {
   e.printStackTrace();
   System.out.println("Exec failed. Exiting");
   System.exit(0);
   return false;
  }

  return true;

执行后,linux输出

[2015-03-03 11:14:20] [INFO] [System.out] [creat folder:/app/tongweb02/deployment/modules/cms-web/static/upload/video/origin/2015/03/03/1.rmvb]
[2015-03-03 11:14:20] [INFO] [System.out] [creat folder:/app/tongweb02/deployment/modules/cms-web/static/upload/video/flv/2015/03/03/1425352460609.flv]
[2015-03-03 11:14:20] [INFO] [System.out] [creat folder:/app/tongweb02/deployment/modules/cms-web/static/upload/video/videoTemp]
[2015-03-03 11:14:20] [INFO] [System.out] [originVideo:/app/tongweb02/deployment/modules/cms-web/static/upload/video/origin/2015/03/03/1.rmvb]
[2015-03-03 11:14:20] [INFO] [System.out] [transform video:/app/tongweb02/deployment/modules/cms-web/static/upload/video/videoTemp/1425352460776.avi]
[2015-03-03 11:14:20] [INFO] [System.out] [About to waitfor]
[2015-03-03 11:14:20] [INFO] [System.out] [
Read 0 lines from stderr.]
[2015-03-03 11:14:20] [INFO] [System.out] [
Read 2 lines from stdout.]
[2015-03-03 11:14:20] [INFO] [System.out] [Done.]
[2015-03-03 11:14:20] [INFO] [System.out] [rmvb to avi true]

并没有成功转码,在文件夹中没有视频文件,求一段java转码代码,使用mencoder的

所有回答列表(1)
abc01230123abc的gravatar头像
abc01230123abc  LV6 2015年3月3日
String getter = null;
    String toAvi = "mencoder "
      + originPath
      + " -o "
      + aviPath
      + " -vf scale=320:240 -oac pcm -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=500";
    try{
     Runtime rt = Runtime.getRuntime();
     Process proc = rt.exec(toAvi);
           BufferedReader stdout = new BufferedReader(  
                   new InputStreamReader(proc.getInputStream()));  
           String line;  
           while ((line = stdout.readLine()) != null) { 
            getter += line + ",";
               if( getter != null )  
                System.out.println(line);  
           }  
           proc.waitFor();   
           stdout.close();  
    }
    catch (Exception e) {
     e.printStackTrace();
     return false;
    }
    return true;

 

评论(0) 最佳答案
最近浏览
mutouershu  LV1 2018年1月12日
zephyry  LV3 2015年3月12日
shengke  LV17 2015年3月4日
562909048  LV10 2015年3月4日
cyzyimao  LV8 2015年3月4日
mj19910923  LV14 2015年3月4日
wfghefg  LV6 2015年3月4日
雨、小雨  LV8 2015年3月4日
lg906321  LV9 2015年3月4日
cwk1  LV1 2015年3月3日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友