This repository contains a Python script that converts .vtt
(WebVTT) subtitle files to .srt
(SubRip Subtitle) format. This is particularly useful for users who need to convert subtitle files from one format to another for compatibility with various media players or platforms.
- Batch Conversion: The script can convert multiple
.vtt
files in a directory to.srt
format with a single command. - Timestamp Conversion: Automatically converts timestamp format from VTT (e.g.,
00:01:02.500
) to SRT (e.g.,00:01:02,500
). - Maintains Subtitle Structure: The script preserves the original structure of the subtitles, ensuring that they remain in sync with the video.
- Python 3.x
-
Clone the repository:
git clone git@github.com:m-hasan-2004/vtt_to_srt.git
-
Navigate to the project directory:
cd vtt-to-srt
-
(Optional) Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install any required dependencies:
This script does not require any external Python packages.
-
Place your
.vtt
files in a directory on your system. -
Edit the
main()
function in themain.py
file to specify the path to your directory:directory = r"path/to/your/directory"
-
Change The Permissions Using Terminal
sudo chmod +x main.py
-
Run the script:
python main.py
The script will automatically convert all
.vtt
files in the specified directory to.srt
format and save them in the same directory.
If you have a directory /home/user/subtitles/
containing .vtt
files, you would set the directory
variable in the main()
function like this:
directory = r"/home/user/subtitles/"