Giter VIP home page Giter VIP logo

srt_delay's Introduction

srt_delay.py

… is a small Python 3 script that you can use to advance or delay the timings of a subtitle file in the .srt file format.

How it works

We will demonstrate srt_delay.py using the subtitles for the open-source movie Elephants Dream. The file can be downloaded from this repo (sample_input.srt) or from Wikimedia Commons.

Here is what the input file looks like:

$ head sample_input.srt
1
00:00:15,000 --> 00:00:17,951
At the left we can see...

2
00:00:18,166 --> 00:00:20,083
At the right we can see the...

3
00:00:20,119 --> 00:00:21,962

Each line contains either an index number for the subtitle (1), the subtitle’s timing (00:00:18,166 --> 00:00:20,083), or the subtitle text itself.

Delaying subtitles

Suppose we want to delay the subtitles by 1 hour and 5 minutes. We can pass this interval in .srt timestamp format (01:05:00,000) to srt_delay with the -d or --delay flag:

$ python3 srt_delay.py sample_input.srt -d 01:05:00,000 | head
1
01:05:15,000 --> 01:05:17,951
At the left we can see...

2
01:05:18,166 --> 01:05:20,083
At the right we can see the...

3
01:05:20,119 --> 01:05:21,962

Advancing subtitles

Suppose we want to advance the subtitles by 1.5 seconds. We can pass this interval in .srt timestamp format (00:00:01,500) to srt_delay.py with the -a or --advance flag:

$ python3 srt_delay.py sample_input.srt -a 00:00:01,500 | head
1
00:00:13,500 --> 00:00:16,451
At the left we can see...

2
00:00:16,666 --> 00:00:18,583
At the right we can see the...

3
00:00:18,619 --> 00:00:20,462

Typical usage

By default, srt_delay.py prints to standard output. In most cases, you will want to save the output to another file:

$ python3 srt_delay.py sample_input.srt -a 00:00:01,500 > sample_input_advanced_by_1.5s.srt

Bugs

If you find one, submit a PR or email me at [email protected].

srt_delay's People

Contributors

maxkapur avatar

Watchers

 avatar

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.