1,到CSDN下載: ffmpeg和mencoder命令使用的總結(超級全面)
2,兩個程序:
package national; import java.util.ArrayList; import java.util.List; public class VideoProcess { public static boolean processTransToImg2(String oldfilepath,String newfilename,String newimg){ System.out.println(oldfilepath+"->"+newfilename+"- >"+newimg); List<String> commendF = new ArrayList<String>(); List<String> commendI=new java.util.ArrayList<String>(); commendF.add("F://mencoder//summer//mencoder"); commendF.add(oldfilepath); commendF.add("-o"); commendF.add(newfilename); commendF.add("-of"); commendF.add("lavf"); commendF.add("-oac"); commendF.add("mp3lame"); commendF.add("-lameopts"); commendF.add("abr:br=32:vol=1"); commendF.add("-srate"); commendF.add("22050"); commendF.add("-ovc"); commendF.add("lavc"); commendF.add("-lavcopts"); commendF.add ("vcodec=flv:vbitrate=480:mbd=2:v4mv:turbo:vb_strategy=1:last_pred=2:trell"); commendF.add("-vf"); commendF.add("scale=400:226"); commendI.add("F://mencoder//summer//ffmpeg.exe"); commendI.add("-i"); commendI.add(oldfilepath); commendI.add("-y"); commendI.add("-f"); commendI.add("image2"); commendI.add("-ss"); commendI.add("8"); commendI.add("-t"); commendI.add("0.001"); commendI.add("-s"); commendI.add("100x100"); commendI.add(newimg); try { ProcessClass.exec(commendF); ProcessClass.exec(commendI); return true; } catch (Exception e) { e.printStackTrace(); return false; } } public static void main(String[] args){ String oldfilepath = "f://shanghaitan.rm"; String newfilename = "f://shanghaitan.flv"; String newimg = "f://shanghaitan.jpg"; System.out.println("--------------"); processTransToImg2(oldfilepath,newfilename,newimg); System.out.println("over"); } } --------------------- package national; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class ProcessClass{ public List<String> commendList = new ArrayList<String>(); public ProcessClass(List<String> commendList){ this.commendList = commendList; } //同步使只能有一個進程執行該方法(實現格式轉換進程完成後執行截圖進程操作) public static synchronized Process exec(List<String> commendlist){ StringBuffer strBuf = new StringBuffer(); for(Iterator iter =commendlist.iterator();iter.hasNext(); ){ String Strtemp = (String)iter.next(); strBuf.append(Strtemp); strBuf.append(" "); } try { return Runtime.getRuntime().exec(strBuf.toString()); } catch (IOException e) { e.printStackTrace(); return null; } } }