Here is a complete example for you that should run you
import java.io.*; import java.util.Scanner; import java.util.regex.Pattern; class Test { public static void main(String[] args) throws IOException { ProcessBuilder pb = new ProcessBuilder("ffmpeg","-i","in.webm","out.mp4"); final Process p = pb.start(); new Thread() { public void run() { Scanner sc = new Scanner(p.getErrorStream());
Output:
Total duration: 117.7 seconds. Progress: 7.71% Progress: 16.40% Progress: 25.00% Progress: 33.16% Progress: 42.67% Progress: 51.35% Progress: 60.57% Progress: 69.07% Progress: 78.02% Progress: 86.49% Progress: 95.94% Progress: 99.97%
You might also consider using some kind of Java bindings for ffmpeg, such as jjmpeg , which can provide what you need in a more reliable way.
EDIT
With ffmpeg 2.0, the time output is HH:mm:ss.S , so timePattern must include a :
Pattern timePattern = Pattern.compile("(?<=time=)[\\d:.]*");
In addition, dur needs to be broken down into : and summed together
String[] matchSplit; while (null != (match = sc.findWithinHorizon(timePattern, 0))) { matchSplit = match.split(":") double progress = Integer.parseInt(matchSplit[0]) * 3600 + Integer.parseInt(matchSplit[1]) * 60 + Double.parseDouble(matchSplit[2]) / totalSecs;
aioobe
source share