Jur153engsub Convert020006 Min
Date: April 5, 2026
Time: 09:00–10:15
Location: Hybrid — Committee Room A / Virtual (link provided to members)
Prepared by: [Secretary]
The most powerful, free, and scriptable tool is FFmpeg. The -ss flag seeks to a timestamp, and -t sets duration.
import re
from datetime import timedelta
def parse_timecode(tc_str):
# Handles 020006 -> 02:00:06.000
if len(tc_str) == 6 and tc_str.isdigit():
h, m, s = tc_str[:2], tc_str[2:4], tc_str[4:6]
return f"h:m:s.000"
return tc_str
def shift_subtitles(input_file, shift_str, minify=False):
shift_td = timedelta(
hours=int(shift_str[:2]),
minutes=int(shift_str[2:4]),
seconds=int(shift_str[4:6])
)
with open(input_file, 'r') as f:
lines = f.readlines()
new_lines = []
i = 0
while i < len(lines):
if '-->' in lines[i]:
times = re.split(r' --> ', lines[i].strip())
start = parse_timecode(times[0])
end = parse_timecode(times[1])
# Apply shift
new_start = (datetime.strptime(start, "%H:%M:%S.%f") + shift_td).strftime("%H:%M:%S.%f")[:-3]
new_end = (datetime.strptime(end, "%H:%M:%S.%f") + shift_td).strftime("%H:%M:%S.%f")[:-3]
new_lines.append(f"new_start --> new_end\n")
i += 1
# Subtitle text
text = ""
while i < len(lines) and lines[i].strip() != '':
text += lines[i]
i += 1
if minify:
# Keep only first line if multiple, remove punctuation
first_line = text.split('\n')[0].strip()
first_line = re.sub(r'[^\w\s]', '', first_line)
new_lines.append(first_line + '\n')
else:
new_lines.append(text)
new_lines.append('\n')
else:
new_lines.append(lines[i])
i += 1
return new_lines
