First Of All Call this method from OnProgress Method of FFmpeg Listener
public void onProgress(String s) {
getProgress(s);
Log.e("Editor", "String ==== " + s);
}
getProgress(s) is a method that find Estimate Time of Our execution
private void getProgress(String message) {
Pattern pattern = Pattern.compile("time=([\\d\\w:]{8}[\\w.][\\d]+)");
Matcher matcher = pattern.matcher(message);
matcher.find();
String tempTime = String.valueOf(matcher.group(1));
Log.d(TAG, "getProgress: tempTime " + tempTime);
String[] arrayTime = tempTime.split("[:|.]");
long currentTime =
TimeUnit.HOURS.toMillis(Long.parseLong(arrayTime[0]))
+ TimeUnit.MINUTES.toMillis(Long.parseLong(arrayTime[1]))
+ TimeUnit.SECONDS.toMillis(Long.parseLong(arrayTime[2]))
+ Long.parseLong(arrayTime[3]);
String speed;
speed = message.substring(message.indexOf("speed=") + 1, message.indexOf("x")).split("=")[1];
long percent = 100 * currentTime / videoLengthInMillis;
long time = TimeUnit.HOURS.toMillis(Long.parseLong(arrayTime[0])) * 3600 + TimeUnit.MINUTES.toMillis(Long.parseLong(arrayTime[1])) * 60 + TimeUnit.SECONDS.toMillis(Long.parseLong(arrayTime[2])) + Math.round(Long.parseLong(arrayTime[3]));
long ETA = Math.round((Math.round(videoLengthInMillis) - time) / Float.valueOf(speed));
Log.e(TAG, "currentTime -> " + currentTime + "s % -> " + percent);
Log.e(TAG, "ETA -> " + ETA);
progressBar.setProgress((int) percent);
String EstimateTime = convertSecondsToHMmSs(ETA);
Log.e(TAG, "EstimateTime -> " + EstimateTime);
ProcessTime.setText(EstimateTime);
}
ConvertSecondToHMmSs
public static String convertSecondsToHMmSs(long millis) {
long seconds=(millis/1000);
long s = seconds % 60;
long m = (seconds / 60) % 60;
long h = (seconds / (60 * 60)) % 24;
return String.format("%d:%02d:%02d", h,m,s);
}