Commit
·
d8510c0
1
Parent(s):
4a21148
improve wordlevel subtitle padding
Browse files- utils/subtitler.py +2 -3
utils/subtitler.py
CHANGED
|
@@ -70,7 +70,7 @@ def subtitler(video_file: str,
|
|
| 70 |
# Calculate word-level highlight positions
|
| 71 |
current_x = x_center
|
| 72 |
for word_info in line["words"]:
|
| 73 |
-
word = word_info["word"]
|
| 74 |
word_start = float(word_info["start"])
|
| 75 |
word_end = float(word_info["end"])
|
| 76 |
|
|
@@ -80,9 +80,8 @@ def subtitler(video_file: str,
|
|
| 80 |
word_clip = word_clip.set_start(word_start).set_end(word_end)
|
| 81 |
word_clip = word_clip.set_position((current_x - 7.5, subtitle_y_position))
|
| 82 |
subtitle_clips.append(word_clip)
|
|
|
|
| 83 |
|
| 84 |
-
space_width = TextClip(" ", fontsize=fontsize, font=font, method='label').w
|
| 85 |
-
current_x += word_clip.w + space_width
|
| 86 |
video = CompositeVideoClip(size=None, clips=[clip] + subtitle_clips)
|
| 87 |
video.set_audio(temp_audiofile)
|
| 88 |
video.write_videofile(output_file, codec='libx264', audio_codec='aac', temp_audiofile = temp_audiofile)
|
|
|
|
| 70 |
# Calculate word-level highlight positions
|
| 71 |
current_x = x_center
|
| 72 |
for word_info in line["words"]:
|
| 73 |
+
word = word_info["word"] + " "
|
| 74 |
word_start = float(word_info["start"])
|
| 75 |
word_end = float(word_info["end"])
|
| 76 |
|
|
|
|
| 80 |
word_clip = word_clip.set_start(word_start).set_end(word_end)
|
| 81 |
word_clip = word_clip.set_position((current_x - 7.5, subtitle_y_position))
|
| 82 |
subtitle_clips.append(word_clip)
|
| 83 |
+
current_x += word_clip.w
|
| 84 |
|
|
|
|
|
|
|
| 85 |
video = CompositeVideoClip(size=None, clips=[clip] + subtitle_clips)
|
| 86 |
video.set_audio(temp_audiofile)
|
| 87 |
video.write_videofile(output_file, codec='libx264', audio_codec='aac', temp_audiofile = temp_audiofile)
|