Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,23 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import subprocess
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
import tempfile
|
| 5 |
-
import shutil
|
| 6 |
-
import uuid
|
| 7 |
-
|
| 8 |
-
allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
|
| 9 |
-
|
| 10 |
def execute_ffmpeg_image_to_video(image_file):
|
| 11 |
-
"""
|
| 12 |
if image_file is None:
|
| 13 |
return None, "❌ Keine Datei ausgewählt"
|
| 14 |
|
| 15 |
temp_dir = tempfile.mkdtemp()
|
| 16 |
file_path = Path(image_file.name)
|
| 17 |
-
|
| 18 |
-
dest_path = Path(temp_dir) / sanitized_name
|
| 19 |
shutil.copy(file_path, dest_path)
|
| 20 |
|
| 21 |
output_file = Path(temp_dir) / f"output_{uuid.uuid4().hex}.mp4"
|
| 22 |
|
|
|
|
| 23 |
cmd = [
|
| 24 |
"ffmpeg",
|
| 25 |
"-y",
|
| 26 |
"-loop", "1",
|
| 27 |
-
"-framerate", "25",
|
| 28 |
"-i", str(dest_path),
|
|
|
|
| 29 |
"-t", "5",
|
| 30 |
-
"-c:v", "mpeg4",
|
| 31 |
-
"-pix_fmt", "yuv420p",
|
| 32 |
str(output_file)
|
| 33 |
]
|
| 34 |
|
|
@@ -38,20 +27,3 @@ def execute_ffmpeg_image_to_video(image_file):
|
|
| 38 |
return None, f"❌ FFmpeg Fehler:\n{e.stderr}"
|
| 39 |
|
| 40 |
return str(output_file), "✅ Video erfolgreich erstellt"
|
| 41 |
-
|
| 42 |
-
# Gradio UI
|
| 43 |
-
with gr.Blocks() as demo:
|
| 44 |
-
gr.Markdown("# Bild → Video Konverter")
|
| 45 |
-
|
| 46 |
-
img_input = gr.File(file_types=allowed_medias, label="Bild auswählen")
|
| 47 |
-
out_video = gr.Video(interactive=False, label="Generiertes Video")
|
| 48 |
-
status = gr.Textbox(interactive=False, label="Status")
|
| 49 |
-
|
| 50 |
-
btn = gr.Button("Video erstellen")
|
| 51 |
-
btn.click(
|
| 52 |
-
fn=execute_ffmpeg_image_to_video,
|
| 53 |
-
inputs=[img_input],
|
| 54 |
-
outputs=[out_video, status],
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
def execute_ffmpeg_image_to_video(image_file):
|
| 2 |
+
"""Erzeugt ein 5-Sekunden-Video aus einem Bild im HF Space"""
|
| 3 |
if image_file is None:
|
| 4 |
return None, "❌ Keine Datei ausgewählt"
|
| 5 |
|
| 6 |
temp_dir = tempfile.mkdtemp()
|
| 7 |
file_path = Path(image_file.name)
|
| 8 |
+
dest_path = Path(temp_dir) / file_path.name.replace(" ", "_")
|
|
|
|
| 9 |
shutil.copy(file_path, dest_path)
|
| 10 |
|
| 11 |
output_file = Path(temp_dir) / f"output_{uuid.uuid4().hex}.mp4"
|
| 12 |
|
| 13 |
+
# Minimalistischer, zuverlässiger FFmpeg-Befehl
|
| 14 |
cmd = [
|
| 15 |
"ffmpeg",
|
| 16 |
"-y",
|
| 17 |
"-loop", "1",
|
|
|
|
| 18 |
"-i", str(dest_path),
|
| 19 |
+
"-vf", "fps=25,format=yuv420p",
|
| 20 |
"-t", "5",
|
|
|
|
|
|
|
| 21 |
str(output_file)
|
| 22 |
]
|
| 23 |
|
|
|
|
| 27 |
return None, f"❌ FFmpeg Fehler:\n{e.stderr}"
|
| 28 |
|
| 29 |
return str(output_file), "✅ Video erfolgreich erstellt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|