FFMpeg\Format\ProgressListener\AbstractProgressListener::parseProgress PHP Method

parseProgress() private method

private parseProgress ( string $progress ) : array
$progress string A ffmpeg stderr progress output
return array the progressinfo array or null if there's no progress available yet.
    private function parseProgress($progress)
    {
        if (!$this->initialized) {
            $this->initialize();
        }
        if (null === $this->totalSize || null === $this->duration) {
            return;
        }
        $matches = array();
        if (preg_match($this->getPattern(), $progress, $matches) !== 1) {
            return null;
        }
        $currentDuration = $this->convertDuration($matches[2]);
        $currentTime = microtime(true);
        $currentSize = trim(str_replace('kb', '', strtolower($matches[1])));
        $percent = max(0, min(1, $currentDuration / $this->duration));
        if ($this->lastOutput !== null) {
            $delta = $currentTime - $this->lastOutput;
            $deltaSize = $currentSize - $this->currentSize;
            $rate = $deltaSize * $delta;
            if ($rate > 0) {
                $totalDuration = $this->totalSize / $rate;
                $this->remaining = floor($totalDuration - $totalDuration * $percent);
                $this->rate = floor($rate);
            } else {
                $this->remaining = 0;
                $this->rate = 0;
            }
        }
        $percent = $percent / $this->totalPass + ($this->currentPass - 1) / $this->totalPass;
        $this->percent = floor($percent * 100);
        $this->lastOutput = $currentTime;
        $this->currentSize = (int) $currentSize;
        $this->currentTime = $currentDuration;
        return $this->getProgressInfo();
    }