Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,64 +51,11 @@ def generate_slideshow_with_audio(images, input_text, duration_per_word=0.5, dur
|
|
| 51 |
temp_audio_file = save_temp_audio(audio_file)
|
| 52 |
|
| 53 |
# Clips für jedes Bild erstellen
|
| 54 |
-
for i, img_path in enumerate(images):
|
| 55 |
-
img_path = Path(img_path.name) # Sicherstellen, dass es den richtigen Pfad hat
|
| 56 |
-
clip_path = Path(temp_dir) / f"clip_{i}.mp4"
|
| 57 |
-
|
| 58 |
-
vf_filters = (
|
| 59 |
-
"scale=w=1280:h=720:force_original_aspect_ratio=decrease,"
|
| 60 |
-
"pad=1280:720:(ow-iw)/2:(oh-ih)/2:color=black,"
|
| 61 |
-
"fps=25,format=yuv420p"
|
| 62 |
-
)
|
| 63 |
-
|
| 64 |
-
# Clips für jedes Bild erstellen (ohne Text auf Bild)
|
| 65 |
-
cmd = [
|
| 66 |
-
"ffmpeg",
|
| 67 |
-
"-y",
|
| 68 |
-
"-loop", "1",
|
| 69 |
-
"-i", str(img_path),
|
| 70 |
-
"-t", str(duration_per_image),
|
| 71 |
-
"-vf", vf_filters,
|
| 72 |
-
str(clip_path)
|
| 73 |
-
]
|
| 74 |
-
try:
|
| 75 |
-
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 76 |
-
except subprocess.CalledProcessError as e:
|
| 77 |
-
return None, f"❌ FFmpeg Fehler bei Bild {i+1}:\n{e.stderr}"
|
| 78 |
-
|
| 79 |
-
clips.append(clip_path)
|
| 80 |
-
|
| 81 |
-
# Clips zusammenfügen
|
| 82 |
-
filelist_path = Path(temp_dir) / "filelist.txt"
|
| 83 |
-
with open(filelist_path, "w") as f:
|
| 84 |
-
for clip in clips:
|
| 85 |
-
f.write(f"file '{clip}'\n")
|
| 86 |
-
|
| 87 |
-
output_file = Path(temp_dir) / f"slideshow_{uuid.uuid4().hex}.mp4"
|
| 88 |
-
cmd_concat = [
|
| 89 |
-
"ffmpeg",
|
| 90 |
-
"-y",
|
| 91 |
-
"-f", "concat",
|
| 92 |
-
"-safe", "0",
|
| 93 |
-
"-i", str(filelist_path),
|
| 94 |
-
"-c:v", "libx264",
|
| 95 |
-
"-pix_fmt", "yuv420p",
|
| 96 |
-
str(output_file)
|
| 97 |
-
]
|
| 98 |
-
try:
|
| 99 |
-
subprocess.run(cmd_concat, check=True, capture_output=True, text=True)
|
| 100 |
-
except subprocess.CalledProcessError as e:
|
| 101 |
-
return None, f"❌ FFmpeg Concat Fehler:\n{e.stderr}"
|
| 102 |
-
|
| 103 |
-
# Text als Overlay Wort für Wort einfügen
|
| 104 |
-
total_duration = duration_per_image * len(images) # Gesamtzeit des Videos
|
| 105 |
-
word_display_time = duration_per_word # Zeit pro Wort (in Sekunden)
|
| 106 |
-
|
| 107 |
clips_with_text = []
|
| 108 |
word_index = 0
|
| 109 |
|
| 110 |
for i, img_path in enumerate(images):
|
| 111 |
-
img_path = Path(img_path.name) # Pfad
|
| 112 |
clip_path_with_text = Path(temp_dir) / f"clip_with_text_{i}.mp4"
|
| 113 |
|
| 114 |
# Berechne Start- und Endzeit für jedes Wort
|
|
|
|
| 51 |
temp_audio_file = save_temp_audio(audio_file)
|
| 52 |
|
| 53 |
# Clips für jedes Bild erstellen
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
clips_with_text = []
|
| 55 |
word_index = 0
|
| 56 |
|
| 57 |
for i, img_path in enumerate(images):
|
| 58 |
+
img_path = Path(img_path.name) # Sicherstellen, dass es den richtigen Pfad hat
|
| 59 |
clip_path_with_text = Path(temp_dir) / f"clip_with_text_{i}.mp4"
|
| 60 |
|
| 61 |
# Berechne Start- und Endzeit für jedes Wort
|