首先需要下载一个格式工厂的安装版或者免安装版
转码代码如下
public static boolean convertVideoToMp4(String videoPath,String mp4Path) {
try{
File file = new File(getFilePath(mp4Path));
if (!file.exists()) {
file.mkdir();
}
String bashCommand = "\"c:\\soft\\FormatFactory\\FormatFactory.exe\""
+ " \"All to MP4\" \"AVC Low quality and size\" \""+videoPath+"\"
\""+mp4Path+"\"";//转码命令
//System.out.println(bashCommand);
Runtime runtime = Runtime.getRuntime();
Process pro = runtime.exec(bashCommand);
int status = pro.waitFor();
if (status != 0)
{
System.out.println("Failed to call shell's command mp4 ");
}
BufferedReader br = new BufferedReader(new
InputStreamReader(pro.getInputStream()));
StringBuffer strbr = new StringBuffer();
String line;
while ((line = br.readLine())!= null)
{
strbr.append(line).append("\n");
}
String result = strbr.toString();
System.out.println(result);
}
catch (IOException ec){
ec.printStackTrace();
}catch (InterruptedException ex){
ex.printStackTrace();
}
return true;
}