feat: speed up output clips to 1.25x speed by default and scale subtitle/mute timestamps

This commit is contained in:
Renato
2026-07-02 19:38:50 +02:00
parent 05e0217541
commit 174b992335
2 changed files with 34 additions and 18 deletions
+7 -7
View File
@@ -90,7 +90,7 @@ def _merge_overlapping(ranges, pad_seconds=0.05):
merged.append((s, e))
return merged
def generate_srt(transcript, clip_start, clip_end, output_path, max_chars=20, max_duration=2.0, swears_path=None, return_mute_ranges=False):
def generate_srt(transcript, clip_start, clip_end, output_path, max_chars=20, max_duration=2.0, swears_path=None, return_mute_ranges=False, speed_factor=1.0):
"""
Generates an SRT file from the transcript for a specific time range.
Groups words into short lines suitable for vertical video.
@@ -110,9 +110,9 @@ def generate_srt(transcript, clip_start, clip_end, output_path, max_chars=20, ma
cleaned_word = re.sub(r'[^\w]', '', word_text.lower())
if cleaned_word in swears:
# Record absolute mute range relative to clip start
rel_start = max(0.0, word_copy['start'] - clip_start)
rel_end = max(0.0, word_copy['end'] - clip_start)
# Record absolute mute range relative to clip start, scaled by speed_factor
rel_start = (max(0.0, word_copy['start'] - clip_start)) / speed_factor
rel_end = (max(0.0, word_copy['end'] - clip_start)) / speed_factor
raw_mute_ranges.append((rel_start, rel_end))
# Censor word
word_copy['word'] = censor_word(word_text)
@@ -134,9 +134,9 @@ def generate_srt(transcript, clip_start, clip_end, output_path, max_chars=20, ma
block_start = None
for i, word in enumerate(words):
# Adjust times relative to clip
start = max(0, word['start'] - clip_start)
end = max(0, word['end'] - clip_start)
# Adjust times relative to clip, scaled by speed_factor
start = (max(0, word['start'] - clip_start)) / speed_factor
end = (max(0, word['end'] - clip_start)) / speed_factor
# Word info copy with relative times
w_rel = {