PHP Classes

PHP Edit Subtitles Class: Edit video subtitles in SRT and VTT formats

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 289 All time: 7,510 This week: 57Up
Version License PHP version Categories
editsubtitles 1.1GNU General Publi...5PHP 5, Files and Folders, Text proces..., V..., P...
Description 

Author

This class can edit video subtitles in SRT and VTT format.

It can create a new video subtitles file or read an existing file in SRT and VTT format.

The class can also add, change and delete subtitles text at a given time.

The generated subtitles may be saved to a SRT or VTT file or returned as an array.

You can also convert formats from SRT to VTT or VTT to SRT.

Innovation Award
PHP Programming Innovation award nominee
January 2017
Number 12
Many video hosting sites like for instance YouTube can show videos with sub-titles provided by the authors. The subtitles may be submitted in several known formats.

This package allows PHP applications to create and edit subtitles in some formats like SRT and VTT.

Manuel Lemos
Picture of Luciano Salvino
  Performance   Level  
Name: Luciano Salvino <contact>
Classes: 11 packages by
Country: Argentina Argentina
Age: 51
All time rank: 134316 in Argentina Argentina
Week rank: 215 Up4 in Argentina Argentina Up
Innovation award
Innovation award
Nominee: 9x

Example

<?php

include('phpEditSubtitles.php');

$st = new phpEditSubtitles();

$st->setFile('test.srt');
// set output type to vtt (it will convert from srt to vtt type)
$st->setType('vtt');
$st->readFile();

// Edit subtitle on position 23
// IMPORTANT: it will reordenate the time. If the amount of time is smaller than $timeIni or bigger than $timeEnd the request will not be processed
$order = 23;
$timeIni = '00:01:10,880';
$timeEnd = '00:01:18,830';
$subtitle = 'Edit subtitle';
$st->editSubtitle($order,$timeIni,$timeEnd,$subtitle);

// remove subtitle on position 25
$st->deleteSubtitle(25);

// add subtitle on position 25
// IMPORTANT: it will reordenate the time. If the amount of time is smaller than $timeIni or bigger than $timeEnd the request will not be processed
$order = 25;
$timeIni = '00:01:31,010';
$timeEnd = '00:01:32,790';
$subtitle = 'New subtitle';
$st->addSubtitle($order,$timeIni,$timeEnd,$subtitle);

// save subtitles in a new file
$st->saveFile('newfile');

// get array of subtitles
$subtitles = $st->getSubtitles();

echo
'<pre>';
print_r($subtitles);
echo
'</pre>';


Details

lutian/phpEditSubtitles

> text processing

Edit files of video subtitles. You can add, edit or delete subtitles and save into new file in .srt or .vtt format New: you can convert from SRT to VTT format

Version

1.1

Authors

  • [Luciano Salvino] - <lsalvino@hotmail.com>

Installation

To use the tools of this repo only has to be required in your composer.json:

{
   "require":{
      "lutian/phpEditSubtitles": "dev-master"
   }
}

Use


include('phpEditSubtitles.php');

$st = new phpEditSubtitles();

$st->setFile('test.srt');
// set output type to vtt (it will convert from srt to vtt type)
$st->setType('vtt');
$st->readFile();

// Edit the first subtitle
// IMPORTANT: it will reordenate the time. If the amount of time is smaller than $timeIni or bigger than $timeEnd the request will not be processed
$order    = 1;
$timeIni  = '00:00:00,090';
$timeEnd  = '00:00:01,830';
$subtitle = 'Replace the first subtitle';
$st->editSubtitle($order,$timeIni,$timeEnd,$subtitle);

// remove subtitle in position 25
$st->deleteSubtitle(25);

// add subtitle on position 145
// IMPORTANT: it will reordenate the time. If the amount of time is smaller than $timeIni or bigger than $timeEnd the request will not be processed
$order    = 145;
$timeIni  = '00:05:05,050';
$timeEnd  = '00:08:05,130';
$subtitle = 'New subtitle';
$st->addSubtitle($order,$timeIni,$timeEnd,$subtitle);

// save subtitles in a new file
$st->saveFile('newfile.srt');

// get array of subtitles
$subtitles = $st->getSubtitles();

echo '<pre>';
print_r($subtitles);
echo '</pre>';


License

MIT

[Luciano Salvino]:http://mueveloz.com/


  Files folder image Files (7)  
File Role Description
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file newfile.srt Data Auxiliary data
Plain text file phpEditSubtitles.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file test.srt Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:289
This week:0
All time:7,510
This week:57Up