r/foojay • u/FrankCodeWriter • 3d ago
Driving FFmpeg from Java without deadlocks or broken files
We just published an article by Mark Santos on running FFmpeg from Java with ProcessBuilder. The code looks fine on a ten-second test clip, then hangs on a ten-minute file. The cause is the stderr pipe: it has a 64 KiB buffer, and once FFmpeg fills it, FFmpeg blocks and waitFor never returns.
The article explains three ways out: Redirect.DISCARD, INHERIT or to(file), redirectErrorStream(true), and reading stdout and stderr at the same time with a virtual thread. It also shows how to map ffprobe JSON onto records with Jackson. All examples were run on OpenJDK 21 and 27, and the test media comes from FFmpeg's own generators.
Author: Mark Santos
Read it here: https://foojay.io/today/driving-ffmpeg-from-java/