ArrayList<String> convert = new ArrayList<String>();
convert.add("ffmpeg -y -i C:/Users/fang/Desktop/1.m4a -ar 8000 -acodec mp3 C:/Users/fang/Desktop/5.mp3");
ProcessBuilder builder = new ProcessBuilder();
try {
builder.command(convert);
// 如果此属性为 true,则任何由通过此对象的 start() 方法启动的后续子进程生成的错误输出都将与标准输出合并,
// 因此两者均可使用 Process.getInputStream() 方法读取。这使得关联错误消息和相应的输出变得更容易
builder.redirectErrorStream(true);
Process process = builder.start();
InputStream is = process.getInputStream();
InputStreamReader inst = new InputStreamReader(is, "GBK");
BufferedReader br = new BufferedReader(inst);//输入流缓冲区
String res = null;
StringBuilder sb = new StringBuilder();
while ((res = br.readLine()) != null) {//循环读取缓冲区中的数据
sb.append(res + "\n");
}
System.out.println(sb.toString());
} catch (Exception e) {
mark = false;
System.out.println(e);
e.printStackTrace();
} finally {
}
解决
ProcessBuilder中的命令必须使用全路径指定,否则报错。
D:\\softwares\\ffmpeg-4.4.1-essentials_build\\bin\\ffmpeg.exe -y -i C:/Users/fang/Desktop/1.m4a -ar 8000 -acodec mp3 C:/Users/fang/Desktop/5.mp3
|