From 98ea16f21b3e85f68bf47b43d9a08c347dd4a1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20T=C3=B3th?= Date: Tue, 11 Dec 2012 16:15:14 +0100 Subject: [PATCH] More precise progress indication This fix solves divison by 0 and incorrect percentage report when extractImage is used --- src/FFMpeg/Helper/ProgressHelper.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/FFMpeg/Helper/ProgressHelper.php b/src/FFMpeg/Helper/ProgressHelper.php index 26aa59b..85e47e6 100644 --- a/src/FFMpeg/Helper/ProgressHelper.php +++ b/src/FFMpeg/Helper/ProgressHelper.php @@ -152,15 +152,20 @@ abstract class ProgressHelper implements HelperInterface $currentDuration = $this->convertDuration($matches[2]); $currentTime = $this->microtimeFloat(); $currentSize = trim(str_replace('kb', '', strtolower(($matches[1])))); - $percent = $currentDuration/ $this->duration; + $percent = max(0, min(1, $currentDuration / $this->duration)); if ($this->lastOutput !== null) { $delta = $currentTime - $this->lastOutput; $deltaSize = $currentSize - $this->currentSize; $rate = $deltaSize * $delta; - $totalDuration = $this->totalSize / $rate; - $this->remaining = floor($totalDuration - ($totalDuration * $percent)); - $this->rate = floor($rate); + if ($rate > 0) { + $totalDuration = $this->totalSize / $rate; + $this->remaining = floor($totalDuration - ($totalDuration * $percent)); + $this->rate = floor($rate); + } else { + $this->remaining = 0; + $this->rate = 0; + } } $this->percent = floor($percent * 100);