I can not figure out how to start a Process in Java for recording a live stream with ffmpeg.
I've tried several solutions, but my current code looks like this (simplified):
public void startDownload() {
String[] processArgs = new String[] {
"ffmpeg",
"-i",
"https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8",
"-c",
"copy",
"-bsf:a",
"aac_adtstoasc",
"C:\\temp\\test.mp4"
};
ProcessBuilder processBuilder = new ProcessBuilder(processArgs);
try {
process = processBuilder.start();
process.wairFor(); // Do I need this? Actually the stream is running forever until I stop it manually.
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = br.readLine()) != null) { // this blocks forever
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
The problem is, that something blocks the process from starting. In this example the br.readLine() blocks it forever and I can not get any output from the process.
But after killing the jar / stopping launch config in Intellij, the process begins to work and I have to kill it via task manager.
Running a process that is not recording a live stream like just executing ffmpeg works by the way.
I'm using Windows, JDK 14, IntelliJ.