PHPackages                             mindedge/subtitles - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mindedge/subtitles

ActiveLibrary

mindedge/subtitles
==================

Subtitle converter and generator for PHP

1.0.1(3y ago)02.3k↓78.7%1MITPHP

Since Mar 7Pushed 3y agoCompare

[ Source](https://github.com/mindedge/subtitles)[ Packagist](https://packagist.org/packages/mindedge/subtitles)[ RSS](/packages/mindedge-subtitles/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/d061bec27f14fa3804cf7b36aa9299f1846b14132e576f3573ea49a524b9c9bb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d616e7461732d646f6e652f7375627469746c65732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mantas-done/subtitles/build-status/master)

Caption And Subtitle Converter for PHP
======================================

[](#caption-and-subtitle-converter-for-php)

Convert and edit subtitles and captions.

Supported formats
-----------------

[](#supported-formats)

FormatExtension[SubRip](https://en.wikipedia.org/wiki/SubRip#SubRip_text_file_format).srt[WebVTT](https://en.wikipedia.org/wiki/WebVTT).vtt[Spruce Technologies SubTitles](https://pastebin.com/ykGM9qjZ).stl[Youtube Subtitles](https://webdev-il.blogspot.lt/2010/01/sbv-file-format-for-youtube-subtitles.html).sbv[SubViewer](https://wiki.videolan.org/SubViewer).subAdvanced Sub Station.ass[DFXP](https://en.wikipedia.org/wiki/Timed_Text_Markup_Language).dfxp[TTML](https://en.wikipedia.org/wiki/Timed_Text_Markup_Language).ttmlQuickTime.qt.txtInstallation
------------

[](#installation)

```
composer require mantas-done/subtitles

```

Usage
-----

[](#usage)

Convert .srt file to .vtt:

```
// add namespace
use \MindEdge\Subtitles\Subtitles;

Subtitles::convert('subtitles.srt', 'subtitles.vtt');
```

Manually create file

```
$subtitles = new Subtitles();
$subtitles->add(0, 5, 'This text is shown in the beggining of video for 5 seconds');
$subtitles->save('subtitles.vtt');
```

Load subtitles from existing file

```
$subtitles = Subtitles::load('subtitles.srt');
```

Load subtitles from string

```
$string = "
1
00:02:17,440 --> 00:02:20,375
Senator, we're making our final approach
";

$subtitles = Subtitles::load($string, 'srt');
```

Save subtitles to file

```
$subtitles->save('subtitler.vtt');
```

Get file content without saving to file

```
echo $subtitles->content('vtt');
```

Add subtitles

```
$subtitles->add(0, 5, 'some text'); // from 0, till 5 seconds

// Add multiline text
$subtitles->add(0, 5, [
    'first line',
    'second line',
]);
```

Remove subtitles

```
$subtitles->remove(0, 5); // from 0, till 5 seconds
```

Add 1 second to all subtitles

```
$subtitles->shiftTime(1);
```

Subtract 0.5 second

```
$subtitles->shiftTime(-0.5);
```

Add 5 second to subtitles starting from 1 minute till 2 mintes

```
$subtitles->shiftTime(5, 60, 120);
```

Example: shift time gradually by 2 seconds over 1 hour video. At the beginning of the video don't change time, in the middle shift time by 1 second. By the end of video, shift time by 2 seconds.

```
$subtitles->shiftTimeGradually(2, 0, 3600);
```

How to add new subtitle format?
-------------------------------

[](#how-to-add-new-subtitle-format)

You need to implement ConverterContract.php interface. It has two methods.

```
fileContentToInternalFormat($file_content)

internalFormatToFileContent($internal_format)
```

Basically what your implementation should be able to do, is convert subtitle file to "internal library's format", and from internal library's format back to subtitle file.

"Internal library's" format is used like middle ground, to be able to convert between different formats.

Best example is to look how [SrtConverter.php](https://github.com/mantas783/subtitle-converter/blob/master/src/code/Converters/SrtConverter.php) is implemented. And this is example of [.srt file](https://github.com/mantas783/subtitle-converter/blob/master/tests/files/srt.srt).

### "Internal Format"

[](#internal-format)

"Internal Format" is just a PHP array. It is used internally in library to be able to convert between different formats.

```
Array
(
    [0] => Array
        (
            [start] => 137.44
            [end] => 140.375
            [lines] => Array
                (
                    [0] => Senator, we're making
                    [1] => our final approach into Coruscant.
                )
        )
    [1] => Array
        (
            [start] => 140.476
            [end] => 142.501
            [lines] => Array
                (
                    [0] => Very good, Lieutenant.
                )
        )
)

```

```
[start] - when to start showing text (float - seconds)
[end] - when to stop showing text (float -seconds)
[lines] - one or more text lines (array)

```

Running Tests
-------------

[](#running-tests)

Simplest way is to download and put phpunit.phar file into the main directory of the project. Then run the command:

```
php phpunit.phar

```

Contribution
------------

[](#contribution)

You can contribute in any way you want. If you need some guidance, choose something from this table:

TaskDifficultyDescriptionAdd new formatsMediumSupporting more formats is nice. Some popular formats: .mcc, .capRefactor [StlConverter.php](https://github.com/mantas783/subtitle-converter/blob/master/src/code/Converters/StlConverter.php) fileEasy.stl format is very similar to .srt. The only problem is that StlConverter.php code can be simplified a lot (check [SrtConverter.php](https://github.com/mantas783/subtitle-converter/blob/master/src/code/Converters/SrtConverter.php) as example)Add .scc formatHard[Format description](https://en.wikipedia.org/wiki/EIA-608)For now library should support only basic features (several lines of text). No need to support different text styles or positioning of text.

Report Bugs
-----------

[](#report-bugs)

If some file is not working with the library, please create and issue and attach the file.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1159d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8bdc9f0c41d19ed030f8d105872f76d80cd0003ece1ed706e5756073a694ac0?d=identicon)[mindedge](/maintainers/mindedge)

---

Top Contributors

[![mantas-done](https://avatars.githubusercontent.com/u/17127206?v=4)](https://github.com/mantas-done "mantas-done (116 commits)")[![JRogaishio](https://avatars.githubusercontent.com/u/3596964?v=4)](https://github.com/JRogaishio "JRogaishio (11 commits)")[![kocoten1992](https://avatars.githubusercontent.com/u/7130705?v=4)](https://github.com/kocoten1992 "kocoten1992 (7 commits)")[![ts-toh](https://avatars.githubusercontent.com/u/41636305?v=4)](https://github.com/ts-toh "ts-toh (1 commits)")[![ntninja](https://avatars.githubusercontent.com/u/246386?v=4)](https://github.com/ntninja "ntninja (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![tcedge](https://avatars.githubusercontent.com/u/26552977?v=4)](https://github.com/tcedge "tcedge (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mindedge-subtitles/health.svg)

```
[![Health](https://phpackages.com/badges/mindedge-subtitles/health.svg)](https://phpackages.com/packages/mindedge-subtitles)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
