Coder Social home page Coder Social logo

subtitles's Introduction

Caption And Subtitle Converter for PHP

Convert and edit subtitles and captions.

Supported formats

Format Extension
SubRip .srt
WebVTT .vtt
Youtube Subtitles .sbv

Installation

composer require saeven/subtitles

Fork Notes

This package was forked from mantas-done/subtitles (thank you) to become more opinionated, to implement strict types and new interfaces, and to implement proper PSR-4 loading. What's more, this version of that package removes all ability to manipulate files directly or to attempt to infer the existence of converters by scanning the filesystem with file_exists and so forth. It also resorts to pattern matching in cases where the original implementation would split strings. Lastly, it adds Carbon to perform time conversions.

Usage

Convert .srt content to .vtt:

// add namespace
use \Circlical\Subtitles\Subtitles;

(new Subtitles())->load($srtContent, 'srt')->content('vtt');

Manually create VTT

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

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');

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

"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

./vendor/bin/phpunit

Contribution

Not all original converters from the fork have been corrected. Feel free to convert one from the 'todo' folder and open a PR!

Report Bugs

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

subtitles's People

Contributors

kocoten1992 avatar mantas-done avatar ntninja avatar saeven avatar scrutinizer-auto-fixer avatar ts-toh avatar

Forkers

cuongheoem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.