Converting VTT to SRT with vtt_to_srt3

Jeison C. | Jan 11, 2025 min read

Introduction

vtt_to_srt3 is a Python tool designed to convert VTT (WebVTT) files to SRT (SubRip Subtitle) format. This article will guide you through the installation, usage, and manual build process of vtt_to_srt3.

Installation

To install vtt_to_srt3, use the following pip command:

pip install vtt_to_srt3

Alternatively, you can use:

python -m pip install vtt_to_srt3

Usage from Terminal

You can use vtt_to_srt3 directly from the terminal. Below is the usage information:

usage: vtt_to_srt [-h] [-r] [-e ENCODING] [-rf] pathname

Convert vtt files to srt files

positional arguments:
  pathname              a file or directory with files to be converted

options:
  -h, --help            show this help message and exit
  -r, --recursive       walk path recursively
  -e ENCODING, --encoding ENCODING
                        encoding format for input and output files
  -rf, --remove_format  remove the format tags like bold & italic from output files

Example Commands

Convert a single VTT file to SRT:

vtt_to_srt input.vtt

Convert all VTT files in a directory recursively:

vtt_to_srt -r /path/to/directory

Specify encoding format:

vtt_to_srt -e utf-8 input.vtt

Remove format tags like bold and italic from output files:

vtt_to_srt -rf input.vtt

Usage as a Library

You can also use vtt_to_srt3 as a library in your Python scripts.

Convert a VTT File

from vtt_to_srt.vtt_to_srt import ConvertFile

convert_file = ConvertFile("input_utf8.vtt", "utf-8")
convert_file.convert()

Recursively Convert All VTT Files in a Directory

from vtt_to_srt.vtt_to_srt import ConvertDirectories

recursive = False
convert_file = ConvertDirectories(".", recursive, "utf-8")
convert_file.convert()

Manual Build

If you need to build vtt_to_srt3 manually, follow these steps:

Generate Wheel

python -m pip install --upgrade setuptools wheel build
python -m build

Generate Documentation

To generate the documentation, use pdoc3:

python -m pip install pdoc3
pdoc --html vtt_to_srt/vtt_to_srt.py -o docs
mv docs/vtt_to_srt.html docs/index.html
rm -rf docs/vtt_to_srt

Conclusion

vtt_to_srt3 is a versatile tool for converting VTT files to SRT format, whether you prefer using it from the terminal or as a library in your Python scripts. For more information, visit the documentation.

Additional Resources