Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -28,13 +28,19 @@ def create_subtitled_video(video_file, srt_file):
|
|
28 |
with open(srt_file, 'r') as f:
|
29 |
lines = f.readlines()
|
30 |
for i in range(0, len(lines), 4):
|
31 |
-
if i +
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Combine video and subtitles
|
40 |
final_video = CompositeVideoClip([video_clip] + subs)
|
|
|
28 |
with open(srt_file, 'r') as f:
|
29 |
lines = f.readlines()
|
30 |
for i in range(0, len(lines), 4):
|
31 |
+
if i + 1 < len(lines): # Ensure there is a next line for timestamps
|
32 |
+
timestamp_line = lines[i + 1].strip()
|
33 |
+
if " --> " in timestamp_line: # Ensure it contains a timestamp
|
34 |
+
try:
|
35 |
+
start_time = convert_to_seconds(timestamp_line.split(" --> ")[0])
|
36 |
+
end_time = convert_to_seconds(timestamp_line.split(" --> ")[1])
|
37 |
+
text = lines[i + 2].strip() if (i + 2 < len(lines)) else ""
|
38 |
+
text_clip = TextClip(text, fontsize=24, color='white', bg_color='black', size=video_clip.size, print_cmd=True)
|
39 |
+
text_clip = text_clip.set_start(start_time).set_end(end_time).set_position('bottom')
|
40 |
+
subs.append(text_clip)
|
41 |
+
except Exception as e:
|
42 |
+
print(f"Error processing subtitle {i // 4 + 1}: {e}") # Debug print
|
43 |
+
continue # Skip to the next subtitle on error
|
44 |
|
45 |
# Combine video and subtitles
|
46 |
final_video = CompositeVideoClip([video_clip] + subs)
|