使用FFmpeg准确更新进度

时间:2019-05-16 06:36:10

标签: java android ffmpeg android-ffmpeg

我目前正在onProgress中显示进度,如下所示:

@Override
    public void onProgress(String message) {

        Pattern pattern = Pattern.compile("time=([\\d\\w:]{8}[\\w.][\\d]+)");

        if (message.contains("speed")) {
            Matcher matcher = pattern.matcher(message);

            if (matcher.find()) {
                String tempTime = String.valueOf(matcher.group(1));
                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]);

                //Length of video in milliseconds
                long timeToExportInMillis = rightThumbTimeRef - leftThumbTimeRef;

                //Calculate percentage
                long percent = 100 * currentTime / timeToExportInMillis;

                //Set percentage to TextView
                percentText.setText(percent + " %");

            }
        }
    }

我的问题是进度会像这样更新:

0 - 9 - 17 - 30 - 38等(直到100)

我想显示进度而不跳过值,例如:

0 - 1 - 2 - 3 - 4等(直到100)


我什至不确定是否可行,因为currentTime(如上)的更新取决于FFmpeg的进度输出,任何建议都将不胜感激。

0 个答案:

没有答案