Reputation: 169
When i launch this command in shell: /home/ffmpeg-2.0.1-64bit-static/ffmpeg -i rtmp://localhost:1935/livetv/2ch5h264 -vn -ar 44100 -ac 2 -ab 128k -f wav -ss 00:00:00 -t 7200 /home/Data/file.wav
That works, 'the file.wav' will be writen and this has for example +-600MB. (the command worked successfully) I confirmed this file has at least 2 hours of audio.
My Question: When i launch this process on Java with:
//Current Java App
Runtime rt = Runtime.getRuntime();
//Command Process to get data from streaming
String cmdLine = "/home/ffmpeg-2.0.1-64bit-static/ffmpeg -i rtmp://localhost:1935/livetv/2ch5h264 -vn -ar 44100 -ac 2 -ab 128k -f wav -ss 00:00:00 -t 7200 /home/Data/file.wav";
//Start the process
proc_ffmpeg = rt.exec(cmdLine);
//Wait to Exit
int exitVal = proc_split.waitFor();
FFmpeg doesn't write beyond +- 104MB in file.wav? In this case my audio file only has +- 10mins.
Thank you
Upvotes: 1
Views: 619
Reputation: 1503869
It sounds like the problem is that ffmpeg is writing log information, and you're not reading it in the Java code. There will be a small buffer between the processes, and when that buffer fills up, ffmpeg will block when it tries to write more log information.
You could use ProcessBuilder
and call ProcessBuilder.redirectError
/ProcessBuilder.redirectOutput
, or you could read from the standard error/output streams in your Java code. Unless you're sure it'll only write to one of them, you should do that in other threads. As a simple example:
public class StreamConsumer implements Runnable {
private final InputStream input;
public StreamConsumer(InputStream input) {
this.input = input;
}
@Override
public void run() {
byte[] buffer = new byte[1024];
try {
while (input.read(buffer) > 0) {
// No-op; we're not interested in the data
}
} catch (IOException e) {
// Log the error or whatever you want to do. The stream is probably
// broken now...
}
}
}
...
new Thread(new StreamConsumer(proc_ffmpeg.getInputStream())).start();
new Thread(new StreamConsumer(proc_ffmpeg.getErrorStream())).start();
Upvotes: 2