Jur153engsub Convert020006 Min -
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() jur153engsub convert020006 min
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
A university records a lecture for course JUR 153. The video has English subtitles. A student or editor wants to convert a portion starting at 20 minutes 6 seconds into a clip. A university records a lecture for course JUR 153
ffmpeg -i "$INPUT" -map 0:s:0 subtitles_eng.srt s = tc_str[:2]
