Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,11 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import subprocess
|
| 3 |
-
import tempfile
|
| 4 |
-
import uuid
|
| 5 |
-
from pathlib import Path
|
| 6 |
-
|
| 7 |
-
allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
|
| 8 |
-
|
| 9 |
def execute_ffmpeg_image_to_video(image_file):
|
| 10 |
-
"""Erzeugt ein 5-Sekunden-Video aus einem Bild
|
| 11 |
if image_file is None:
|
| 12 |
return None, "❌ Keine Datei ausgewählt"
|
| 13 |
|
| 14 |
-
# Gradio liefert manchmal ein Dict, manchmal ein File-Objekt
|
| 15 |
image_path = Path(image_file.name) if hasattr(image_file, "name") else Path(image_file)
|
| 16 |
|
|
|
|
| 17 |
temp_dir = tempfile.mkdtemp()
|
| 18 |
output_file = Path(temp_dir) / f"output_{uuid.uuid4().hex}.mp4"
|
| 19 |
|
|
@@ -22,25 +14,15 @@ def execute_ffmpeg_image_to_video(image_file):
|
|
| 22 |
"-y",
|
| 23 |
"-loop", "1",
|
| 24 |
"-i", str(image_path),
|
| 25 |
-
"-vf", "fps=25,format=yuv420p",
|
| 26 |
"-t", "5",
|
| 27 |
str(output_file)
|
| 28 |
]
|
| 29 |
|
|
|
|
| 30 |
try:
|
| 31 |
subprocess.run(cmd, check=True, text=True, capture_output=True)
|
| 32 |
except subprocess.CalledProcessError as e:
|
| 33 |
return None, f"❌ FFmpeg Fehler:\n{e.stderr}"
|
| 34 |
|
| 35 |
return str(output_file), "✅ Video erfolgreich erstellt"
|
| 36 |
-
|
| 37 |
-
# Gradio UI
|
| 38 |
-
with gr.Blocks() as demo:
|
| 39 |
-
gr.Markdown("# Bild → Video Konverter")
|
| 40 |
-
img_input = gr.File(file_types=allowed_medias, label="Bild auswählen")
|
| 41 |
-
out_video = gr.Video(interactive=False, label="Generiertes Video")
|
| 42 |
-
status = gr.Textbox(interactive=False, label="Status")
|
| 43 |
-
btn = gr.Button("Video erstellen")
|
| 44 |
-
btn.click(fn=execute_ffmpeg_image_to_video, inputs=[img_input], outputs=[out_video, status])
|
| 45 |
-
|
| 46 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
def execute_ffmpeg_image_to_video(image_file):
|
| 2 |
+
"""Erzeugt ein 5-Sekunden-Video aus einem Bild, selbst bei ungeraden Dimensionen"""
|
| 3 |
if image_file is None:
|
| 4 |
return None, "❌ Keine Datei ausgewählt"
|
| 5 |
|
|
|
|
| 6 |
image_path = Path(image_file.name) if hasattr(image_file, "name") else Path(image_file)
|
| 7 |
|
| 8 |
+
import tempfile, uuid
|
| 9 |
temp_dir = tempfile.mkdtemp()
|
| 10 |
output_file = Path(temp_dir) / f"output_{uuid.uuid4().hex}.mp4"
|
| 11 |
|
|
|
|
| 14 |
"-y",
|
| 15 |
"-loop", "1",
|
| 16 |
"-i", str(image_path),
|
| 17 |
+
"-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2,fps=25,format=yuv420p",
|
| 18 |
"-t", "5",
|
| 19 |
str(output_file)
|
| 20 |
]
|
| 21 |
|
| 22 |
+
import subprocess
|
| 23 |
try:
|
| 24 |
subprocess.run(cmd, check=True, text=True, capture_output=True)
|
| 25 |
except subprocess.CalledProcessError as e:
|
| 26 |
return None, f"❌ FFmpeg Fehler:\n{e.stderr}"
|
| 27 |
|
| 28 |
return str(output_file), "✅ Video erfolgreich erstellt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|