Spaces:
Sleeping
Sleeping
File size: 1,590 Bytes
52409f1 882c245 e5b658f d593d36 d68759e d593d36 e5b658f d593d36 77921b4 d593d36 e5b658f d593d36 e5b658f d593d36 77921b4 d593d36 77921b4 e5b658f 52409f1 d593d36 e5b658f 77921b4 d593d36 bbc25a7 d593d36 b4ce27c d593d36 bbc25a7 882c245 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import gradio as gr
import subprocess
from pathlib import Path
import tempfile
import shutil
import uuid
allowed_medias = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".tiff"]
def execute_ffmpeg_image_to_video(image_file):
"""Konvertiert ein Bild in ein 5-Sekunden-Video"""
if image_file is None:
return None, "❌ Keine Datei ausgewählt"
temp_dir = tempfile.mkdtemp()
file_path = Path(image_file.name)
sanitized_name = file_path.name.replace(" ", "_")
dest_path = Path(temp_dir) / sanitized_name
shutil.copy(file_path, dest_path)
output_file = Path(temp_dir) / f"output_{uuid.uuid4().hex}.mp4"
cmd = [
"ffmpeg",
"-y",
"-loop", "1",
"-framerate", "25",
"-i", str(dest_path),
"-t", "5",
"-c:v", "mpeg4",
"-pix_fmt", "yuv420p",
str(output_file)
]
try:
subprocess.run(cmd, check=True, text=True, capture_output=True)
except subprocess.CalledProcessError as e:
return None, f"❌ FFmpeg Fehler:\n{e.stderr}"
return str(output_file), "✅ Video erfolgreich erstellt"
# Gradio UI
with gr.Blocks() as demo:
gr.Markdown("# Bild → Video Konverter")
img_input = gr.File(file_types=allowed_medias, label="Bild auswählen")
out_video = gr.Video(interactive=False, label="Generiertes Video")
status = gr.Textbox(interactive=False, label="Status")
btn = gr.Button("Video erstellen")
btn.click(
fn=execute_ffmpeg_image_to_video,
inputs=[img_input],
outputs=[out_video, status],
)
demo.launch()
|