I made a simple program and UI for it. It has one button for starting ffmpeg.exe to decode a video:
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ProcessBuilder pb = new ProcessBuilder("D:\\ffmpeg.exe", "-i", "\"D:\\video\\input.mp4\"", "\"output.mp4\"");
try {
Process p = pb.start();
} catch (IOException error) {
//
}
}
}
The problem is that after clicking the button ffmpeg starts but it doesn't do anything (in task manager it doesn't use cpu - 0%) until I close the program (UI) and then ffmpeg process starts to decode a video (only after closing the program ffmpeg starts using cpu - e.g. 24%)
It's not duplicate: older questions proposed by Andy Thomas doesn't have an answer (solution) for my problem
Your
Process
blocks the event dispatch thread. Instead, run yourProcessBuilder
in the background of aSwingWorker
, as shown in this complete example.Note that the example invokes
redirectErrorStream(true)
, so you should be able to see any errors or prompts fromffmpeg.exe
.