Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ def generate_slideshow(images, duration, texts=None, y_pos=0.5, fade_duration=0.
|
|
| 10 |
if not images:
|
| 11 |
return None, "❌ Keine Bilder ausgewählt"
|
| 12 |
|
| 13 |
-
y_pos = min(max(0.0, y_pos), 0.9)
|
| 14 |
temp_dir = tempfile.mkdtemp()
|
| 15 |
clips = []
|
| 16 |
|
|
@@ -21,18 +21,22 @@ def generate_slideshow(images, duration, texts=None, y_pos=0.5, fade_duration=0.
|
|
| 21 |
clip_path = Path(temp_dir) / f"clip_{i}.mp4"
|
| 22 |
text = texts[i] if i < len(texts) else ""
|
| 23 |
|
| 24 |
-
# Scale + Pad
|
| 25 |
-
vf_filters =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Text Overlay Filter
|
| 28 |
if text:
|
| 29 |
safe_text = text.replace(":", "\\:").replace("'", "\\'")
|
| 30 |
drawtext_filter = (
|
| 31 |
-
f"drawtext=text='{safe_text}':fontcolor=white:fontsize={font_size}:borderw=2:"
|
| 32 |
f"x=(w-text_w)/2:y=(h-text_h)*{y_pos}:"
|
| 33 |
f"alpha='if(lt(t,{fade_duration}), t/{fade_duration}, if(lt(t,{duration}-{fade_duration}), 1, ({duration}-t)/{fade_duration}))'"
|
| 34 |
)
|
| 35 |
-
vf_filters +=
|
| 36 |
|
| 37 |
cmd = [
|
| 38 |
"ffmpeg",
|
|
@@ -50,6 +54,7 @@ def generate_slideshow(images, duration, texts=None, y_pos=0.5, fade_duration=0.
|
|
| 50 |
|
| 51 |
clips.append(clip_path)
|
| 52 |
|
|
|
|
| 53 |
filelist_path = Path(temp_dir) / "filelist.txt"
|
| 54 |
with open(filelist_path, "w") as f:
|
| 55 |
for clip in clips:
|
|
@@ -84,7 +89,7 @@ with gr.Blocks() as demo:
|
|
| 84 |
duration_input = gr.Number(value=3, label="Dauer pro Bild in Sekunden", precision=1)
|
| 85 |
fade_input = gr.Number(value=0.7, label="Fade Dauer in Sekunden", precision=1)
|
| 86 |
text_input = gr.Textbox(label="Texte pro Bild (mit Komma trennen)", placeholder="Text1, Text2, Text3 ...")
|
| 87 |
-
ypos_input = gr.Slider(minimum=0.0, maximum=
|
| 88 |
font_size_input = gr.Number(value=60, label="Textgröße (px)")
|
| 89 |
out_video = gr.Video(interactive=False, label="Generiertes Video")
|
| 90 |
status = gr.Textbox(interactive=False, label="Status")
|
|
|
|
| 10 |
if not images:
|
| 11 |
return None, "❌ Keine Bilder ausgewählt"
|
| 12 |
|
| 13 |
+
y_pos = min(max(0.0, y_pos), 0.9) # 0=oben, 1=unten, max 0.9
|
| 14 |
temp_dir = tempfile.mkdtemp()
|
| 15 |
clips = []
|
| 16 |
|
|
|
|
| 21 |
clip_path = Path(temp_dir) / f"clip_{i}.mp4"
|
| 22 |
text = texts[i] if i < len(texts) else ""
|
| 23 |
|
| 24 |
+
# Scale + Pad für proportionalen Fit in 1280x720
|
| 25 |
+
vf_filters = (
|
| 26 |
+
"scale=w=1280:h=720:force_original_aspect_ratio=decrease,"
|
| 27 |
+
"pad=1280:720:(ow-iw)/2:(oh-ih)/2:color=black,"
|
| 28 |
+
"fps=25,format=yuv420p"
|
| 29 |
+
)
|
| 30 |
|
| 31 |
# Text Overlay Filter
|
| 32 |
if text:
|
| 33 |
safe_text = text.replace(":", "\\:").replace("'", "\\'")
|
| 34 |
drawtext_filter = (
|
| 35 |
+
f",drawtext=text='{safe_text}':fontcolor=white:fontsize={font_size}:borderw=2:"
|
| 36 |
f"x=(w-text_w)/2:y=(h-text_h)*{y_pos}:"
|
| 37 |
f"alpha='if(lt(t,{fade_duration}), t/{fade_duration}, if(lt(t,{duration}-{fade_duration}), 1, ({duration}-t)/{fade_duration}))'"
|
| 38 |
)
|
| 39 |
+
vf_filters += drawtext_filter
|
| 40 |
|
| 41 |
cmd = [
|
| 42 |
"ffmpeg",
|
|
|
|
| 54 |
|
| 55 |
clips.append(clip_path)
|
| 56 |
|
| 57 |
+
# Alle Clips zu einem Video zusammenfügen
|
| 58 |
filelist_path = Path(temp_dir) / "filelist.txt"
|
| 59 |
with open(filelist_path, "w") as f:
|
| 60 |
for clip in clips:
|
|
|
|
| 89 |
duration_input = gr.Number(value=3, label="Dauer pro Bild in Sekunden", precision=1)
|
| 90 |
fade_input = gr.Number(value=0.7, label="Fade Dauer in Sekunden", precision=1)
|
| 91 |
text_input = gr.Textbox(label="Texte pro Bild (mit Komma trennen)", placeholder="Text1, Text2, Text3 ...")
|
| 92 |
+
ypos_input = gr.Slider(minimum=0.0, maximum=0.9, step=0.01, value=0.5, label="Y-Position für alle Texte (0=oben, 0.5=mitte, 0.9=unten)")
|
| 93 |
font_size_input = gr.Number(value=60, label="Textgröße (px)")
|
| 94 |
out_video = gr.Video(interactive=False, label="Generiertes Video")
|
| 95 |
status = gr.Textbox(interactive=False, label="Status")
|