I'm running ffmpeg
command to generate video for given images (img001.jpg, img002.jpg ...) it's creating slide.mp4, but it waits infinitely:
public class Ffmpeg {
public static void main(String[] args) throws IOException, InterruptedException {
String path = "E:\\pics\\Santhosh\\FadeOut\\testing";
String cmd = "ffmpeg -r 1/5 -i img%03d.jpg -c:v libx264 -r 30 -y -pix_fmt yuv420p slide.mp4";
runScript (path, cmd);
}
private static boolean runScript(String path, String cmd) throws IOException, InterruptedException {
List<String> commands = new ArrayList<String>();
commands.add("cmd");
commands.add("/c");
commands.add(cmd);
ProcessBuilder pb = new ProcessBuilder(commands);
pb.directory(new File(path));
pb.redirectErrorStream(true);
Process process = pb.start();
flushInputStreamReader(process);
int exitCode = process.waitFor();
return exitCode == 0;
}
}
private static void flushInputStreamReader (Process process) throws IOException, InterruptedException {
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line=null;
StringBuilder s = new StringBuilder();
while((line=input.readLine()) != null) {
s.append(line);
}
}
Any suggestions?
After writing the function flushInputStreamReader, its working
Aside from reading the ErrorStream, there's a better way to handle this.
Add -loglevel quiet
to the command, so that the ErrorStream won't overflow and blocking the process at the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With