alexwlchan / ttml2srt

Convert TTML subtitles to SRT subtitles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

16 March 2024: This repo is no longer maintained.

My original use case for ttml2srt was converting TTML subtitles which I'd downloaded using youtube-dl.

There is a convert-subtitles=srt flag in youtube-dl, and it was around when I started doing this, but it didn't work for me for some reason. If I tried to download SRT subtitles, it left them as TTML files. I don't know if this was a code bug or user error.

It was easier to pick up this script than work out what was wrong with youtube-dl. I forked the original repo to make the script match my workflow (e.g. write the subtitles to an SRT file rather than stdout).

I recently retested the --convert-subtitles=srt flag with a newer version of youtube-dl (more specifically yt-dlp) and it's working correctly. I get an SRT file, so I don't need this script any more.


ttml2srt

Convert TTML subtitles to SRT subtitles.

Installation

This is how I set up this script on a new machine:

  1. Clone the repository:

    $ git clone https://github.com/alexwlchan/ttml2srt.git ~/repos/ttml2srt
  2. Add a Fish configuration snippet that adds the repo to my PATH:

    $ echo 'set -g -x PATH ~/repos/ttml2srt "$PATH"' > ~/.config/fish/conf.d/ttml2srt.fish

Usage

Run the script from anywhere, passing the name of one or more TTML files as arguments:

$ ttml2srt mysubtitle.ttml
mysubtitle.srt

$ ttml2srt video1.ttml video2.ttml video3.ttml
video1.srt
video2.srt
video3.srt

The converted files will be written to an SRT file with the same name, and the path of the new file printed to stdout.

This will delete the original TTML files. This is what I find convenient, but user beware -- if that's an issue for you, you may prefer to use Laura Klünder's original script.

History

This is a fork of a script written by Laura Klünder.

I made the following changes:

  • Write the new subtitles to an SRT file rather than stdout
  • Try to make it run faster
  • Delete the original TTML file when it's done

About

Convert TTML subtitles to SRT subtitles

License:MIT License


Languages

Language:Python 100.0%