SrtParser\srtFile::sync PHP Метод

sync() публичный Метод

The subtitles are first shifted to the first subtitle's correct time, and then proportionally adjusted using the last subtitle's correct time. Based on gnome-subtitles (https://git.gnome.org/browse/gnome-subtitles/)
public sync ( integer $startIndex, integer $startTime, integer $endIndex, integer $endTime, boolean $syncLast = true ) : boolean
$startIndex integer The subtitle index to start the adjustment with.
$startTime integer The correct start time for the first subtitle.
$endIndex integer The subtitle index to end the adjustment with.
$endTime integer The correct start time for the last subtitle.
$syncLast boolean Whether to sync the last subtitle.
Результат boolean Whether the subtitles could be adjusted
    public function sync($startIndex, $startTime, $endIndex, $endTime, $syncLast = true)
    {
        $keys = array_keys($this->subs);
        $sub_count = sizeof($keys);
        //set first and last subtitles index
        if (!$startIndex) {
            $startIndex = 0;
        }
        if (!$endIndex) {
            $endIndex = $sub_count - 1;
        }
        //check subtitles do exist
        $startSubtitle = $this->getSub($startIndex);
        $endSubtitle = $this->getSub($endIndex);
        if (!$startSubtitle || !$endSubtitle) {
            return false;
        }
        if (!($startTime < $endTime)) {
            return false;
        }
        $shift = $startTime - $startSubtitle->getStart();
        $factor = ($endTime - $startTime) / ($endSubtitle->getStart() - $startSubtitle->getStart());
        /* Shift subtitles to the start point */
        if ($shift) {
            $this->shift($shift, $startIndex, $endIndex);
        }
        /* Sync timings with proportion */
        for ($index = $startIndex; $index <= $endIndex; $index++) {
            $entry = $this->getSub($index);
            $entry->scale($startTime, $factor);
        }
        return true;
    }