67,513
社区成员
发帖
与我相关
我的任务
分享
// 对ffmpeg无法解析的文件格式(wmv9,rm,rmvb等), 可以先用别的工具(mencoder)转换为avi(ffmpeg能解析的)格式.
private String processAVI(String filepath,int type, String outputPath) {
List<String> commend = new java.util.ArrayList<String>();
commend.add("D:\\IDS\\tomcat-6.0.29\\ffmpeg\\mencoder");
commend.add(filepath);
commend.add("-oac");
commend.add("lavc");
commend.add("-lavcopts");
commend.add("acodec=mp3:abitrate=64");
commend.add("-ovc");
commend.add("xvid");
commend.add("-xvidencopts");
commend.add("bitrate=600");
commend.add("-of");
commend.add("avi");
commend.add("-o");
commend.add(outputPath);
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
builder.redirectErrorStream(true);
Process process = builder.start();
BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = stdout.readLine()) != null) {
System.out.println(line);
continue;
}
process.waitFor();
return outputPath;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
private boolean processFLV(String oldfilepath, String outputPath) {
if (!checkfile(oldfilepath)) {
System.out.println(oldfilepath + " is not file");
return false;
}
List<String> commend = new java.util.ArrayList<String>();
commend.add("D:\\IDS\\tomcat-6.0.29\\ffmpeg\\ffmpeg");
commend.add("-i");
commend.add(oldfilepath);
commend.add("-ab");
commend.add("64");
commend.add("-acodec");
commend.add("mp3");
commend.add("-ac");
commend.add("2");
commend.add("-ar");
commend.add("22050");
commend.add("-b");
commend.add("230");
commend.add("-r");
commend.add("24");
commend.add("-y");
commend.add(outputPath);
try {
ProcessBuilder builder = new ProcessBuilder();
builder.command(commend);
builder.redirectErrorStream(true);
Process process = builder.start();
BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = stdout.readLine()) != null) {
System.out.println(line);
continue;
}
process.waitFor();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}