This is a Python script designed to help you adjust the timing of subtitles in .srt files. Whether you need to fix sync issues or simply shift the timing, this script will allow you to add or subtract time to all subtitle timestamps in the file.
- Adjust subtitle times by any given amount of seconds.
- Supports
HH:MM:SS,SSSformat commonly used in.srtsubtitle files. - Creates a new adjusted subtitle file with the same content but with updated timings.
No installation is required, just make sure you have Python installed (version 3.x recommended).
- Clone the repository or download the script.
- Ensure your subtitle file is in
.srtformat and accessible.
- Download the
subtitle_time_shift.pyscript and place it in the same folder as your.srtsubtitle file, or specify the full path to the subtitle file. - Open your terminal/command prompt and run the script:
python subtitle_time_shift.py- When prompted, enter the number of seconds you want to shift the subtitle times by:
- Positive number to increase the timestamp (delay subtitles).
- Negative number to decrease the timestamp (advance subtitles).
Example input:
Enter the number of seconds to increase the timestamps: 2.5
- The script will read your subtitle file, adjust the timestamps, and create a new file with
_adjappended to the original filename. For example, if your file wasmovie.srt, the adjusted file will be namedmovie.srt_adj.
Given a subtitle line like:
00:01:23,500 --> 00:01:25,000
Hello, how are you?
If you input 2 seconds to shift, the adjusted subtitle will be:
00:01:25,500 --> 00:01:27,000
Hello, how are you?
-
convert_to_seconds(time_str): Converts a subtitle timestamp fromHH:MM:SS,SSSformat to total seconds (including milliseconds). -
convert_to_timestamp(seconds): Converts seconds back into theHH:MM:SS,SSSformat. -
adjust_subtitles(file_path, time_shift_seconds): Reads the.srtfile, identifies all timestamps using regex, and applies the time shift. Then, it writes the adjusted subtitles to a new file.
- Python 3.x
- No external dependencies (uses built-in Python libraries like
re).