Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,26 +5,39 @@ import os
|
|
| 5 |
|
| 6 |
# -------- Video Trim Funktion --------
|
| 7 |
def trim_video(file, start, duration):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# -------- Gradio Interface --------
|
| 30 |
iface = gr.Interface(
|
|
@@ -36,7 +49,7 @@ iface = gr.Interface(
|
|
| 36 |
],
|
| 37 |
outputs=gr.Video(label="Getrimmtes Video"),
|
| 38 |
title="FFmpeg Video Editor",
|
| 39 |
-
description="Trimme Videos direkt im Hugging Face Space"
|
| 40 |
)
|
| 41 |
|
| 42 |
# -------- Server starten --------
|
|
|
|
| 5 |
|
| 6 |
# -------- Video Trim Funktion --------
|
| 7 |
def trim_video(file, start, duration):
|
| 8 |
+
try:
|
| 9 |
+
# --- Pfade für temporäre Dateien ---
|
| 10 |
+
input_path = f"/tmp/{uuid.uuid4()}_in.mp4"
|
| 11 |
+
output_path = f"/tmp/{uuid.uuid4()}_out.mp4"
|
| 12 |
+
|
| 13 |
+
# --- Datei speichern ---
|
| 14 |
+
file_bytes = file.read() # Gradio liefert SpooledTemporaryFile
|
| 15 |
+
with open(input_path, "wb") as f:
|
| 16 |
+
f.write(file_bytes)
|
| 17 |
+
|
| 18 |
+
# --- FFmpeg Befehl ---
|
| 19 |
+
cmd = [
|
| 20 |
+
"ffmpeg",
|
| 21 |
+
"-y",
|
| 22 |
+
"-ss", str(start),
|
| 23 |
+
"-i", input_path,
|
| 24 |
+
"-t", str(duration),
|
| 25 |
+
"-c", "copy",
|
| 26 |
+
output_path
|
| 27 |
+
]
|
| 28 |
+
subprocess.run(cmd, check=True, capture_output=True)
|
| 29 |
+
|
| 30 |
+
# --- Prüfen, ob Output existiert ---
|
| 31 |
+
if not os.path.exists(output_path):
|
| 32 |
+
return "Fehler: Output-Video wurde nicht erstellt."
|
| 33 |
+
|
| 34 |
+
return output_path
|
| 35 |
+
|
| 36 |
+
except subprocess.CalledProcessError as e:
|
| 37 |
+
return f"FFmpeg-Fehler:\n{e.stderr.decode()}"
|
| 38 |
+
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"Allgemeiner Fehler:\n{str(e)}"
|
| 41 |
|
| 42 |
# -------- Gradio Interface --------
|
| 43 |
iface = gr.Interface(
|
|
|
|
| 49 |
],
|
| 50 |
outputs=gr.Video(label="Getrimmtes Video"),
|
| 51 |
title="FFmpeg Video Editor",
|
| 52 |
+
description="Trimme Videos direkt im Hugging Face Space. Fehlermeldungen werden angezeigt, falls etwas schiefgeht."
|
| 53 |
)
|
| 54 |
|
| 55 |
# -------- Server starten --------
|