Update app.py
Browse files
app.py
CHANGED
@@ -177,7 +177,7 @@ def write_google(google_translate):
|
|
177 |
def time_to_seconds(time_obj):
|
178 |
return time_obj.hours * 3600 + time_obj.minutes * 60 + time_obj.seconds + time_obj.milliseconds / 1000
|
179 |
|
180 |
-
def create_subtitle_clips(subtitles, videosize, fontsize,
|
181 |
subtitle_clips = []
|
182 |
for subtitle in subtitles:
|
183 |
start_time = time_to_seconds(subtitle.start)
|
@@ -186,7 +186,7 @@ def create_subtitle_clips(subtitles, videosize, fontsize, fon, color, debug):
|
|
186 |
video_width, video_height = videosize
|
187 |
reshaped_text = arabic_reshaper.reshape(subtitle.text)
|
188 |
bidi_text = get_display(reshaped_text)
|
189 |
-
text_clip = TextClip(bidi_text, fontsize=fontsize,
|
190 |
subtitle_x_position = 'center'
|
191 |
subtitle_y_position = video_height * 4 / 5
|
192 |
text_position = (subtitle_x_position, subtitle_y_position)
|
@@ -212,7 +212,7 @@ def process_video(url):
|
|
212 |
print(video)
|
213 |
subtitles = pysrt.open("google_translate.srt", encoding="utf-8")
|
214 |
output_video_file = input_video_name + '_subtitled' + ".mp4"
|
215 |
-
subtitle_clips = create_subtitle_clips(subtitles, video.size, 32,
|
216 |
final_video = CompositeVideoClip([video] + subtitle_clips)
|
217 |
final_video.write_videofile(output_video_file, codec="libx264", audio_codec="aac")
|
218 |
return output_video_file
|
|
|
177 |
def time_to_seconds(time_obj):
|
178 |
return time_obj.hours * 3600 + time_obj.minutes * 60 + time_obj.seconds + time_obj.milliseconds / 1000
|
179 |
|
180 |
+
def create_subtitle_clips(subtitles, videosize, fontsize, font, color, debug):
|
181 |
subtitle_clips = []
|
182 |
for subtitle in subtitles:
|
183 |
start_time = time_to_seconds(subtitle.start)
|
|
|
186 |
video_width, video_height = videosize
|
187 |
reshaped_text = arabic_reshaper.reshape(subtitle.text)
|
188 |
bidi_text = get_display(reshaped_text)
|
189 |
+
text_clip = TextClip(font, bidi_text, fontsize=fontsize, color=color, bg_color='black', size=(video_width*3/4, None), method='label', align='West').set_start(start_time).set_duration(duration)
|
190 |
subtitle_x_position = 'center'
|
191 |
subtitle_y_position = video_height * 4 / 5
|
192 |
text_position = (subtitle_x_position, subtitle_y_position)
|
|
|
212 |
print(video)
|
213 |
subtitles = pysrt.open("google_translate.srt", encoding="utf-8")
|
214 |
output_video_file = input_video_name + '_subtitled' + ".mp4"
|
215 |
+
subtitle_clips = create_subtitle_clips(subtitles, video.size, 32, 'arial.ttf', 'yellow', False)
|
216 |
final_video = CompositeVideoClip([video] + subtitle_clips)
|
217 |
final_video.write_videofile(output_video_file, codec="libx264", audio_codec="aac")
|
218 |
return output_video_file
|