Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -52,11 +52,13 @@ def create_slides(text, duration, output_folder, max_lines=6):
|
|
52 |
draw = ImageDraw.Draw(img)
|
53 |
|
54 |
lines = slide_text.split("\n")
|
55 |
-
total_height = sum([draw.textbbox((0, 0), line, font=font)[3] for line in lines]) + (len(lines)-1)*10
|
56 |
y = (720 - total_height) // 2
|
57 |
|
58 |
for line in lines:
|
59 |
-
|
|
|
|
|
60 |
draw.text(((1280 - w) // 2, y), line, font=font, fill="white")
|
61 |
y += h + 10
|
62 |
|
@@ -82,27 +84,20 @@ def url_to_av_summary(url, duration):
|
|
82 |
frame_dir = tempfile.mkdtemp()
|
83 |
slides = create_slides(summary, duration, frame_dir)
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
f.write(f"file '{path}'\n")
|
89 |
-
f.write(f"duration {t}\n")
|
90 |
|
|
|
91 |
concat_img = os.path.join(frame_dir, "video_input.mp4")
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
video_path,
|
101 |
-
i=audio_path,
|
102 |
-
vcodec='libx264', acodec='aac', pix_fmt='yuv420p', shortest=None
|
103 |
-
).run(overwrite_output=True, quiet=True)
|
104 |
-
|
105 |
-
return summary, video_path
|
106 |
|
107 |
iface = gr.Interface(
|
108 |
fn=url_to_av_summary,
|
|
|
52 |
draw = ImageDraw.Draw(img)
|
53 |
|
54 |
lines = slide_text.split("\n")
|
55 |
+
total_height = sum([draw.textbbox((0, 0), line, font=font)[3] - draw.textbbox((0, 0), line, font=font)[1] for line in lines]) + (len(lines)-1)*10
|
56 |
y = (720 - total_height) // 2
|
57 |
|
58 |
for line in lines:
|
59 |
+
bbox = draw.textbbox((0, 0), line, font=font)
|
60 |
+
w = bbox[2] - bbox[0]
|
61 |
+
h = bbox[3] - bbox[1]
|
62 |
draw.text(((1280 - w) // 2, y), line, font=font, fill="white")
|
63 |
y += h + 10
|
64 |
|
|
|
84 |
frame_dir = tempfile.mkdtemp()
|
85 |
slides = create_slides(summary, duration, frame_dir)
|
86 |
|
87 |
+
slide_inputs = []
|
88 |
+
for path, t in slides:
|
89 |
+
slide_inputs.extend(["-t", str(t), "-loop", "1", "-i", path])
|
|
|
|
|
90 |
|
91 |
+
filter_complex = "".join([f"[{i}:v]" for i in range(len(slides))]) + f"concat=n={len(slides)}:v=1[outv]"
|
92 |
concat_img = os.path.join(frame_dir, "video_input.mp4")
|
93 |
+
|
94 |
+
cmd = ["ffmpeg", "-y"] + slide_inputs + ["-filter_complex", filter_complex, "-map", "[outv]", concat_img]
|
95 |
+
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
96 |
+
|
97 |
+
final_video = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
|
98 |
+
ffmpeg.input(concat_img).output(audio_path, final_video, vcodec='libx264', acodec='aac', pix_fmt='yuv420p', shortest=None).run(overwrite_output=True, quiet=True)
|
99 |
+
|
100 |
+
return summary, final_video
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
iface = gr.Interface(
|
103 |
fn=url_to_av_summary,
|