Spaces:
Sleeping
Sleeping
Update app.py
Browse filessubtitled video
app.py
CHANGED
@@ -132,11 +132,14 @@ def download_video():
|
|
132 |
# Generate subtitles (each subtitle will last for 2.5 seconds with millisecond precision)
|
133 |
subs = []
|
134 |
subtitle_length = 2.5 # seconds each subtitle will be displayed
|
135 |
-
for i in range(0, len(translated_subtitle),
|
136 |
-
start_time = (i //
|
137 |
-
subtitle_text = translated_subtitle[i:i +
|
138 |
subs.append((start_time, subtitle_text)) # Create a tuple for start time and text
|
139 |
|
|
|
|
|
|
|
140 |
# Create subtitle clips
|
141 |
subtitles = SubtitlesClip(subs, generator)
|
142 |
|
@@ -144,7 +147,7 @@ def download_video():
|
|
144 |
subtitled_video = mp.CompositeVideoClip([video, subtitles.set_position(('center', 'bottom'))])
|
145 |
|
146 |
output_video_path = "subtitled_video.mp4"
|
147 |
-
subtitled_video.write_videofile(output_video_path)
|
148 |
|
149 |
# Return the file path for download
|
150 |
return output_video_path
|
|
|
132 |
# Generate subtitles (each subtitle will last for 2.5 seconds with millisecond precision)
|
133 |
subs = []
|
134 |
subtitle_length = 2.5 # seconds each subtitle will be displayed
|
135 |
+
for i in range(0, len(translated_subtitle), 40): # Reduce chunk size to improve reliability
|
136 |
+
start_time = (i // 40) * subtitle_length # Get start time with more precision
|
137 |
+
subtitle_text = translated_subtitle[i:i + 40] # Get the next 40 characters
|
138 |
subs.append((start_time, subtitle_text)) # Create a tuple for start time and text
|
139 |
|
140 |
+
# Debugging log
|
141 |
+
print("Generated subtitles:", subs)
|
142 |
+
|
143 |
# Create subtitle clips
|
144 |
subtitles = SubtitlesClip(subs, generator)
|
145 |
|
|
|
147 |
subtitled_video = mp.CompositeVideoClip([video, subtitles.set_position(('center', 'bottom'))])
|
148 |
|
149 |
output_video_path = "subtitled_video.mp4"
|
150 |
+
subtitled_video.write_videofile(output_video_path, codec='libx264') # Use libx264 for better compatibility
|
151 |
|
152 |
# Return the file path for download
|
153 |
return output_video_path
|