1

I am quite new to java, and try as I might, I can't find any examples to help me. I am running ffmpeg as a process and parsing the stderr to get various bits of data - all of which is working fine, but I want to send a "q\n" command to ffmpeg's input from a gui menu item to gracefully quit it whilst it is running when necessary. So all I want to do is send a string programmatically to ffmpeg, the equivalent of sending q return from terminal. Thanks in advance edit here is the relevant (simplified) section of the code

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                 Thread thread = new Thread() {

public void run()
BufferedReader error_reader,input_reader;
InputStreamReader error_isr,input_isr;

String ffmpeg_command = "ffmpeg " + overwrite + " -i " + "\"" + currentfilestring + "\"" + " " + stream + " " + test + " " + findsilence + " " + videocodec + " -b:v " + videoqual + " " + audiocodec + " -ac 2  -ab " + audioqual + " " + res + " " + aspectratio + " " + framerate + " " + "\"" + destdir + destfile + "\"";
System.out.println(ffmpeg_command);
try {
OutputStream stdout;
InputStream stdin;
InputStream stderr;
String errorstr,inputstr;
//Run the ffmpeg
Process ffmpeg = Runtime.getRuntime().exec(ffmpeg_command, null, new File(userDir));

//Get stdin,stderr + stdout                     
stdin = ffmpeg.getInputStream();
stderr = ffmpeg.getErrorStream();
stdout = ffmpeg.getOutputStream();
stdout.write("\r\n".getBytes());   
stdout.flush();
stdout.close();

error_isr = new InputStreamReader(stderr);
error_reader = new BufferedReader(error_isr);

input_reader = new BufferedReader(input_isr);
while (!error_reader.ready()) {
}
while ((errorstr = error_reader.readLine()) != null) {

if(stopconv =="yes"){
                            //-------------------------------------------------------------------------------------
                               // TRYING TO INPUT "q\n" TO FFMPEG HERE
               //-------------------------------------------------------------------------------------
 }

 error_isr.close();
 error_reader.close();
 stdin.close();
 stderr.close();
 jProgressBar1.setValue(0);

 ffmpeg.destroy();

 } catch (Exception e) {
 e.printStackTrace();
                        }
};
thread.start();
}                             
jdauthre
  • 21
  • 1
  • 3

0 Answers0