ChiBenevisamPas commited on
Commit
ef3342d
·
verified ·
1 Parent(s): 857e4b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
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 + 2 < len(lines):
32
- start_time = convert_to_seconds(lines[i + 1].split(" --> ")[0])
33
- end_time = convert_to_seconds(lines[i + 1].split(" --> ")[1])
34
- text = lines[i + 2].strip()
35
- text_clip = TextClip(text, fontsize=24, color='white', bg_color='black', size=video_clip.size, print_cmd=True)
36
- text_clip = text_clip.set_start(start_time).set_end(end_time).set_position('bottom')
37
- subs.append(text_clip)
 
 
 
 
 
 
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)