2012-08-02 4 views
0

Java에서 ffmpeg를 실행 중입니다. 그것을 사용하여 flv 파일을 mp3로 변환합니다.cmd에서 프로세스가 실행되지 않습니다.

아래 코드를 실행하면 ffmpeg가 시작되어 새 파일 (.mp3 파일)이 생성되지만 CPU의 0 %에서 실행됩니다. (netbeans에서) 자바 애플 리케이션을 중지하면 ffmpeg는 열려 있고 Windows 작업 관리자 (CTRL-ALT-DEL) 당 0 %에서 99 %까지 진행됩니다. 또 다른 이상한 일이 벌어지고 있습니다. ffmpeg의 출력이 인쇄되지 않습니다.

스레드가 시작되고 있지만 어떤 이유로 인해 처리를 수행 할 시간이 없습니다.

이 문제를 해결하는 방법에 대한 제안 사항이 있으십니까? 감사.

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); 
    } 

답변

0

나는 그 문제는 여기 어딘가에 생각 :

Thread cur=Thread.currentThread(); 
cur.setPriority(Thread.MAX_PRIORITY); 

Java 환경이 최대 우선 순위를 가지며는 FFmpeg에게 한 정도로 CPU 시간을 제공하지 않습니다. 실제로 스레드 우선 순위를 사용하지 않는 것은 다른 OS/환경에서 다른 동작을 일으킬 수 있기 때문에 고려하십시오.

또한 여기는 FFmpeg 명령의 끝을 기다리고 있습니다 :

while ((s = stdInput.readLine()) != null) { 
    System.out.println(s); 
} 

그래서, 당신은 자바의 모든 CPU 시간이 있으면 어렵는 FFmpeg 마무리 될 때까지 여기서 기다릴 것이다.

+0

나는 당신이 제안한대로 시도했다. 여전히 같은 결과. – FredTheLover

+0

'gedit' 또는'notepad.exe'와 같은 것을 exec 할 수 있습니까? 그것은 어떤 결과를 낳을 것인가? 난 당신의 코드를 시도하고'gedit' 응용 프로그램을 실행했다. 또한 출력도 보았습니다. – gkuzmin

관련 문제