How to add progress bar to FFMPEG android

前端 未结 4 1159
时光取名叫无心
时光取名叫无心 2021-01-01 07:34

I want add a progress bar during FFMPEG execution android.

When i start FFMPEG command then progress bar start with percentage progress.

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-01 08:25

    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

提交回复
热议问题