I'm trying to record a video from a capture card. As I want my program to control ffmpeg, I started a process within Java, let ffmpeg run for 30 seconds and then shut it down by sending "q" to the process. The video however is only 6 seconds long. I couldn't find anything wrong in my code and would appreciate some help
My code:
import java.io.*;
public class FfmpegTest {
public static void main(String[] args) throws Exception {
Process process = Runtime.getRuntime().exec("E:\\ffmpeg\\bin\\ffmpeg.exe -y -f dshow -i video=\"The video card\" bla.mp4");
PrintWriter pw = new PrintWriter(process.getOutputStream(),true);
Thread.sleep(30000);
System.out.println("recording done");
pw.println("q");
Thread.sleep(2000);
}
}
Ok I figured it out. The reason videos are only 6 seconds long was because ffmpeg has a lot of output which was full after 6 seconds. As the output didn't go anywhere, they clogged up the buffers and ffmpeg stopped to record.
To solve this, you can do one of two things:
-loglevel quiet
to suppress output messages. This might be unwanted if you need to look for specific messages in the streams