dastan..
5
计算ffmpeg进度百分比
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; // 25秒视频
但是totalDur将根据操作而变化,例如对于2x慢视频,您必须给totalDur = 2 * 25; // 50秒视频