Spaces:
Sleeping
Sleeping
Update src/text_to_video.py
Browse files- src/text_to_video.py +8 -8
src/text_to_video.py
CHANGED
@@ -24,7 +24,7 @@ def get_audio_duration(audio_path):
|
|
24 |
|
25 |
for audio_path in audio_list:
|
26 |
# Mở file âm thanh và lấy thời gian
|
27 |
-
with AudioFileClip(f"./
|
28 |
duration_list.append(audio.duration)
|
29 |
# Tính tổng tích lũy thời gian
|
30 |
duration_list = [format_time(time) for time in list(accumulate(duration_list))]
|
@@ -87,7 +87,7 @@ def create_video_from_images(image_folder, audio_path, output_video_path):
|
|
87 |
duration_per_image = total_duration / len(image_files)
|
88 |
|
89 |
# Tạo danh sách các clip ảnh
|
90 |
-
clips = [ImageClip(f"./
|
91 |
|
92 |
# Ghép các clip ảnh lại với nhau
|
93 |
final_video = concatenate_videoclips(clips, method="chain")
|
@@ -127,7 +127,7 @@ def add_subtitles_to_video(video_path, subtitle_path, output_video_path):
|
|
127 |
# Chuyển thời gian thành giây
|
128 |
start_time = sub.start.ordinal / 1000 # Chuyển từ milliseconds sang giây
|
129 |
end_time = sub.end.ordinal / 1000
|
130 |
-
font = "./
|
131 |
# Tạo clip phụ đề
|
132 |
txt_clip = TextClip(font=font, text=wrap_text(sub.text, max_width=85), font_size=30, stroke_color="black", stroke_width=3, color="#fff")
|
133 |
|
@@ -144,10 +144,10 @@ def add_subtitles_to_video(video_path, subtitle_path, output_video_path):
|
|
144 |
|
145 |
print(f"Video với phụ đề đã được lưu tại: {output_video_path}")
|
146 |
def text_to_video():
|
147 |
-
duration_time = get_audio_duration("./
|
148 |
-
create_srt_from_time_and_text(duration_time, './
|
149 |
-
concatenate_audio_files("./
|
150 |
-
create_video_from_images("./
|
151 |
-
add_subtitles_to_video("./
|
152 |
if __name__ == "__main__":
|
153 |
text_to_video()
|
|
|
24 |
|
25 |
for audio_path in audio_list:
|
26 |
# Mở file âm thanh và lấy thời gian
|
27 |
+
with AudioFileClip(f"./audio/{audio_path}") as audio:
|
28 |
duration_list.append(audio.duration)
|
29 |
# Tính tổng tích lũy thời gian
|
30 |
duration_list = [format_time(time) for time in list(accumulate(duration_list))]
|
|
|
87 |
duration_per_image = total_duration / len(image_files)
|
88 |
|
89 |
# Tạo danh sách các clip ảnh
|
90 |
+
clips = [ImageClip(f"./image/{img}").with_duration(duration_per_image).resized(width=1280) for img in image_files]
|
91 |
|
92 |
# Ghép các clip ảnh lại với nhau
|
93 |
final_video = concatenate_videoclips(clips, method="chain")
|
|
|
127 |
# Chuyển thời gian thành giây
|
128 |
start_time = sub.start.ordinal / 1000 # Chuyển từ milliseconds sang giây
|
129 |
end_time = sub.end.ordinal / 1000
|
130 |
+
font = "./BeVietnamPro-Light.ttf"
|
131 |
# Tạo clip phụ đề
|
132 |
txt_clip = TextClip(font=font, text=wrap_text(sub.text, max_width=85), font_size=30, stroke_color="black", stroke_width=3, color="#fff")
|
133 |
|
|
|
144 |
|
145 |
print(f"Video với phụ đề đã được lưu tại: {output_video_path}")
|
146 |
def text_to_video():
|
147 |
+
duration_time = get_audio_duration("./audio")
|
148 |
+
create_srt_from_time_and_text(duration_time, './text', './output/subtitle.srt')
|
149 |
+
concatenate_audio_files("./audio","./output/final_audio.wav")
|
150 |
+
create_video_from_images("./image","./output/final_audio.wav","./output/output.mp4")
|
151 |
+
add_subtitles_to_video("./output/output.mp4", "./output/subtitle.srt", "./output/final_output.mp4")
|
152 |
if __name__ == "__main__":
|
153 |
text_to_video()
|