src/Captioning/File.php
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;
    }
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;
    }
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 ; }
Auto syncs a range of subtitles given their first and last correct times.
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/)

@param int $_startIndex The subtitle index to start the adjustment with.
@param int $_startTime The correct start time for the first subtitle.
@param int $_endIndex The subtitle index to end the adjustment with.
@param int $_endTime The correct start time for the last subtitle.
@param bool $_syncLast Whether to sync the last subtitle.
@return bool Whether the subtitles could be adjusted
Auto syncs a range of subtitles given their first and last correct times . The subtitles are first shifted to the first subtitle s correct time and then proportionally adjusted using the last subtitle s correct time .