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;
}