将mp4转换为mp3:找不到文件

时间:2019-12-08 16:00:34

标签: ffmpeg mp3 mp4

我已经使用以下代码将mp4转换为mp3

public static void main(String[] args) throws IOException, InterruptedException {

String line;
String mp4File = "/Users/hywelgriffiths/Documents/home/pictures/Test.mp4";
String mp3File = "/Users/hywelgriffiths/Documents/home/pictures/Audio.mp3";

// ffmpeg -i input.mp4 output.avi as it's on www.ffmpeg.org
String cmd = "ffmpeg -i " + mp4File + " " + mp3File;
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReadernew InputStreamReader(p.getErrorStream()));
while ((line = in.readLine()) != null) {
System.out.println(line);
}
p.waitFor();
System.out.println("Video converted successfully!");

目前,它找不到我要转换的文件。我在终端中使用路径输入了cd命令,并将其带到文件的正确位置。我收到的错误是:

Exception in thread "main" java.io.IOException: Cannot run program "ffmpeg": error=2, No     
such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at Main.main(Main.java:37)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 4 more

    in.close();

}

将不胜感激地收到任何帮助

0 个答案:

没有答案