1. Go to this page and download the library: Download mantas-done/subtitles library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mantas-done / subtitles example snippets
// add namespace
use \Done\Subtitles\Subtitles;
Subtitles::convert('subtitles.srt', 'subtitles.vtt');
// if no input format is specified, library will determine file format by its content
// if third parameter is specified, library will convert the file to specified format.
// list of formats are in Subtitle::$formats, they are: ass, dfxp, sbv, srt, stl, sub, ttml, txt_quicktime, vtt
Subtitles::convert('subtitles1', 'subtitles2', ['output_format' => 'vtt']);
$subtitles = new Subtitles();
$subtitles->add(0, 5, 'This text is shown in the beggining of video for 5 seconds');
$subtitles->save('subtitles.vtt');
$string = "
1
00:02:17,440 --> 00:02:20,375
Senator, we're making our final approach
";
$subtitles = Subtitles::loadFromString($string);
$subtitles->save('subtitler.vtt');
echo $subtitles->content('vtt');
$subtitles->add(0, 5, 'some text'); // from 0, till 5 seconds
// Add multiline text
$subtitles->add(0, 5, [
'first line',
'second line',
]);
// Add styles to VTT file format
// Only VTT supports styles currently
$subtitles->add(0, 5, 'text', ['vtt_cue_settings' => 'position:50% line:15% align:middle']);
$subtitles->remove(0, 5); // from 0, till 5 seconds
$subtitles->trim(3, 4); // get only from 3, till 4 seconds
$subtitles->shiftTime(1);
$subtitles->shiftTime(-0.5);
$subtitles->shiftTime(5, 60, 120);
$subtitles->shiftTimeGradually(2, 0, 3600);
try {
(new \Done\Subtitles\Subtitles())->add(0, 1, 'very long text... aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')->content('scc');
} catch (\Done\Subtitles\Code\UserException $e) {
echo $e->getMessage(); // SCC file can't have more than 4 lines of text each 32 characters long. This text is too long: <text from user file that triggered this error>
}