I want add a progress bar during FFMPEG execution android.
When i start FFMPEG command then progress bar start with percentage progress.
To Calculate ffmpeg progress in percentage
ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
@Override
public void onFailure(String s) {
Log.d(TAG, "FAILED with output : " + s);
}
@Override
public void onSuccess(String s) {
Log.d(TAG, "SUCCESS with output : " + s);
}
@Override
public void onProgress(String s) {
Log.d(TAG, "Started command : ffmpeg " + Arrays.toString(command));
Log.d(TAG, "progress : " + s);
Pattern timePattern = Pattern.compile("(?<=time=)[\\d:.]*");
Scanner sc = new Scanner(s);
String match = sc.findWithinHorizon(timePattern, 0);
if (match != null) {
String[] matchSplit = match.split(":");
if (totalDur != 0) {
float progress = (Integer.parseInt(matchSplit[0]) * 3600 +
Integer.parseInt(matchSplit[1]) * 60 +
Float.parseFloat(matchSplit[2])) / totalDur;
float showProgress = (progress * 100);
Log.d(TAG, "=======PROGRESS======== " + showProgress);
}
}
}
@Override
public void onStart() {
Log.d(TAG, "Started command : ffmpeg " + Arrays.toString(command));
progressDialog.setMessage("Processing...");
progressDialog.show();
}
@Override
public void onFinish() {
Log.d(TAG, "Finished command : ffmpeg " + Arrays.toString(command));
progressDialog.dismiss();
}
});
totalDur=25; // for 25 Sec Video
But totalDur will change according to operation like for 2x Slow Video you have to give totalDur=2*25; //50 Sec Video