天天看點

mencoder轉換的flv不能用flvplayer播放

用mencoder轉換成.flv後用一般的播放器是可以播放的, 可是使用flvplayer無法播放...

問題方向比較明确.是指令的問題...

正确的轉換指令如下, 測試--可以用flvplayer播放.

  /** 

    * 使用mencoder轉碼 

    * @param videoPath 源路徑 -- 要轉換的視訊檔案 

    * @param targetPath 目标路徑 -- 轉換後的視訊flv 

    * @return 傳回目标路徑 

    */ 

  public    String mencoderTransVideo() { 

    List<String> commend = new java.util.ArrayList<String>(); 

    commend.add("d:\\flv\\MediaCoder\\codecs\\mencoder.exe");    

    commend.add(videoPath); 

    commend.add("-of"); 

    commend.add("lavf"); 

    commend.add("-oac"); 

    commend.add("mp3lame"); 

    commend.add("-lameopts"); 

    commend.add("abr:br=56"); 

    commend.add("-ovc"); 

    commend.add("lavc"); 

    commend.add("-lavcopts"); 

    commend.add("vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:dia=4:cmp=6:vb_strategy=1"); 

    commend.add("-vf"); 

    commend.add("scale=512:-3"); 

    commend.add("-ofps"); 

    commend.add("12"); 

    commend.add("-srate"); 

    commend.add("22050"); 

    commend.add("-o"); 

    commend.add(ChineseSpelling.getInstance().getSelling(targetPath)); 

    try { 

      ProcessBuilder builder = new ProcessBuilder(); 

      builder.command(commend); 

      Process process = builder.start(); 

      /** 

        * 同時清空mencoder的錯誤流緩沖區和輸出緩沖區(防止線程阻塞--停掉tomcat才能轉碼) 

        */ 

      final InputStream is1 = process.getInputStream(); 

      new Thread(new Runnable() { 

             public void run() { 

                     BufferedReader br = new BufferedReader(new InputStreamReader(is1));    

            try { 

              while(br.readLine() != null) ; 

            } catch (IOException e) { 

              e.printStackTrace(); 

            } 

             } 

      }).start(); // 啟動單獨的線程來清空process.getInputStream()的緩沖區 

      InputStream is2 = process.getErrorStream(); 

      BufferedReader br2 = new BufferedReader(new InputStreamReader(is2));    

      StringBuilder buf = new StringBuilder(); // 儲存輸出結果流 

      String line = null; 

      while((line = br2.readLine()) != null) buf.append(line);    

      return targetPath; 

    } catch (Exception e) { 

      e.printStackTrace(); 

      return null; 

    } 

  }

 本文轉自chainli 51CTO部落格,原文連結:http://blog.51cto.com/lichen/163836,如需轉載請自行聯系原作者

繼續閱讀