Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -289,7 +289,7 @@ def write_srt(subtitle_text, output_file="edited_srt.srt"):
|
|
289 |
return output_file+".srt"
|
290 |
|
291 |
def generate_translated_subtitle(language, segments, input_video_name):
|
292 |
-
subtitle_file = f"sub-{
|
293 |
text = ""
|
294 |
lines = segments.split('\n')
|
295 |
new_list = [item for item in lines if item != '']
|
@@ -413,21 +413,22 @@ def time_to_seconds(time_obj):
|
|
413 |
|
414 |
def create_subtitle_clips(subtitles, videosize, fontsize, font, color, debug):
|
415 |
subtitle_clips = []
|
|
|
416 |
for subtitle in subtitles:
|
417 |
start_time = time_to_seconds(subtitle.start) # Add 2 seconds offset
|
418 |
end_time = time_to_seconds(subtitle.end)
|
419 |
duration = end_time - start_time
|
420 |
video_width, video_height = videosize
|
421 |
-
max_width = video_width * 0.8
|
422 |
max_height = video_height * 0.2
|
423 |
-
|
424 |
-
|
425 |
-
text_clip = TextClip(font, subtitle.text, font_size=fontsize, size=(int(video_width * 0.8), int(video_height * 0.2)) ,text_align="center" ,color=color, method='caption').with_opacity(0.8).with_start(start_time).with_duration(duration)
|
426 |
subtitle_x_position = 'center'
|
427 |
subtitle_y_position = video_height * 0.68
|
428 |
text_position = (subtitle_x_position, subtitle_y_position)
|
429 |
subtitle_clips.append(text_clip.with_position(text_position))
|
430 |
-
|
|
|
431 |
|
432 |
|
433 |
def process_video(video, url, type):
|
|
|
289 |
return output_file+".srt"
|
290 |
|
291 |
def generate_translated_subtitle(language, segments, input_video_name):
|
292 |
+
subtitle_file = f"sub-{language}.srt"
|
293 |
text = ""
|
294 |
lines = segments.split('\n')
|
295 |
new_list = [item for item in lines if item != '']
|
|
|
413 |
|
414 |
def create_subtitle_clips(subtitles, videosize, fontsize, font, color, debug):
|
415 |
subtitle_clips = []
|
416 |
+
color_clips=[]
|
417 |
for subtitle in subtitles:
|
418 |
start_time = time_to_seconds(subtitle.start) # Add 2 seconds offset
|
419 |
end_time = time_to_seconds(subtitle.end)
|
420 |
duration = end_time - start_time
|
421 |
video_width, video_height = videosize
|
422 |
+
max_width = video_width * 0.8
|
423 |
max_height = video_height * 0.2
|
424 |
+
text_clip = TextClip(font, subtitle.text, font_size=fontsize, size=(int(video_width * 0.8), int(video_height * 0.2)) ,text_align="center" ,color=color, method='caption').with_start(start_time).with_duration(duration)
|
425 |
+
myclip = ColorClip(size=(int(video_width * 0.8), int(video_height * 0.2)) , color=(0, 0, 0)).with_opacity(0.4).with_start(start_time).with_duration(duration)
|
|
|
426 |
subtitle_x_position = 'center'
|
427 |
subtitle_y_position = video_height * 0.68
|
428 |
text_position = (subtitle_x_position, subtitle_y_position)
|
429 |
subtitle_clips.append(text_clip.with_position(text_position))
|
430 |
+
color_clips.append(myclip.with_position(text_position))
|
431 |
+
return subtitle_clips, color_clips
|
432 |
|
433 |
|
434 |
def process_video(video, url, type):
|