Captioning\File::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)
    {
        //set first and last subtitles index
        if (!$_startIndex) {
            $_startIndex = 0;
        }
        if (!$_endIndex) {
            $_endIndex = $this->getCuesCount() - 1;
        }
        if (!$_syncLast) {
            $_endIndex--;
        }
        //check subtitles do exist
        $startSubtitle = $this->getCue($_startIndex);
        $endSubtitle = $this->getCue($_endIndex);
        if (!$startSubtitle || !$endSubtitle || $_startTime >= $_endTime) {
            return false;
        }
        $shift = $_startTime - $startSubtitle->getStartMS();
        $factor = ($_endTime - $_startTime) / ($endSubtitle->getStartMS() - $startSubtitle->getStartMS());
        /* Shift subtitles to the start point */
        if ($shift) {
            $this->shift($shift, $_startIndex, $_endIndex);
        }
        /* Sync timings with proportion */
        for ($index = $_startIndex; $index <= $_endIndex; $index++) {
            $cue = $this->getCue($index);
            $cue->scale($_startTime, $factor);
        }
        return true;
    }