PHPackages                             mokhosh/laravel-xml2srt - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. mokhosh/laravel-xml2srt

Abandoned → [mokhosh/laravel-captions](/?search=mokhosh%2Flaravel-captions)Library[File &amp; Storage](/categories/file-storage)

mokhosh/laravel-xml2srt
=======================

Work with SRT files and YouTube XML subtitles in Laravel

v3.0.0(1y ago)213[3 PRs](https://github.com/mokhosh/laravel-caption/pulls)MITPHP ^8.2

Since Dec 23Compare

[ Source](https://github.com/mokhosh/laravel-caption)[ Packagist](https://packagist.org/packages/mokhosh/laravel-xml2srt)[ Docs](https://github.com/mokhosh/laravel-caption)[ RSS](/packages/mokhosh-laravel-xml2srt/feed)WikiDiscussions Synced 2d ago

READMEChangelog (6)Dependencies (13)Versions (13)Used By (0)

Work with SRT files and YouTube XML subtitles in Laravel
========================================================

[](#work-with-srt-files-and-youtube-xml-subtitles-in-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/65a49e8d0aa01bdbff463ec20a4fc1bc52a6734136cab2ffb236bce6f3c15adf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f6b686f73682f6c61726176656c2d63617074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mokhosh/laravel-caption)[![GitHub Tests Action Status](https://camo.githubusercontent.com/075248b7dac4128f617e4aa148461631d8bc198a4dcd1619b4fc7378d3d36531/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f6b686f73682f6c61726176656c2d63617074696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/mokhosh/laravel-caption/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/7624835e7b3f93256b7e81e526061ca53b308a98e1faa7e3f04941dec60aea8b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f6b686f73682f6c61726176656c2d63617074696f6e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/mokhosh/laravel-caption/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/6c934768a5fdf62e96131826c420757130a8fc71114ca8239569478459521913/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f6b686f73682f6c61726176656c2d63617074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mokhosh/laravel-caption)

You can parse xml timecodes into line by line representation of the caption, and then generate srt files based on the parsed caption.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require mokhosh/laravel-caption
```

Concepts
--------

[](#concepts)

`Caption` has a `Collection` of `Line`s, to which you can `add()` a new `Line`. You can also get all `lines()` of a `Caption`. Each line is a readonly value object consisting of a float `start`, a float `duration`, and a `text`.

You can also use `TimecodeConverter`'s `floatToTimecode()` to convert floating seconds/miliseconds values to formatted timecode.

Usage
-----

[](#usage)

Let's say you need to read subtitles in any custom format and generate SRT subtitles based on its contents.

Here's how we convert an OpenAI transcription Json to an STR file:

```
use Mokhosh\LaravelCaption\Caption;use Mokhosh\LaravelCaption\Generators\SrtGenerator;use Mokhosh\LaravelCaption\Line;

// $response = OpenAI::audio()->transcribe();

$caption = new Caption;

foreach ($response->segments as $segment) {
    $caption->add(new Line(
        floatval($segment->start),
        floatval($segment->end) - floatval($segment->start),
        trim($segment->text),
    ));
}

SrtGenerator::load($caption)->export('output.srt');
```

Or you can use the facade to load a json file containing an OpenAI response:

```
use Mokhosh\LaravelCaption\Facades\LaravelCaption;

// convert to srt and return output path
$output = LaravelCaption::openai2srt('input.json', 'output.srt');
```

You can simply convert a YouTube xml timecode file to a srt subtitle file like so:

```
use Mokhosh\LaravelCaption\Facades\LaravelCaption;

// convert to srt and return output path
$output = LaravelCaption::xml2srt('input.xml', 'output.srt');
```

If you need to chunk your xml into smaller srt files, do this:

```
use Mokhosh\LaravelCaption\Facades\LaravelCaption;

// chunk every 10 lines into chunks/ folder and return an array of chunks' paths
$chunks = LaravelCaption::xml2srt('input.xml', 'chunks/', every: 10);
```

If you need more control you can do this:

```
use Mokhosh\LaravelCaption\Generators\SrtGenerator;use Mokhosh\LaravelCaption\Parsers\XmlCaptionParser;

$caption = XmlCaptionParser::import('input.xml')->parse();
$output = SrtGenerator::load($caption)->export('output.srt');
```

And for chunking:

```
use Mokhosh\LaravelCaption\Generators\SrtGenerator;use Mokhosh\LaravelCaption\Parsers\XmlCaptionParser;

$caption = XmlCaptionParser::import('input.xml')->parse();
// chunk every 4 lines into chunks folder and prefix chunk files with the word "part"
$chunks = SrtGenerator::load($caption)->chunk(4, 'chunks/', 'part');
```

Testing
-------

[](#testing)

```
./vendor/bin/pest
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Mo Khosh](https://github.com/mokhosh)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity62

Established project with proven stability

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 ~46 days

Recently: every ~54 days

Total

6

Last Release

694d ago

Major Versions

v1.1.2 → v2.0.02024-08-08

v2.0.0 → v3.0.02024-08-09

PHP version history (2 changes)v1.0.0PHP ^8.1

v2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/939919859a4e4f8e56b5771bc355135f44d98d8a3926baa6ce4358d2dc090edf?d=identicon)[mokhosh](/maintainers/mokhosh)

---

Tags

laravelMo Khoshlaravel-xml2srtlaravel-caption

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/mokhosh-laravel-xml2srt/health.svg)

```
[![Health](https://phpackages.com/badges/mokhosh-laravel-xml2srt/health.svg)](https://phpackages.com/packages/mokhosh-laravel-xml2srt)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M100](/packages/dedoc-scramble)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.8k3](/packages/defstudio-telegraph)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

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