0

I am trying to convert a flv file to mp3 using ffmpeg from java.

I am running the following command

cmd.exe /C start /BELOWNORMAL /WAIT /B /ffmpeg -i "C:\Documents and Settings\user\My Documents\Bob Dylan - Spanish Harlem Incident(LD).flv" "C:\Documents and Settings\user\My Documents\Bob Dylan - Spanish Harlem Incident(LD).mp3"

I am getting this error "The system cannot find the file and."

I am using the following code to execute commands http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4

When i run it outside of java, from cmd console i have no problems

Any ideas would be appreciated.

4

1 回答 1

1

您是否正确转义了特殊字符?如果您只是将它作为字符串粘贴到代码中,它应该是这样的:

String command = "cmd.exe /C start /BELOWNORMAL /WAIT /B /ffmpeg -i \"C:\\Documents and Settings\\user\\My Documents\\Bob Dylan - Spanish Harlem Incident(LD).flv\"";

如果您是,但它仍然无法正常工作,我建议您将命令分开,如下所示:

Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", "start", "BELOWNORMAL", "/WAIT", "/B", "ffmepg", "-i", "C:\\Documents and Settings\user\\My Documents\\Bob Dylan - Spanish Harlem Incident(LD).flv"});

这将消除引用文件名的需要。

或者,为了增加可读性并排除文件系统的问题,您可以使用 File 类来包装位置,因此:

    File f = new File("C:\\Documents and Settings\\user\\My Documents\\Bob Dylan - Spanish Harlem Incident(LD).flv");
    Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", "start", "BELOWNORMAL", "/WAIT", "/B", "ffmepg", "-i", f.getAbsolutePath()});
于 2012-08-14T16:13:51.957 回答