我正在从 Java 运行 ffmpeg。使用它将flv文件转换为mp3。
当我运行下面的代码时,ffmpeg 启动,创建一个新文件(.mp3 文件)但以 0% 的 CPU 运行。当我停止 JAVA 应用程序(来自 netbeans)时,ffmpeg 保持打开状态,并且每个 Windows 任务管理器(CTRL-ALT-DEL)从 0% 变为 99%。另一件奇怪的事情正在发生。ffmpeg 的输出没有被打印。
线程正在启动,但由于某种原因,java 没有给它任何时间来进行处理。
对于如何解决这个问题,有任何的建议吗?谢谢。
public class ConverterThread extends Thread {
String fileToConvert;
String fileToCreate;
GetSong getSong;
public ConverterThread(String downloadLocationOnDisk, GetSong getSong) {
this.fileToConvert = downloadLocationOnDisk;
this.getSong = getSong;
}
public void run(){
try {
Thread cur=Thread.currentThread();
cur.setPriority(Thread.MAX_PRIORITY);
String downloadLocationOnDisk = fileToConvert;
if(downloadLocationOnDisk.contains(".flv"))
fileToCreate = downloadLocationOnDisk.replace(".flv", ".mp3");
if(downloadLocationOnDisk.contains(".m4a"))
fileToCreate = downloadLocationOnDisk.replace(".m4a", ".mp3");
String cmdLine = "ffmpeg/bin/ffmpeg -i \"" + fileToConvert + "\" \"" + fileToCreate +"\"";
System.err.println(cmdLine);
// run the Unix "ps -ef" command
// using the Runtime exec method:
Process p = Runtime.getRuntime().exec(cmdLine);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
String s;
// read the output from the command
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
} catch (IOException ex) {
Logger.getLogger(ConverterThread.class.getName()).log(Level.SEVERE, null, ex);
}