public void run()
{
Runtime rt = Runtime.getRuntime();
try {
Process cmd = rt.exec("cmd /c C:\\mplayer\\mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=xvcd -vf scale=512:512,harddup -srate 44100 -af lavcresample=44100 -lavcopts vcodec=mpeg1video:keyint=15:vrc_buf_size=327:vrc_minrate=1152:vbitrate=1152:vrc_maxrate=1152:acodec=mp2:abitrate=224 -ofps 25 -o \"C:\\Documents and Settings\\Alvin Loh\\My Documents\\MP-SIP\\Server (Secure With JpegImagesToMovie)\\videos\\Nov2005\\test\\abc.mpg\" \"C:\\Documents and Settings\\Alvin Loh\\My Documents\\MP-SIP\\Server (Secure With JpegImagesToMovie)\\videos\\Nov2005\\test\\abc.mov\"");
} catch (IOException ex) {
ex.printStackTrace();
}
}
I'm currently running the exec method as a seperate thread. How do I check if the process is completed? Sorry, I'm still new to Java.
public void run() {
Runtime rt = Runtime.getRuntime();
try {
Process cmd = rt.exec("...snip...");
System.out.println("Command finished with value: " + cmd.waitFor());
} catch (IOException ex) {
ex.printStackTrace();
} catch (InterruptedException ex) {
System.out.println("INTERRUPTED while waiting on command!");
}
}
Then the process is not completing. Read the article posted earlier again and follow the advice given in regards to the error and output streams. There's a chance your process is blocking because the pipe is full. Since it's not exiting there may be resources it's still holding on to resources which prevent you from viewing the movie. Killing your IDE probably results in killing the blocked process too, since it was launched from there.
public void run()
{
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(...cmd...);
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<ERROR>");
while ( (line = br.readLine()) != null)
System.out.println(line);
System.out.println("</ERROR>");
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
It's not working still. :(
Any idea why?
That takes care of the error stream, what about the output stream? Keep reading the article, that's the mediocre solution for a reason. Use StreamGobbler which is described later in the article.
class StreamGobbler extends Thread
{
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
{
this.is = is;
this.type = type;
}
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
public void run() {
Runtime rt = Runtime.getRuntime();
try {
Process cmd = rt.exec("...snip...");
new StreamGobbler(cmd.getInputStream(), "OUTPUT").start();
new StreamGobbler(cmd.getErrorStream(), "ERROR").start();
System.out.println("Command finished with value: " + cmd.waitFor());
} catch (IOException ex) {
ex.printStackTrace();
} catch (InterruptedException ex) {
System.out.println("INTERRUPTED while waiting on command!");
}
}